ffmpeg批量获取视频第一帧shell脚本
#!/bin/bash
echo "ffmpegmp4"
ffmpegmp4(){
original=$1
echo $original
# check whether file is exist
# if $original de chang du wei 0 huo bu $original bu shi chang gui wenjian
if [ -z $original ] || [ ! -f $original ]; then
echo "file $original not exist!"
exit
fi
# check whether file is end of '.mp4' or whether it is h264 encodeing.
# 显示 以 .mp4结尾的文件名字或者 h264编码的文件名字 不需要转换的啊
#if [ `ffprobe -show_streams $1 | grep "codec_name=h264"` ]; then
# echo "Don't need convert!"
# else
# target=${original%.*}_h264.${original##*.} 截取文件最长的字符串,比如 文件的名字是 a.html.dds.dd.ddedeers.sd.date.mp4, 在这里值截取 .mp4 以前的字符为target
target=${original%.*}.${original##*.}
tmp=${original%.*}`date +%N`.mp4 # 文件的临时名字
picpath=${original%.*}_pic.jpg
## ffmpeg -i $original -ab 56 -ar 22050 -qscale 8 -codec:v libx264 -c:a copy -movflags faststart -r 15 -s 480*320 -y $tmp
ffmpeg -i $original -ab 56 -ar 22050 -qscale 8 -codec:v libx264 -c:a copy -movflags faststart -r 15 -s 480*320 -y $tmp
ffmpeg -ss 0 -i $original -y -f image2 -t 0.001 -s 238*140 $picpath
# 覆盖原文件
mv $tmp $target
#fi
}
echo "ffmpegmp4 over"
list_allpdf(){
for i in `ls -a $1`; do
if [ -d "$1/$i" -a x"$i" != x"." -a x"$i" != x".." ];then
list_allpdf "$1/$i"
elif [ -f "$1/$i" -a -s "$1/$i" ];then
echo "$1/$i"
if [ "${i##*.}" = "mp4" -o "${i##*.}" = "flv" -o "${i##*.}" = "MP4" -o "${i##*.}" = "FLV" ];then
echo "---------------------------111--------------------------------"
ffmpegmp4 $1/$i
fi
echo "*******************************"
fi
done
}
list_allpdf $1