c - MP4 到 DASH 使用 ffmpeg linux 太慢了
问题描述
目前,我正在一个包含 2000 个视频 mp4 文件的项目中工作,我需要将它们全部转换为 mpeg dash 文件。
我有这个脚本:
MYDIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
SAVEDIR=$(pwd)
# Check programs
if [ -z "$(which ffmpeg)" ]; then
echo "Error: ffmpeg is not installed"
exit 1
fi
if [ -z "$(which MP4Box)" ]; then
echo "Error: MP4Box is not installed"
exit 1
fi
cd "$MYDIR"
TARGET_FILES=$(find ./ -maxdepth 1 -type f \( -name "*.mov" -or -name "*.mp4" \))
for f in $TARGET_FILES
do
fe=$(basename "$f") # fullname of the file
f="${fe%.*}" # name without extension
if [ ! -d "${f}" ]; then #if directory does not exist, convert
echo "Converting \"$f\" to multi-bitrate video in MPEG-DASH"
mkdir "${f}"
ffmpeg -y -i "${fe}" -c:a aac -b:a 192k -vn "${f}_audio.m4a"
ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 800k -bufsize 2000k -pix_fmt yuv420p -vf "scale=-2:720" -f mp4 "${f}_800.mp4"
# static file for ios and old browsers and mobile safari
ffmpeg -y -i "${fe}" -preset slow -tune film -movflags +faststart -vsync passthrough -write_tmcd 0 -c:a aac -b:a 160k -c:v libx264 -crf 23 -maxrate 1400 -bufsize 3000k -pix_fmt yuv420p -f mp4 "${f}/${f}.mp4"
rm -f ffmpeg*log*
# if audio stream does not exist, ignore it
if [ -e "${f}_audio.m4a" ]; then
MP4Box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a" -out "${f}/${f}.mpd"
rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a"
else
MP4Box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" -out "${f}/${f}.mpd"
rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4"
fi
# create a jpg for poster. Use imagemagick or just save the frame directly from ffmpeg is you don't have cjpeg installed.
ffmpeg -i "${fe}" -ss 00:00:00 -vframes 1 -qscale:v 10 -n -f image2 - | cjpeg -progressive -quality 75 -outfile "${f}"/"${f}".jpg
fi
done
cd "$SAVEDIR"
这工作正常,但是,只转换单个文件需要很长时间,我有 intel 7 和一个简单的 mp4 文件需要 30 分钟才能转换。我怎样才能加速这个过程?我必须更改此脚本中的某些内容吗?
谢谢你。
解决方案
推荐阅读
- r - 在 R 中使用“foreach”循环时,仅执行第一个任务
- mysql - 不满足条件的查询计数为 1
- python - google colab中for循环中的列表索引超出范围
- php - 完整性约束违规:1062 重复条目唯一值
- android - 如何创建 Web 浏览器的选项卡屏幕?
- php - 在 Laravel 8 中找不到类“App\Http\Controllers\Controller”
- javascript - 如何模仿PHP??Javascript中的双问号行为?
- javascript - React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE?
- hyperledger-fabric - 在 Hyperledger Fabric 中评估生产网络
- java - Google 移动广告 SDK 初始化不正确。AdMob 发布商应遵循此处的说明: