Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 00:00:01-f image2\”,destFile\”; fullCommand=string.Concat(ffPath,strCommand); pth=新工艺(); pth.StartInfo.FileName=ffPath; pth.Star_Image Processing_Ffmpeg_Video Capture - Fatal编程技术网

Image processing 00:00:01-f image2\”,destFile\”; fullCommand=string.Concat(ffPath,strCommand); pth=新工艺(); pth.StartInfo.FileName=ffPath; pth.Star

Image processing 00:00:01-f image2\”,destFile\”; fullCommand=string.Concat(ffPath,strCommand); pth=新工艺(); pth.StartInfo.FileName=ffPath; pth.Star,image-processing,ffmpeg,video-capture,Image Processing,Ffmpeg,Video Capture,00:00:01-f image2\”,destFile\”; fullCommand=string.Concat(ffPath,strCommand); pth=新工艺(); pth.StartInfo.FileName=ffPath; pth.StartInfo.Arguments=strCommand; pth.StartInfo.UseShellExecute=false; pth.StartInfo.CreateNoWindow=true; pth.Start(); pth.WaitF

00:00:01-f image2\”,destFile\”; fullCommand=string.Concat(ffPath,strCommand); pth=新工艺(); pth.StartInfo.FileName=ffPath; pth.StartInfo.Arguments=strCommand; pth.StartInfo.UseShellExecute=false; pth.StartInfo.CreateNoWindow=true; pth.Start(); pth.WaitForExit(); this.Cursor=Cursors.Default; } 私有int GetVideoLength(字符串ffmpeg,字符串源文件) { //exec('start C:\Inetpub\ffmpeg\ffmpeg-i“D:/Jaime flex.wmv“2>&1|grep”Duration“| cut-D”“-f4-| sed s/,/”,$output); 字符串结果=”; string strCommand=string.Concat( “-i\”,源文件“\”2>”; 流程pth=新流程(); pth.StartInfo.FileName=ffmpeg; pth.StartInfo.Arguments=strCommand; pth.StartInfo.UseShellExecute=false; pth.StartInfo.CreateNoWindow=true; pth.StartInfo.RedirectStandardOutput=true; pth.StartInfo.RedirectStandardError=true; pth.Start(); pth.WaitForExit(); //结果=pth.StandardOutput.ReadToEnd(); //结果=pth.StandardError.ReadToEnd(); 字符串str=“”; 字符串[]ssplit; char[]splitChars=new char[]{'.',''}; 整数秒=0; 而(!pth.StandardError.EndOfStream) { str=pth.StandardError.ReadLine(); 如果(str.Contains(“持续时间”)) { ssplit=str.Split(splitChars); seconds=GetSeconds(ssplit[3]); } } 返回秒数; } private int GetSeconds(字符串p) { 字符串[]ssplit=p.Split(“:”); int ho=转换为32(ssplit[0])*120; int mi=转换为32(ssplit[1])*60; int se=转换为32(ssplit[2]); 返回ho+mi+se; } } 公共类MediaItem { 公共字符串短名称{get;set;} 公共字符串全名{get;set;} 公共字符串iconName{get;set;} 公共媒体mainType mainType{get;set;} 公共媒体子类型子类型{get;set;} 公共长长度{get;set;} } 公共枚举MediaMainType { MMT\u视频=0,MMT\u图像,MMT\u图标,MMT\u NOTMEDIA } 公共枚举媒体子类型 { MST_JPG=0,MST_GIF,MST_BMP,MST_PNG,MST_MP4,MST_WMV,MST_FLV,MST_NOTMEDIA 3.
您将如何选择特定的视频帧作为缩略图?选择一个随机帧是否足够好,或者您是否希望选择一个最能代表特定视频的帧?您能否确切地说明问题所在?ffmpeg似乎对您有所帮助,但太费时间了。如果问题是文件的数量,那么ffmpeg生成,您可能可以限制它。
    public partial class ThumbSelector : Form
{
    public List<MediaItem> videoList = new List<MediaItem>();
    private Random ra = new Random();
    int iCount = 1;

    public ThumbSelector()
    {
        InitializeComponent();
    }

    public void FillList()
    {
        if(videoList.Count() < 1)
            return;
        //only get mp4 files
        var videosOnly = from n in videoList
                      where n.mainType == MediaMainType.MMT_VIDEO
                      select n;
        lbVideoList.Items.Clear();
        foreach (MediaItem mi in videosOnly)
        {
            lbVideoList.Items.Add(mi.shortName);
        }
    }

    private void lbVideoList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(lbVideoList.SelectedItems.Count < 1)
            return;
        CreateThumbs(lbVideoList.SelectedItems[0].ToString());
    }

    private void CreateThumbs(string fShortName)
    {
        string sourceVideoName;
        int sourceLength = 0;
        int quarter = 0;
        int half = 0;
        int threequarter = 0;
        string destDir = @"C:\Users\robert\dwhelper\VideoIcons";

        string ffPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ffmpeg.exe";

        var sname = (from n in videoList
                    where n.shortName == fShortName
                     select n).First();
        sourceVideoName = sname.fullName;
        sourceLength = GetVideoLength(ffPath, sourceVideoName);

        quarter = sourceLength / 4;
        half = sourceLength / 2;
        threequarter = quarter * 3;
        Image im1;
        Image im2;
        Image im3;
        string n1;
        string n2;
        string n3;


        while (File.Exists(string.Concat(destDir, @"\", "x1_", iCount.ToString(), ".jpg")))
        {
            ++iCount;
        }
        n1 = string.Concat("x1_", iCount.ToString(), ".jpg");
        ++iCount;
        while (File.Exists(string.Concat(destDir, @"\", "x2_", iCount.ToString(), ".jpg")))
        {
            ++iCount;
        }
        n2 = string.Concat("x2_", iCount.ToString(), ".jpg");
        ++iCount;
        while (File.Exists(string.Concat(destDir, @"\", "x3_", iCount.ToString(), ".jpg")))
        {
            ++iCount;
        }
        n3 = string.Concat("x3_", iCount.ToString(), ".jpg");

        pic1.Image = null;
        pic2.Image = null;
        pic3.Image = null;


        CreateThumbs(sname, quarter, n1);
        im1 = Image.FromFile(string.Concat(destDir, @"\", n1));
        pic1.Image = im1;
        CreateThumbs(sname, half, n2);
        im2 = Image.FromFile(string.Concat(destDir, @"\", n2));
        pic2.Image = im2;
        CreateThumbs(sname, threequarter, n3);
        im3 = Image.FromFile(string.Concat(destDir, @"\", n3));
        pic3.Image = im3;

    }

    private void CreateThumbs(MediaItem mi, int timeIn, string outName)
    {
        this.Cursor = Cursors.WaitCursor;
        Process pth;
        string destDir = @"C:\Users\robert\dwhelper\VideoIcons";
        string sourceFile;
        string destFile;
        string ffPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ffmpeg.exe";
        string strCommand;
        string fullCommand;
        string[] ssplit;

        sourceFile = mi.fullName;
        ssplit = mi.shortName.Split('.');
        destFile = string.Concat(destDir, "\\", outName);

        strCommand = string.Concat(
            " -i \"", sourceFile, "\" -r 1 -ss ", timeIn.ToString(), " -t 00:00:01 -f image2 \"", destFile, "\"");

        fullCommand = string.Concat(ffPath, strCommand);

        pth = new Process();
        pth.StartInfo.FileName = ffPath;
        pth.StartInfo.Arguments = strCommand;
        pth.StartInfo.UseShellExecute = false;
        pth.StartInfo.CreateNoWindow = true;

        pth.Start();
        pth.WaitForExit();

        this.Cursor = Cursors.Default;

    }

    private int GetVideoLength(string ffmpeg, string sourceFile)
    {
        //exec('start C:\Inetpub\ffmpeg\ffmpeg -i "D:/Jaime-flex.wmv" 2>&1 | grep "Duration" | cut -d " " -f 4 - | sed s/,//', $output);
        string result = "";
        string strCommand = string.Concat(
                " -i \"", sourceFile, "\" 2>");
        Process pth = new Process();
        pth.StartInfo.FileName = ffmpeg;
        pth.StartInfo.Arguments = strCommand;
        pth.StartInfo.UseShellExecute = false;
        pth.StartInfo.CreateNoWindow = true;
        pth.StartInfo.RedirectStandardOutput = true;
        pth.StartInfo.RedirectStandardError = true;
        pth.Start();


        pth.WaitForExit();
        //result = pth.StandardOutput.ReadToEnd();
        //result = pth.StandardError.ReadToEnd();
        string str = "";
        string[] ssplit;
        char[] splitChars = new char[] { '.', ' ' };
        int seconds = 0;
        while (!pth.StandardError.EndOfStream)
        {
            str = pth.StandardError.ReadLine();
            if (str.Contains("Duration"))
            {
                ssplit = str.Split(splitChars);
                seconds = GetSeconds(ssplit[3]);
            }
        }
        return seconds;
    }

    private int GetSeconds(string p)
    {
        string[] ssplit = p.Split(':');
        int ho = Convert.ToInt32(ssplit[0]) * 120;
        int mi = Convert.ToInt32(ssplit[1]) * 60;
        int se = Convert.ToInt32(ssplit[2]);

        return ho + mi + se;
    }

}
public class MediaItem
{
    public string shortName { get; set; }
    public string fullName { get; set; }
    public string iconName { get; set; }
    public MediaMainType mainType { get; set; }
    public MediaSubType subType { get; set; }
    public long length { get; set; }
}
public enum MediaMainType
{
    MMT_VIDEO = 0, MMT_IMAGE, MMT_ICON, MMT_NOTMEDIA
}
public enum MediaSubType
{
    MST_JPG = 0, MST_GIF, MST_BMP, MST_PNG, MST_MP4, MST_WMV, MST_FLV, MST_NOTMEDIA
3