Im showing a video int my application, but its being chopped up, its locally on disc so I dont understand why this is so... any way i can start to preload it before playing it - so the content would be buffered?
EDIT: Im playing a wmv HD video from the samples provided by Microsoft. I play the video using a MediaElement:
MediaElement mediaElement = new MediaElement();
mediaElement.Source = new Uri(fileLocation, UriKind.Absolute);
mediaElement.LoadedBehavior = MediaState.Play;
The "chopped up behaviour refrs to that I see 2 secs, then it stops for a split second and plays again for a couple of seconds - almost like it cant read the movie fast enough to play it
EDIT 2 Seemed to be fixed when run it on another machine guess the bottle neck is on my machine. Closing question
Closing, see my last update
Related
I've got a little side project going on using SDL2/SDL_mixer and a couple other sound libraries. I've been trying for a while now to synchronize my audio and video but haven't been able to get it anywhere near successfully. All new to this stuff so forgive the poorman's logic and coding. At first I thought to set the delay to SDL_Delay(30) after every frame, and then a few other numbers in that range. Not quite right. Then I tried doing it by getting Ticks. Where I would get the difference between current_ticks and last_ticks and set a delay if the delta between ticks was <=30 and set the delay to 30-delta. Still not quite right (by far). Hoping someone on here with more experience might guide me in the right direction. In regards to the video, it's a visualizer of course, seems like a popular beginners project.
The basic way you synchronize audio and video is that you choose one to use as a timer source and present the other according to that timer. The easiest is generally audio, but because it's generally buffered ahead, you need some method of measuring what time in the audio stream is actually coming out of the speakers. Once you get that, it's just a matter of waiting until the audio reaches the right time for the next video frame and displaying it.
I'm currently developing a WPF application where one of the controls displays a stream of images; much like any webcam. These images originate of an IP camera and can only be accessed by an HTTP Url, which is fixed and always the sames. Now capturing the images is no problem, via
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = uri;
bitmapImage.CacheOption = BitmapCacheOption.None;
bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bitmapImage.EndInit();
return bitmapImage;
This much works. The problem arises when I attempt to hook up several cameras (more than 6), the application chokes and eventually crashes. All cameras run on a separate thread btw.
I've identified the basic problem: creating a (highlevel?) bitmap eats too much resources as I need the app to process about 600 images/sec in real-time (about 30Mb/sec) eventually.
In a nutshell, i'm looking for a way to make this retrieval/rendering process a lot more efficient.
Thanks in advance!
UPDATE:
Forgot to mention perhaps, im working in .NET 4 WPF, the camera itself is a Mobotix M12, accessed by ethernet.
So, if I get this right, each camera has a framerate of 100 fps? (you mention 600 images/second for 6 cams).
With some profiling you could identify the bottleneck?
As a very late update and for anyone still interested - we managed an implementation with the aForge framework http://www.aforgenet.com/aforge/framework
While dated, it can do these kind of things out of the box.
I have tied a MediaElement control to a Slider control.
I am getting my stream from a binary field in a SQL Server database.
I am concerned that there may be some performance issues due to the following:
1. I am storing a byte array that is being retrieved from a web service
2. Anytime I do anything with the MediaElement (i.e. reset position, stop playback, resume playback) I have to reset the source of the MediaElement
The code I am using to set the position is as follows:
private void ResetPlayerWithPosition(double milliseconds = 0)
{
// _wmss is a WaveMediaStreamSource from WAVMss.dll
// audio is of type byte[]
this._wmss = new WaveMediaStreamSource(new MemoryStream(this.audio));
this.playbackController.SetSource(this._wmss);
this.playbackController.MediaOpened += (s, e) =>
{
this.playbackController.Position = TimeSpan.FromMilliseconds(milliseconds);
};
}
My concern is that if the file gets to be large, there will be performance degradation in that the code has to wait for the file to be loaded into the MediaElement's source before the position is reset. If this is the case, does anyone have any suggestions as to how I could make it a bit more efficient?
Thanks in advance for any suggestions.
It's been 1 year 10 months 14 days since I first posted this, and not even a comment or follow-up question. In this time, iOS has made many advancements, Android has released some new flavors, HTML5 and jQuery have matured gracefully, and Microsoft has abandoned Silverlight for Metro.
I have abandoned this solution since support is sparse and on its way to nonexistence. In exchange for Silverlight, I have opted for a HTML5 + jQuery solution. This has enabled me to develop a light weight, Web Method driven, AJAX enabled, browser + device + server independent, cross-platform client in a reduced development time with more flexibility, sustainability, and maintainability.
Silverlight: Another highly innovative yet grossly inefficient technology laid to rest. RIP.
I am trying to record a stream from a webcam using Expression Encoder 4 SDK in WPF I can capture the video & audio streams and record these to disk however they are only recording at a base resolution of 320x240 the webcam is capable of capturing at 720p, how can I record at this resolution. Any help would be appreciated, I have been pulling my hair out trying to solve this all week.
Know this is a bit late but all questions need answers:
These might be a possible solution:
Check to see if your camera has it's own settings on the camera or comes with an installation disk.
for the expression encoder 4 put the video profile quality to max.
Good luck. If you are still around tell me, how it goes.
to change the "size" you can use the following line :
LiveJob.OutputFormat.VideoProfile.Streams[0].Size = new Size(1280,1080)
Or whatever you want it to be.
Encoder also offers a setting page that you can use.
That's what I did and then after setting the outputsize you can do that :
currentJob.OutputFormat.VideoProfile.Streams[0].Size = ((LiveSource)LiveDeviceSource).CropRect.Size;
Only 1 small limitation, you can't change the size while it's recording if you are publishing the source.
I'm attempting to use a large number of short sound samples in a game I'm creating in Silverlight 2. The samples are less than 2 seconds long.
I would prefer to load all the audio samples onto the canvas during the initualization. I have been adding the media element to the canvas and a generic list to manage it. So far, it appears to work.
When I play the sample the first time, it plays perfectly. If it has finished playing and I want to re-use the same element, it cuts off the first part of the sound. To play the sample again, I stop and play the media element.
Is there another method I should use the samples so that the audio is not clipped and good performance is obtained?
Also, it's probably a good idea to make sure that all of your audio samples are brought down to the client side initially. Depending on how you set it up, it's possible that the MediaElements are using their progressive download functionality to get the media files from the server. While there's nothing wrong with this per se (browser caching should be helping you out after the initial download), it does mean that you have to deal with the browser cache, and there are some potential issues there.
Possible steps to try:
Mark your audio files as "Content". This will get them balled up in the .xap.
Load your audio files into MemoryStreams (see Application.GetResourceStream method) and call MediaElement.SetSource().
HTH,
Erik
Some comments:
From MSDN:
Try to limit the number of MediaElement objects you have in your application at once. If you have over one hundred MediaElement objects in your application tree, regardless of whether they are playing concurrently or not, MediaFailed events may be raised. The way to work around this is to add MediaElement objects to the tree as they are needed and remove them when they are not.
You could try to seek to the start of the sample to reset the point currently being played before re-using it with:
mediaelement.Position = new TimeSpan();
See also MSDNs MediaElement.Position.
One techique you can use, although I'm not sure how well it will work in Silverlight, is create one large file with all of your samples joined together (probably with a half-second or so of silence between each). Figure out the timecode for each sample and seek the media element to that position and play. You'll only need as many media elements as simultaneous sounds you want to play.