13

When I use this, the quality doesn't look bad.

ffmpeg -same_quant -i video.mp4 video.avi

In the ffmpeg documentation is written: "Note that this is NOT SAME QUALITY. Do not use this option unless you know you need it."

Do I get with -same_quant the best quality or is there an option that gives the same quality as the input and is more recommended?

njsg
  • 13,345
  • 1
  • 27
  • 29
sid_com
  • 1,531
  • 3
  • 16
  • 20
  • Depending on the codecs used (some codecs are incompatible with some containers), you could always simply copy the streams (`-codec copy`). That is the best way to avoid quality changes, as you're not reencoding the streams, just repackaging those in a different container. – njsg Jun 08 '12 at 15:35
  • When I try this I get: `Unknown decoder 'copy'`. – sid_com Jun 08 '12 at 15:46
  • 4
    It seems `-codec copy` must go *after* `-i video.mp4` -- can you try `ffmpeg -i video.mp4 -codec copy video.avi`? (`-same_quant` works here too, but will do nothing, as this just copies the streams) – njsg Jun 08 '12 at 16:12
  • Regarding the placement of ffmpeg's command-line options, see [ffmpeg Documentation - 2 Description](http://ffmpeg.org/ffmpeg.html#Synopsis): Here is an excerpt: *As a general rule, options are applied to the* ***next*** *specified file. Therefore, order is important, ...* – Peter.O Jun 08 '12 at 16:43
  • Thx! Now with `-codec copy` on the right place is works. – sid_com Jun 08 '12 at 17:53
  • @njsg Can you add that as an answer? – Tim Jun 08 '12 at 18:30
  • @Tim, did it, with some more comments on the container vs. codec issue. – njsg Jun 08 '12 at 19:09
  • @njsg Thanks a bunch, and now I can vote on your answer ;) – Tim Jun 08 '12 at 19:57
  • `-same_quant` does not work for me, but `-sameq` does. See also http://askubuntu.com/questions/83161/use-ffmpeg-to-transform-mp4-to-same-high-quality-avi-file – Faheem Mitha Sep 29 '13 at 16:52

2 Answers2

16

(adapted from comments above)

Depending on the codecs used (some codecs are incompatible with some containers), you could always simply copy the streams (-codec copy). That is the best way to avoid quality changes, as you're not reencoding the streams, just repackaging those in a different container.

When dealing with audio/video files, it is important to keep in mind that containers are mostly independent from the used codecs. It is common to see people referring to files as "AVI video" or "MP4 video", but those are containers and tell us little about whether a player will be able to play the streams, as, apart from technical limitations (for example, AVI may have issues with h264 and Ogg Vorbis), you could use any codec.

-same_quant seems to be a way to tell ffmpeg to try to achieve a similar quality, but as soon as you reencode the video (at least with lossy codecs), you have no way to get the same quality. If you're concerned with quality, a good rule of thumb is to avoid reencoding the streams when possible.

So, in order to copy the streams with ffmpeg, you'd do:

ffmpeg -i video.mp4 -codec copy video.avi

(As @Peter.O mentioned, option order is important, so that's where -codec copy must go. You could still keep -same_quant, but it won't have any effect as you're not reencoding the streams.)

njsg
  • 13,345
  • 1
  • 27
  • 29
  • Your solution works for me. I see that `avconv` is now recommended in place of `ffmpeg` and in fact is what I used. – Faheem Mitha Sep 29 '13 at 11:44
4

Under FreeBSD 8. 2, I tried -codec copy but I got message unknown decoded as well. After trial and error I found the one that working is under FreeBSD:

ffmpeg -i video.mp4 -vcodec copy video.avi
slm
  • 363,520
  • 117
  • 767
  • 871
binyo66
  • 41
  • 1