我的文件夹中有包含电影文件的文件夹,其中一些是 .mp4、.avi 或 .mov/.MOV。我需要将它们重新压缩为 H264 高质量(比如说,10MBPS)并在完成后删除原件。我有以下代码,但这是用于音频的,我不知道从哪里开始。我正在使用 Mac 终端。 for i in *.ogg; do ffmpeg -i "$i" -b:a 320000 "${i%.*}.mp3"; done
最佳答案
这是一个关于如何将 mp4 文件转换为 10M h264 文件的小示例,可以轻松修改并再次针对其他文件类型运行,并且可以轻松修改以在转换后删除文件:
convert_file() {
# loop through all mp4 files in current directory
for i in $1*.mp4;
# convert to .h264
do ffmpeg -i "$i" -b:v 10M -b:a 192k -an -vcodec libx264 -crf 23 "${i%.*}.h264" -y
done
# recursive call
# call convert_file function for each sub directory
for d in $1*/; do
if [ -d "$d" ]
then
convert_file $d;
fi
done
}
# call with path/to/myvideos
convert_file ~/Videos/
关于FFMPEG 扫描和转换电影文件并删除原始文件 - 隐居,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67747408/