Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

ffmpeg - how to apply filters without losing quality

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Lossy, but looks lossless

Alternatively you can use proper encoding settings that look "visually lossless", but technically are not truly lossless. Example for H.264:

ffmpeg -i input -codec:v libx264 -crf 18 -preset slow -vf format=yuv420p out.mp4
  • -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 and therefore compression efficiency: ultrafast, superfast, veryfast, faster, fast, medium (the default), slow, slower, veryslow.

  • -vf format=yuv420p uses a compatible chroma subsampling required by most players.

Using a lossless format

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

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

The output file size can be huge–generally much bigger than your input file.

Use CSS or your player to add the watermark

Avoid encoding completely and just deal with the watermark with CSS or with your HTML5 video player.

Also see


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...