The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn’t technically lossless.
-crf 是 FFmpeg 中用来控制视频压缩质量的选项。它表示 Constant Rate Factor(恒定码率因子),使用了一种变量码率的编码方法。值越小,输出的视频文件的质量越高,但文件大小也越大。常用的 -crf 值范围是 0-51,其中 0 表示无损编码,51 表示最差的编码质量。一般来说,-crf 17 或 -crf 18 被认为是“视觉上无损”的,因为它们能够提供高质量的输出,同时文件大小比无损编码要小得多。
如果设置为1(或0),在我自己的测试下,转换后的文件会为原文件的三倍以上,所以建议使用 17/18。
单文件:
ffmpeg -i video.webm -crf 17 -c:v libx264 video.mp4
批量:
for f in *.webm; do ffmpeg -i $f -crf 17 -c:v libx264 ${f%.webm}.mp4; done
解释下${f%.webm}
:从f
所包含的字符串结尾开始删除.webm
,从而获得文件名。
如果批量转换的文件太多,可以归类下原文件以便查看
mkdir Orginal; mv *.webm Orginal
参考链接:
FFMPEG: webm to mp4 quality loss
FFmpeg 官方文档 - H.264 编码