我怎样才能保存视频为图像的第一帧? [英] How can I save first frame of a video as image?

查看:668
本文介绍了我怎样才能保存视频为图像的第一帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提取上传视频的第一帧,并保存为图像文件。结果
可能的视频格式有MPEG,AVI和WMV。

I want to extract first frame of uploaded video and save it as image file.
Possible video formats are mpeg, avi and wmv.

还有一个要考虑的是,我们正在创建一个ASP.NET网站。

One more thing to consider is that we are creating an ASP.NET website.

推荐答案

您可以使用FFMPEG作为单独的进程(最简单的方法),并让它去code第一IDR为您服务。在这里,你有一个具有GetThumbnail()方法的类FFMPEG,它传递的视频文件的地址,要做出的JPEG图像的地址和分辨率你想要的形象是:

You could use FFMPEG as a separate process (simplest way) and let it decode first IDR for you. Here you have a class FFMPEG that has GetThumbnail() method, to it you pass address of video file, address of the JPEG image to be made, and resolution that you want the image to be:

using System.Diagnostics;
using System.Threading; 

public class FFMPEG
{
    Process ffmpeg;

    public void exec(string input, string output, string parametri)
    {
        ffmpeg = new Process();

        ffmpeg.StartInfo.Arguments = " -i " + input+ (parametri != null? " "+parametri:"")+" "+output; 
        ffmpeg.StartInfo.FileName = "utils/ffmpeg.exe";
        ffmpeg.StartInfo.UseShellExecute = false;
        ffmpeg.StartInfo.RedirectStandardOutput = true;
        ffmpeg.StartInfo.RedirectStandardError = true;
        ffmpeg.StartInfo.CreateNoWindow = true;

        ffmpeg.Start();
        ffmpeg.WaitForExit();
        ffmpeg.Close();     
    }


    public void GetThumbnail(string video, string jpg, string velicina)
    {
        if (velicina == null) velicina = "640x480";
        exec(video, jpg, "-s "+velicina);
    }
}

使用这样的:

FFMPEG f = new FFMPEG();
f.GetThumbnail("videos/myvid.wmv", "images/thumb.jpg", "1200x223");

对于这个工作,你必须有ffmpeg.exe文件夹/ utils的,或改变code定位ffmpeg.exe。

For this to work, you must have ffmpeg.exe in folder /utils, or change the code to locate ffmpeg.exe.

有其他方式在.NET中使用FFMPEG,像.NET包装,你可以谷歌他们。他们基本上做同样的事情在这里,只有更好。所以,如果FFMPEG得到你的工作做好,我会推荐将使用.NET包装。

There are other ways to use FFMPEG in .NET, like .NET wrappers, you could google for them. They basically do the same thing here, only better. So if FFMPEG gets your job done, I'd recomend to use .NET wrapper.

这篇关于我怎样才能保存视频为图像的第一帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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