Last active
June 24, 2021 05:42
-
-
Save zqhong/fe8f55bf85e18263306cd1379980c0a8 to your computer and use it in GitHub Desktop.
ffmpeg 批量对 find 匹配后的视频文件进行处理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
: ' | |
用法: | |
find-exec-ffmpeg path file_ext | |
例子: | |
find-exec-ffmpeg /home/ mp4:【转换 /home 目录下的 mp4 视频文件】 | |
说明: | |
脚本用于将某目录下符合条件的视频文件,转换为 H.264 视频编码,AAC 音频编码。期间,尝试使用 Videotoolbox(macOS) 视频加速。 | |
转换成功后的文件,文件结尾添加【_batch】。示例:源文件 1.mp4,转换后的文件则为 1_batch.mp4。 | |
脚本依赖 FFmpeg,使用前请下载安装:https://ffmpeg.org/download.html | |
(建议使用编译成功的二进制文件,手动编译较为耗时。) | |
注意: | |
为了避免重复处理,脚本默认忽略处理【_batch.ext(如:_batch.mp4)】的文件。 | |
' | |
ffmpeg_file() { | |
local loop_file | |
loop_file=$1 | |
local new_file | |
new_file="${loop_file/.$search_file_ext/$append_filename.$search_file_ext}" | |
echo "ffmpeg -in $loop_file -out $new_file..." | |
ffmpeg -y -nostdin -hide_banner -loglevel error -i "$loop_file" -allow_sw 1 -vcodec h264_videotoolbox -preset veryfast -acodec aac "$new_file" | |
} | |
search_path="." | |
search_file_ext="mp4" | |
append_filename="_batch" | |
if test -n "$1"; then | |
search_path=$1 | |
fi | |
if test -n "$2"; then | |
search_file_ext=$2 | |
fi | |
find "$search_path" ! -name "*$append_filename.$search_file_ext" -name "*.$search_file_ext" | while read -r file; do ffmpeg_file "$file"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, thank you for reminding me.
是的,谢谢你的提醒。