Linux下安装ffmpeg
官网下载:http://ffmpeg.org/download.html
下载之后上传至Linux准备安装,首先解压安装包(注意文件后缀名称通过不同的解压命令解压)
tar -zxvf ffmpeg-4.1.6.tar.gz
cd ffmpeg-4.1.6/
如果现在执行configure配置的话,可能会报如下的错误:
看来是需要安装yasm
Linux下安装yasm
官网下载:http://yasm.tortall.net/Download.html
下载之后上传至Linux准备安装,解压、安装
tar -xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install
安装成功之后继续回到ffmpeg解压后的目录,执行下面命令编译并安装
./configure --enable-shared --prefix=/opt/ffmpeg
make:编译过程有点长
make install
make install会把ffmpeg相关执行程序、头文件、lib库安装在/opt/ffmpeg/下
耐心等待完成之后执行
cd /opt/ffmpeg/
进入安装目录,查看一下发现有bin,include,lib,share这4个目录
bin是ffmpeg主程序二进制目录
include是C/C++头文件目录
lib是编译好的库文件目录
share是文档目录
然后进入bin目录,执行
./ffmpeg -version
查看当前版本的详细信息,默认情况下一般会出现错误
我这里出现了ffmpeg编译错误,提示找不到相应的shared libraries :libavdevice.so.58
ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
查看需要哪些依赖
ldd ffmpeg
先find一下
find /usr -name 'libavdevice.so.58'
没有直接
vi /etc/ld.so.conf
在内容页中添加一行
/opt/ffmpeg/lib
退出执行ldconfig使配置生效
sudo ldconfig
编辑环境变量
vim /etc/profile:编辑写入↓
PATH=/opt/ffmpeg-4/bin/:$PATH
source /etc/profile
现在再次执行./ffmpeg -version 显示就正常了
运行截图命令
ffmpeg -i rtmp://222.254.85.57:1935/live/livestream -f image2 -ss 5 -vframes 1 -s 100*100 wwwroot/Upload/VideoPhotograph/chid310000003-1603181424666.jpg
成功
中间通过程序调用linux命令遇见的问题
System.ComponentModel.Win32Exception (2): No such file or directory\n at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)\n at System.Diagnostics.Process.StartCore(
试了好几个小时一致有问题(路径,文件名的大小写,权限等各种常见问题都不是),查阅了N多资料测试后都没效果,,连调用一个hello word控制台程序都不能,一度怀疑是运行环境的问题,后来在下班前关掉Shell后想想再试一次测试发现直接能运行成功了超郁闷但是还是不知道原因所在
没有帐号? 现在注册.