zoukankan      html  css  js  c++  java
  • netcore linux ffmpeg 首帧图

    第一步  
    On CentOS/RHEL 6.*:   $ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm On CentOS/RHEL 7:   $ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm   $ yum repolist 第二步:yum install ffmpeg
    安装后,查看版本,来进行是否安装成功判断;(用whereis ffmpeg可以查看其安装路径;)
    
    /usr/bin/ffmpeg -version
     /// <summary>
            /// 获取视频首帧图
            /// </summary>
            /// <param name="vediofilepath"></param>
            /// <param name="directImagedirectory"></param>
            /// <param name="ffmpegpath"></param>
            /// <returns></returns>
            public static string GetVedioFirstImage(string vediofilepath, string directImagedirectory, string ffmpegpath)
            {
                if (string.IsNullOrEmpty(vediofilepath))
                {
                    return string.Empty;
                }
                string str_CommandArgs = "";
                var file1 = new FileInfo(vediofilepath);
                if (file1.Exists)
                {
                    try
                    {
                        //string save_folder = file1.FullName.Replace(file1.Name, "");
                        //string image_file = "video_" + file1.Name.Replace(file1.Extension, ".jpg");
                        var basepath = directImagedirectory + DateTime.Now.ToString("yyyyMMdd") + "/";
                        if (!Directory.Exists(directImagedirectory))
                        {
                            Directory.CreateDirectory(directImagedirectory);
                        }
                        if (!Directory.Exists(basepath))
                        {
                            Directory.CreateDirectory(basepath);
                        }
                        //string image_file = "video_" + file1.Name.Replace(file1.Extension, ".jpg");
                        string image_file = basepath + Guid.NewGuid().ToString("N") + ".jpg";
                        //#设置参数以直接输出图像序列(帧),第2秒
                        //str_CommandArgs = "-i " + vediofilepath + " -ss 00:00:02 -vframes 1 -an -y  -f mjpeg " + image_file;
                        str_CommandArgs = "-i " + vediofilepath + "  -y -f   image2  -ss 1 -vframes 1   " + image_file;
                        System.Diagnostics.ProcessStartInfo cmd_StartInfo = new System.Diagnostics.ProcessStartInfo(ffmpegpath, str_CommandArgs);
                        cmd_StartInfo.RedirectStandardError = false; //set false
                        cmd_StartInfo.RedirectStandardOutput = false; //set false
                        cmd_StartInfo.UseShellExecute = false; //set true
                        cmd_StartInfo.CreateNoWindow = true;  //don't need the black window
                                                              //创建一个进程,分配它的ProcessStartInfo并启动它
                        System.Diagnostics.Process cmd = new System.Diagnostics.Process();
                        cmd.StartInfo = cmd_StartInfo;
                        cmd.Start();
                        cmd.WaitForExit();
                        //System.Threading.Thread.Sleep(1000);
    
    
                        return image_file;
                    }
                    catch (Exception ee)
                    {
                        throw new Exception(ee.StackTrace + ee.Message + " for: " + vediofilepath + " " + str_CommandArgs);
                    }
                }
                else
                {
                    return string.Empty;
    
                }
            }
  • 相关阅读:
    ADO.NET的记忆碎片(四)
    ADO.NET的记忆碎片(八)
    卡特兰数 应用
    hdu 1249 三角形
    hdu 1143
    nyist 93 汉诺塔(三)
    hdu 1123 Train Problem II
    hdu 1133 Buy the Ticket
    hdu 1022 Train Problem I
    nyist 610 定长覆盖
  • 原文地址:https://www.cnblogs.com/chenyishi/p/12302053.html
Copyright © 2011-2022 走看看