安装格式转换器ffmpeg,及简单的批量转换脚本

ffmpeg是安装在linux的一个音视频转换程序,格式工厂等软件的核心便是ffmpeg,听说格式工厂违背了gpl协议,具体就不清楚啦。

官方安装文档:http://trac.ffmpeg.org/wiki/CompilationGuide/Centos

一、下载安装包:
1、x264-snapshot-20170814-2245-stable.tar.bz2 (264解码器)

2、x265_2.5.tar.gz (265解码器)

2、ffmpeg-3.3.3.tar.bz2

安装依赖程序

yum -y install yasm-devel.x86_64

编译安装

/configure --prefix=/usr/local/ffmpeg --enable-gpl  --enable-shared  --enable-libx264  --enable-libx265 --docdir=/usr/share/doc/ffmpeg-3.3.3
(--enable-libx264 和 --enable-libx265 为相应解码器,要先下载安装)

此时如果报“x265 not found using pkg-config”错误,那么检查/usr/local/lib/pkgconfig/x265.pc,如果这个文件不存在那么把你编译x265时所指定的目录中拷贝过来
原因是需要设置 PKG_CONFIG_PATH,通过pkg-config去指定路径自动寻找需要链接的依赖库
同时,就不需要使用  --extra-cflags=-I
		    --extra-cxxflags=-I
		    --extra-ldflags=-L来指定依赖库路径
	使用方法:在./configure之前输入export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH(此路径为.pc文件所在路径),可使用echo $PKG_CONFIG_PATH查看  
echo "/usr/local/lib/" >> /etc/ld.so.conf
ldconfig -v
(必要的时候执行一下,时间太久,有点忘记了)
make && make install

二、验证

进入安装目录

cd /usr/local/ffmpeg/bin

./ffmpeg

出现版本信息和编译信息说明安装完成。

ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
  configuration: --prefix=/data1/ffmpeg-3.3.3 --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

三、简单的批量转换脚本

#!/bin/bash

for a in `find /data1/html/Public/Upload/Animation/ -type f -name "*.mp4"`
do

cd $(dirname ${a})
dir=`pwd |awk -F "/" '{print $NF}'`

if [ ! -d "/data1/html/Public/Upload/Animation-convert/$dir" ]; then
	mkdir -p  /data1/html/Public/Upload/Animation-convert/${dir}
fi
	echo $(date) >> /var/log/ffmpeg.log
	echo -e "start convert $a " >> /var/log/ffmpeg.log
ffmpeg -i $a -vcodec libx265 /data1/html/Public/Upload/Animation-convert/${dir}/$(basename ${a}) >> /var/log/ffmpeg.log
##basename  获取文件本身名称,对应的  dirname  则为获取该文件的路径

if [ $? -eq 0  ];then 
	echo -e "convert $(basename ${a}) done" >> /var/log/ffmpeg.log
else 
	echo -e "convert $(basename ${a}) failed" >> /var/log/ffmpeg.log
fi
	# echo -e "done \n"   >> /var/log/ffmpeg.log
	
done



你可能感兴趣的:(linux软件相关)