在尝试优化家庭视频的大小时,我在Xubuntu上使用Pitivi将其中的一些视频转换为WebM作为测试。大小差异很大。生成的webm文件仅占原始文件的10%左右,而图片质量对我来说几乎一样。
我还尝试使用进行转换,avconv
以便可以编写脚本,但是生成的文件看起来确实很烂。在查看了Pitivi中的渲染设置之后,我尝试了一些参数:avconv -i $1 -q 5 -qmin 0 -qmax 63 ${1%.*}.webm
,但是质量看起来仍然很糟糕,因此似乎缺少了/使用了一些错误的参数。有人知道哪些正确的参数可用于将h264电影转换为webm并获得与Pitivi相同的质量吗?
这些是Pitivi中的设置:
Note: This information is based on the FFmpeg Wiki on VP9 encoding. Please refer to that article for more information – it will be continuously maintained and extended. For the best results you should use the a recent version of
ffmpeg
by downloading it from their website (a static build will suffice; it contains thelibvps-vp9
encoder).
VBR encoding gives you the optimal overall quality, since the encoder can freely choose how many bits to assign to a frame. Choose this mode unless you are preparing videos for constant-bitrate streaming.
Typically, if you do not want to target a specific file size, you should let the bitrate vary freely, as that will lead to the highest quality. You can do this by setting the bitrate to 0 and the constant rate factor (CRF) to the target quality level:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm
CRF value can be from 0–63. Lower values mean better quality. Recommended values range from 15–35, with 31 being recommended for 1080p HD video. Google has a guide with more info on that.
If you want your file to have a specific target bitrate or file size, you need to specify the rate and use two-pass encoding (which will ensure an optimal quality distribution). Here we're choosing 5 MBit/s, which should be enough for 1080p content.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 5M -pass 1 -f webm /dev/null && \
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 5M -pass 2 output.webm
Windows users need to use NUL
instead of /dev/null
, and a ^
instead of \
.
First of all, libvpx offers constant bitrate and variable bitrate encoding modes. Constant bitrate should be avoided whenever possible (unless you target a specific file size or streaming scenario), since the average quality per file size will be worse. Still, you could try setting a constant bitrate if nothing else works for you, e.g. with 1 MBit/s:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -minrate 5M -maxrate 5M -b:v 5M output.webm
Look at the output and increase or decrease the bit rate to your liking (or file size constraints). For example, you can use 500K
or 5M
, et cetera.
你必须指定-minrate
,-maxrate
以及比特率-b:v
,以使编码器使用CBR。它们都必须具有相同的值-否则,它将选择不同的目标比特率,并进行VBR编码,但质量较差。
VP9编码当前选择的音频编解码器是Opus。FFmpeg将默认选择必要的编码器及其选项。如果要显式设置-c:a libopus
,也可以这样做。有关更多选项,请参考libopus
文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句