码迷,mamicode.com
首页 > Web开发 > 详细

netcore linux ffmpeg 首帧图

时间:2020-02-13 09:58:31      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:lse   class   folder   启动   ring   ror   yum   trace   exists   

第一步  
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;

            }
        }

 

netcore linux ffmpeg 首帧图

标签:lse   class   folder   启动   ring   ror   yum   trace   exists   

原文地址:https://www.cnblogs.com/chenyishi/p/12302053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!