Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am working on a website which require video uploading and displaying. Uploading, buffering and playing is completed but I want to display the video thumbnails in my Gallery also. How it can be done? I think I should create the thumbnails at uploading time. But how to create thumbnails at upload time, I dont know. Answer this please.....
Posted
Updated 23-May-16 3:47am

Hi, I didn't try it with ASP yet, but MediaDetector should be the right way for you. If you don't won't to use
a 3rd library, you'll almost have no other options than using DShow or DirectX.


Something like this in a BackgroundWorker:

C#
FileInfo finfo = new FileInfo(@"PATH TO TESTFILE");
                
if(string.Compare(finfo.Extension, ".avi", true) == 0 || string.Compare(finfo.Extension, ".mpg", true) == 0 || string.Compare(finfo.Extension, ".wmv", true) == 0)
{
                    string thumb_path = finfo.FullName + ".jpg";
                    if (File.Exists(thumb_path) != true)
                    {
                        MediaDetector capture_thumb = new MediaDetector();
                        capture_thumb.LoadMedia(finfo.FullName);
                        
                        int width = 128;
                        int height = width;
                        int stride = width / 8;
                        byte[] pixels = new byte[height * width];

                        // Define the Bitmap palette
                        BitmapPalette myPalette = BitmapPalettes.Halftone256;

                        // Creates a new empty image with palette settings
                        BitmapSource image =
                            BitmapSource.Create(
                            width,
                            height,
                            96,
                            96,
                            PixelFormats.Indexed1,
                            myPalette,
                            pixels,
                            stride);


                        Stream stream = new FileStream(finfo.FullName + ".jpg", FileMode.Create);
                        JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                        encoder.FlipHorizontal = false;
                        encoder.FlipVertical = false;
                        encoder.QualityLevel = 80;
                        
 encoder.Frames.Add(BitmapFrame.Create(capture_thumb.GetImage(new TimeSpan(0, 0, 30))));
                        encoder.Save(stream);
                       
                  }
} 


Cheers,
Bjoern
 
Share this answer
 
v5
Comments
NeptuneHACK! 16-Feb-12 20:58pm    
5
Hi there..

Try visiting this website.. I think this will be very much important..
http://jasonjano.wordpress.com/2010/02/09/a-simple-c-wrapper-for-ffmpeg/[^]

All the best.. :)
 
Share this answer
 
v2
Comments
ProEnggSoft 25-Feb-12 3:17am    
Good link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900