Linux下使用ffmpeg自动将视频转换为flv的shell脚本
有了ffmpeg,还需要把指定的视频文件用shell脚本批量转换。
随手写了一个,已经可以实现简单功能,代码还需要优化!
#Having install ffmpeg, we need change the video file to flv.
#!/bin/sh
#created by 2hei
#set path
FtpPwd=”/home/2hei”
PlayPwd=”/usr/local/video”
wwwPwd=”/usr/local/video/htdocs”
FFM=”/opt/ffmpeg/bin/ffmpeg”
/opt/ffmpeg/bin/ffmpeg -i “/home/u2isme/ffmpeg/aa.wma” -y -ab 32
-ar 22050 -b 800000 -s 640*480 “/home/u2isme/ffmpeg/aa.flv”
#get user upload dir
ls -l $FtpPwd| grep ^d |awk ‘{print $9}’ > $PlayPwd/dirlist
while read LINE
do
ls -l $FtpPwd/$LINE | awk ‘{print $9}’ > $PlayPwd/inlist
#get filename
while read FILE
do
NowSuf=`echo $FILE|awk -F. ‘{print $1}’`
cd $wwwPwd
if [ -d $wwwPwd/$LINE ]
then
$FFM -i “$FtpPwd/$LINE/$FILE” -y -ab 32 -ar 22050 -b 800000 -s
640*480 “$wwwPwd/$LINE/$NowSuf.flv” #create flv
$FFM -i “$wwwPwd/$LINE/$NowSuf.flv” -y -f image2 -t 1 -s
100*100 “$wwwPwd/$LINE/$NowSuf.jpg”
else
mkdir $wwwPwd/$LINE
$FFM -i “$FtpPwd/$LINE/$FILE” -y -ab 32 -ar 22050 -b 800000 -s
640*480 “$wwwPwd/$LINE/$NowSuf.flv” #create flv
$FFM -i “$wwwPwd/$LINE/$NowSuf.flv” -y -f image2 -t 1 -s
100*100 “$wwwPwd/$LINE/$NowSuf.jpg”
fi
done < $PlayPwd/inlist
rm -rf $FtpPwd/$LINE
done < $PlayPwd/dirlist
rm -rf $PlayPwd/dirlist
rm -rf $PlayPwd/inlist
最活跃的读者