Repost of previous question: MediaElement in WPF - c#

I am looking for a solution for a question that was already posted but did not answer correctly, thanks in advance.
Show first frame of video in WPF MediaElement

The solution in the other thread should work but you could approach it differently.
Basically, to avoid having to load the video just to grab the first frame you could generate a static image that is the frame you want to show. If you are encoding the video most encoding software will generate a thumbnail for you for this purpose. If not you can screen shot a frame and use that
Then display that image in a normal WPF image control when the movie is not playing. When the user plays the video use a trigger to hide the image and show the video.
This will give you the effect you want.
Downside: This static image will get out of sync with the video if your video file is updated (you would need to regenerate the thumbnail in this case)

Related

How can I extract the duration of a GIF animation from a file in UWP

I found this article http://web.archive.org/web/20130820015012/http://madskristensen.net/post/Examine-animated-Gife28099s-in-C.aspx (very helpful).
Unfortunately, our favorite hobbled race horse, UWP, does not include the required APIs.
I am working on a slide show app and would like to allow the user to advance an image with a set timing, except if it is an animated GIF, then I want to show the full animation once...
So, where can I extract the duration of the complete GIF animation, using the UWP on board tools?

Capturing Images from Playing Video File

I am developing C# desktop application and referring this link to Play video file http://www.codeproject.com/Articles/2632/DirectShow-MediaPlayer-in-C , now from this playing video file ,when I click on this panel (shown in above link ) how to capture Images from playing video file,I searched but I found all examples showing capturing Images from some device(for eg.webcam,etc..) ,In my case Its not device it's file which I am browsing from Directory and Playing ,as I am new to this Video capturing Please direct me how I can do this
"Capture" normally refers to image acquisition when you obtain the image from external source. You want to take a copy of currently displayed video frame instead. There are several ways to do it and when it comes to playback when video is being visualized, the video renderers typically offer GetCurrentImage method which returns a copy of currently displayed video frame, possibly even converted to RGB.
Method syntax slightly differs between video renderer versions.
See previous topics on achieving this:
take picture from webcam c# (references sample application from DirectShow.NET)
IBasicVideo CetCurrentImage catastrophic failure(DirectShow.NET)
Also:
Best DirectShow way to capture image from web cam preview ? SampleGrabber is deprecated
Grabbing images from a DVD using direct show
You need a filter which captures screen and sends the video down the stream.
In the DirectShow Library there is a sample filter called PushSource and inside there is PushSourceDesktop.
At Codeplex there are Examples like this (Click me) or Information (Click me) about Filters.
You can also use a "SampleGrabber" DirectShow filter: just place it in the filter chain between your source filter and render filter.
More info about SampleGrabber:
see MSDN

Progressive Image Loading Technique

When i am searching image through Google Link to view
it load blur image first then load high-quality image progressively as image below
after some time
but by inspecting that image i found This Link and by going that link it load complete image or loaded image is viewed as top to down preview as below picture.
how it happened?
what technique Google use for Progressive loading of image.
how can i do loading of image as Google do in my site?
is it possible using c# ?
It seems to me that there is no actual progressive loading going on in Google Images.
When you click on an image thumbnail, there is a quick animation "unveiling" the full resolution image. While the animation is happening, the image that is partly displayed is actually just the thumbnail (size 251x201), but upscaled to the resolution of the larger image (1280X1024).
The way to do this upscaling in HTML should be something like this:
<img src="thumbnail.jpg" width="251" height="201">
The full resolution image is then displayed when the animation is completed, replacing the upscaled thumbnail. So this is not a progressive loading after all.
Still, you might want to read about Progressive JPEG: http://en.wikipedia.org/wiki/JPEG#JPEG_compression.

Animation using List<Image>

I'm skeptical if I'm doing this the right way.
I have to play an animation at about 60fps. I'm using a List<Image> to load all the frames at the time of initialization. And then using a System.Timers.Timer to call an event at every 10ms which will change the image in the pictureBox.
List<Image> imageList = new List<Image>();
private static Timer_Event(o, e)
{
pictureBox.Image = imageList[i++];
}
So, am I doing this right? Is there a better approach?
What you're describing seems unlikely to work in a robust fashion. Here's a brief summary:
In my experience, timers aren't generally accurate. Since timer messages go through the Windows Message pump, they can only move as fast as your Windows UI processes messages. Any application that interferes with messages will cause your timers to stutter, although careful work can prevent most of this. Some classic discussion of timers here: Winforms Timer for Dummies
In general, List is a very inefficient way to store images. For a one-second animation at 60 frames per second, you will have to hold 60 images in memory and decompress each one individually.
Here are some possible solutions, and the tradeoffs they entail:
Full Motion Video
If you are looking to present a full motion video on your form, you should really consider using a MediaElement (for WPF applications: http://www.c-sharpcorner.com/uploadfile/dpatra/media-element-in-wpf/ ) or a MediaPlayer object (for WinForms applications: http://msdn.microsoft.com/en-us/library/bb383953(v=vs.90).aspx ).
This will allow you to play a lengthy video that contains extremely high quality images, varied compression, and start or stop the playback arbitrarily. However, the startup and memory usage requirements of a full video player are greater than just displaying a single image on screen. You will find that your application takes a moment to initialize the video subsystem, which may be annoying.
Animated Images
It's possible to show an animated image in a picturebox in Windows Forms or WPF. You would simply generate the animated image - generally using a GIF animation file. This will work smoothly for a majority of simple animations, and it's possible to get free-to-use animated GIFs from websites like this one: http://www.chimply.com/Generator
Here's a walkthrough of how to place an animated GIF on your form: http://trompelecode.com/2010/12/animated-progress-indicator-in-csharp-windows-forms/
Sprite Animation
Let's say you need to accurately represent each image exactly (which isn't necessary if you're simply trying to look appealing), and that you don't want the overhead of a video system (which is okay if you're only playing a second or two worth of animations). What you want to do then is create a single composite "sprite" image. This reduces the memory overhead requirements of your application and reduces the amount of time decompressing files.
For example, here's a website that generates PNG sprites for you: http://wearekiss.com/spritepad
Once you generate an image with sprites, you can place it within a picturebox and animate the image by changing the relative position of the image within the picturebox. Here's a walkthrough of how to accomplish this: C# picturebox load image with an offset
Summary
Any way you choose to display an animated image, you will have some tradeoffs. I like to pick the simplest possible solution for myself - and in my case I like to use an animated GIF image. Good luck animating!
The .avi is alternative otherwise, however, if you have bunch of images than probably utilizing threads/timers apparently seems to be the way forward.
The easiest way would be to use an animated gif in that pictureBox and don't mess with timers.
You may also be able to put your animation together using WPF or Silverlight ... if you need the animation to be interactive or programmatically controllable that would probably be the way to go.
If on the other hand the animated content is static then AVI (or MPEG etc.) is probably your best bet.
You don't say exactly what you're trying to accomplish so I can't be sure.

Fading a video clip to black

I have a requirement to play a video file in C# (with audio) then to be able to fade out the video to a black screen then fade in another video.
I've looked at DirectShow & DirectShowNet however I'm none the wiser. I've got a simple app to play a video with a time counter etc, however I'm flummoxed with filters & graphs.
What direction do I need to go in?
Create a WPF Apllication and use the MediaElement Control to play the videos. Use the events of the MediaElement (for example MediaEnded) to detect when to start fadeout / switch streaming source / fadein. The easiest way for the fadeout is to change opacity of the Mediaelement.
The MediaElement should be able to play all videos which have a directshow filter installed on your system.
Are you using WPF?
With WPF you could do this in a variety of ways. eg you could simply animate the video control's (MediaElement) opacity.
NOTE: you can use WPF controls inside of a Winforms app. See this video for how to do this.
One solution, although I would consider it a hack, would be to draw a black overlay ontop of the viewable area of the video. You can adjust the transparency of the overlay based on the frame/time of the video. Essentially, you would fire off a timed event that would slowly remove or add transparency to the overlay based on where in the video you want to starting fading.

Categories