asp.net core在linux进行上传视频ffmpeg截图
項(xiàng)目要求,視頻要提供一張截圖。在linux使用ffmpeg,沒(méi)有window方便可以直接用exe文件;因?yàn)槲覀兪褂玫牟僮飨到y(tǒng)是centos7.0+ ,必須先安裝;?
?
1、在centos上安裝FFMPEG;?
所以先找了ffmpeg的安裝。一開(kāi)始,是網(wǎng)上一堆教程,全手動(dòng)安裝,安裝過(guò)程遇到一堆問(wèn)題。然后一個(gè)問(wèn)題解決,又遇到另一個(gè),然后了三四個(gè)問(wèn)題后。最后果然放棄安裝。從網(wǎng)上搜索到了yum install一鍵自動(dòng)安裝的。嘗試了,可用。紀(jì)錄 下來(lái)
第一步: 按照自己centOS版本安裝 nux-dextop repository
一下是指令!
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
Now verify that Nux Dextop repository is successfully installed:
$ yum repolist
第二步:yum install ffmpeg
安裝后,查看版本,來(lái)進(jìn)行是否安裝成功判斷;(用whereis ffmpeg可以查看其安裝路徑;)
/usr/bin/ffmpeg -version
?
?
2、在asp.net core進(jìn)行視頻截圖;我上的代碼,也是網(wǎng)上抄過(guò)來(lái)的。代碼寫(xiě)后,在window運(yùn)行正常;然后發(fā)布到linux環(huán)境上,一直這個(gè)報(bào)錯(cuò),遇到:No such file or directory ;
一開(kāi)始以為是命令寫(xiě)錯(cuò),在linux命令行執(zhí)行轉(zhuǎn)換命令,都能正常執(zhí)行,然后又認(rèn)為是linux權(quán)限問(wèn)題;各種嘗試;后面果斷認(rèn)為是asp.net core出問(wèn)題。或是代碼有問(wèn)題;
public string convertVideoImage(string VideoPath = ""){string str_MyProg = AppSettings.GetValue("FfmpegPath");//工具路徑。從上面看,就是/usr/bin/ffmpegif (string.IsNullOrEmpty(VideoPath)){return string.Empty;}string str_CommandArgs = "";var file1 = new FileInfo(VideoPath);if (file1.Exists){try{string save_folder = file1.FullName.Replace(file1.Name, "");string image_file = "video_" + file1.Name.Replace(file1.Extension, ".jpg");//#設(shè)置參數(shù)以直接輸出圖像序列(幀),第四秒str_CommandArgs = "-i " + VideoPath + " -ss 00:00:04 -vframes 1 -an -y -f mjpeg " + save_folder + image_file;System.Diagnostics.ProcessStartInfo cmd_StartInfo = new System.Diagnostics.ProcessStartInfo(str_MyProg, str_CommandArgs);cmd_StartInfo.RedirectStandardError = false; //set falsecmd_StartInfo.RedirectStandardOutput = false; //set falsecmd_StartInfo.UseShellExecute = true; //set truecmd_StartInfo.CreateNoWindow = true; //don't need the black window//創(chuàng)建一個(gè)進(jìn)程,分配它的ProcessStartInfo并啟動(dòng)它System.Diagnostics.Process cmd = new System.Diagnostics.Process();cmd.StartInfo = cmd_StartInfo;cmd.Start();System.Threading.Thread.Sleep(1000);return image_file;}catch (Exception ee){throw new Exception(ee.StackTrace + ee.Message + " for: " + str_MyProg + " " + str_CommandArgs);}}else{throw new Exception("No exists file:" + VideoPath);}}?
上面的代碼,在window執(zhí)行都正確,在linux下,就會(huì)報(bào)找不到路徑(No such file or directory);
在各個(gè)網(wǎng)站上查找,最終問(wèn)題,是出現(xiàn)在 ,
UseShellExecute 一定要設(shè)置為false; cmd_StartInfo.UseShellExecute = false; //set true特紀(jì)錄下來(lái),發(fā)現(xiàn)在asp.net core,用FFMPEG文章的還是比較少;
?
轉(zhuǎn)載于:https://www.cnblogs.com/swordming/p/10304013.html
總結(jié)
以上是生活随笔為你收集整理的asp.net core在linux进行上传视频ffmpeg截图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 怎么还原系统分区 恢复系统分区教程
- 下一篇: Linux 查看磁盘分区、文件系统、磁盘