ffmpeg-如何在不损失质量的情况下应用过滤器 [英] ffmpeg - how to apply filters without losing quality

查看:83
本文介绍了ffmpeg-如何在不损失质量的情况下应用过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的请求,它具有输入,输出和两个水印.从我收集到的信息来看,我无法应用-codec copy,因为我正在使用过滤器.

Here is a simple request, it has an input, output, and two watermarks. From what I gathered I can't apply -codec copy because I'm using a filter.

ffmpeg -i input.mp4 -i wm-bl.png -i wm-br.png -filter_complex "overlay=x=0:y=H-h,overlay=x=W-w:y=H-h" output.mp4

就加水印而言,这可以解决问题,但是输出被压缩为原始文件大小的一半.

This does the trick, as far as watermarking is concerned, but the output is compressed into half the original file size.

是否可以在不损失视频质量的情况下加水印?

Is it possible to watermark without losing video quality?

推荐答案

您必须重新编码才能执行任何过滤

因此,在过滤时进行流复制的任何尝试都将被忽略.这就是-codec copy对您无能为力的原因.

You must re-encode to perform any filtering

Therefore any attempt at stream copying while filtering will be ignored. This is why -codec copy does nothing for you.

尽管您必须重新编码以进行过滤,但这并不意味着您必须降低质量.您可以使用无损编码器:

Although you must re-encode for filtering it does not mean that you have to lose quality. You can use a lossless encoder:

  • -codec:v libx264 -crf 0 -preset veryslow
  • -codec:v huffyuv
  • -codec:v ffv1
  • -codec:v ffvhuff
  • -codec:v libx264 -crf 0 -preset veryslow
  • -codec:v huffyuv
  • -codec:v ffv1
  • -codec:v ffvhuff

输出文件的大小可能很大(无损).

The outputs file size can be huge (they are lossless).

如果发生色度二次采样,您可能会遭受一些损失.

You may experience some loss if chroma subsampling occurs.

或者,您可以使用看起来视觉上无损"的正确编码设置,但从技术上讲并不是真正的无损.创建可能看起来视觉上无损的H.264视频的示例(由于质量是主观的,因此取决于输入和观看者):

Alternatively you can use proper encoding settings that look "visually lossless", but technically are not truly lossless. Example for creating H.264 video that will likely look visually lossless (depends on input and the viewer since quality is subjective):

ffmpeg -i input -codec:v libx264 -crf 18 -preset slow -pix_fmt yuv420p out.mp4

概括地说,-crf控制质量:范围是0-51的对数刻度,0是无损的,〜18通常在视觉上被认为是无损的,默认值为23. -preset控制编码速度:超快,超快,非常快,更快,更快,中等(默认),慢,慢,非常慢.

To generalize, -crf controls quality: range is a log scale of 0-51, 0 is lossless, ~18 is often considered visually lossless, and 23 is default. -preset controls encoding speed: ultrafast, superfast, veryfast, faster, fast, medium (the default), slow, slower, veryslow.

-pix_fmt yuv420p将允许编码器使用色度子采样方案,该方案与像QuickTime这样的穴居人播放器兼容.根据您的输入,ffmpeg版本以及您将如何使用输出而定,可能不需要,也可能不需要,但是对于一般用途,使用libx264时包括它并不有害.

-pix_fmt yuv420p will allow the encoder to use a chroma sub-sampling scheme that is compatible with troglodyte players like QuickTime. It may or may not be required depending on your input, your ffmpeg version, and how you're going to use the output but for general use it does not hurt to include it when using libx264.

这篇关于ffmpeg-如何在不损失质量的情况下应用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆