创建视频缩略图 [英] Creating Video Thumbnails

查看:119
本文介绍了创建视频缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在一个需要视频上传和显示的网站上工作。上传,缓冲和播放已完成,但我也希望在我的图库中显示视频缩略图。怎么做?我想我应该在上传时创建缩略图。但是如何在上传时创建缩略图,我不知道。请回答这个.....

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.....

推荐答案

我还没有尝试使用ASP,但MediaDetector应该是适合你的方式。如果您不使用

a第3库,除了使用DShow或DirectX之外,您几乎没有其他选择。





在BackgroundWorker中有这样的事情:



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:

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);
                       
                  }
} 





干杯,

Bjoern



Cheers,
Bjoern


你好..



尝试访问这个网站..我认为这将非常重要..

http://jasonjano.wordpress.com/2010/ 02/09 / a-simple-c-wrapper-for-ffmpeg / [ ^ ]



一切顺利.. :))
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.. :)


这篇关于创建视频缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆