asp.net core在linux进行上传视频ffmpeg截图

项目要求,视频要提供一张截图。在linux使用ffmpeg,没有window方便可以直接用exe文件;因为我们使用的操作系统是centos7.0+ ,必须先安装; 

 

1、在centos上安装FFMPEG; 

所以先找了ffmpeg的安装。一开始,是网上一堆教程,全手动安装,安装过程遇到一堆问题。然后一个问题解决,又遇到另一个,然后了三四个问题后。最后果然放弃安装。从网上搜索到了yum install一键自动安装的。尝试了,可用。纪录 下来

第一步: 按照自己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


安装后,查看版本,来进行是否安装成功判断;(用whereis ffmpeg可以查看其安装路径;)


/usr/bin/ffmpeg -version

 

 

2、在asp.net core进行视频截图;我上的代码,也是网上抄过来的。代码写后,在window运行正常;然后发布到linux环境上,一直这个报错,遇到:No such file or directory ;

一开始以为是命令写错,在linux命令行执行转换命令,都能正常执行,然后又认为是linux权限问题;各种尝试;后面果断认为是asp.net core出问题。或是代码有问题;

 public string convertVideoImage(string VideoPath = "")
        {
            string str_MyProg = AppSettings.GetValue("FfmpegPath");//工具路径。从上面看,就是/usr/bin/ffmpeg
            if (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");
                    //#设置参数以直接输出图像序列(帧),第四秒
                    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 false
                    cmd_StartInfo.RedirectStandardOutput = false; //set false
                    cmd_StartInfo.UseShellExecute = true; //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();
                    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执行都正确,在linux下,就会报找不到路径(No such file or directory);

在各个网站上查找,最终问题,是出现在 ,

UseShellExecute 一定要设置为false; 
 cmd_StartInfo.UseShellExecute = false; //set true 

特纪录下来,发现在asp.net core,用FFMPEG文章的还是比较少;

 

转载于:https://www.cnblogs.com/swordming/p/10304013.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值