最近有一个 H5 页面的需求,里面有非常多的视频,由于视频在 H5 中播放缓冲较慢,因此需要在每一个视频前面加上一个封面,从而来避免白屏的情况。
主要使用的 ffmpeg 的语法:
ffmpeg -i input.mp4 -ss 00:00:00 -frames:v 1 out.jpg;
说明:
-i input.mp4 截取的视频的名字
-ss 00:00:00 这是视频的第一帧
-frames:v 1 这代表单独这1帧
out.jpg 要保存的截取的封面文件
批量转化脚本,存储为 run.sh ,在视频目录运行 run.sh
#!bin/sh
for file in `(find . -name "*.mp4")`;
do
if test -f $file
then
echo $file 是文件
if [ "${file##*.}"x = "mp4"x ];then
filename=$(basename $file);
echo $filename;
ffmpeg -i $file -ss 00:00:00 -frames:v 1 "${filename%%.*}-cover".jpg;
fi
fi
if test -d $file
then
echo $file 是目录
fi
done