分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 02:31责任编辑:白小东关键词:暂无标签

项目要求,视频要提供一张截图。在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文章的还是比较少;

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

原文地址:https://www.cnblogs.com/swordming/p/10304013.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved