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;

            }
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章