14

I'm looking for the best in quality when converting videos.

I only want to use lossless audio and video encoders and a good container.

How do I enable lossless x264 vcodec for ffmpeg?

I currently use ffmpeg -i "inputvideo" -s 1280x720 -ar 48000 -threads 4 -vcodec libx264 -acodec copy -dsur_mode 2 -ac 6 "outputvideo720p.mkv"

I plan on using flac for the acodec by am unsure because I don't want to use quality if it switches to 16-bit instead of 24-bit

Zombo
  • 1
  • 62
  • 391
  • 407
Marc Brown
  • 601
  • 2
  • 11
  • 26
  • You can not copy audio and attempt to change audio rate and number of channels. These options (`-acodec copy` vs `-ar` and `-ac`) are mutually exclusive. Why do you want to convert to lossless? What are you planning to do with these lossless files (archiving, editing, temporary intermediates, etc)? – llogan Jul 30 '12 at 19:20
  • @LordNeckbeard The originals have to be converted to .mkv. Because I need to convert them, I want to maintain the highest quality possible using lossless for both the audio and the video. The video side is fine except for the fact that I might not be using lossless x264. The reason I still use `-acodec copy` is because I believe .mkv doesn't support .flac audio and I use `-ar & -ac` just to remind myself in the future to use them when I find a lossless acodec. I just need to enable lossless vcodec and find a lossless acodec aside from flac in AAC. – Marc Brown Jul 30 '12 at 23:00
  • MKV is a versatile container format and can handle FLAC and most likely your input format as well. Why not simply use `ffmpeg -i input -c copy output.mkv`? – llogan Jul 30 '12 at 23:31
  • @MarcBrown Just to clarify, when you use something like `-s 1280x720` to change the video's size, how do you imagine that being handled losslessly? – blahdiblah Jul 30 '12 at 23:48
  • @blahdiblah Well, the whole idea is to maintain the highest quality possible. 1280x720 is just one resolution some of the videos are rendered in so I expect losses there; then I would worry about the bitrate. But, if the source starts as 1080p.m2t or something else and has to be converted to "output1080p.mkv", I want to use lossless even still for that occasion. – Marc Brown Jul 31 '12 at 04:02
  • @LordNeckbeard The reason I don't simply copy is because the source media could vary as to what codecs they are using. Some could use wma, raw pcm, or aac. Because they will be on a website, consistency is needed. That's why all vcodecs are x264, acodecs as flac, and the container as .mkv. I just tried `-acodec flac` with ffmpeg and the conversion went through and I could play it in VLC. I would find a preset for lossless vcodec, but would rather see what "parameters" are used by ffmpeg for command line usage. – Marc Brown Jul 31 '12 at 04:06

1 Answers1

15

You can use x264 in lossless manner I think. As in here and here use these flags for ffmpeg:

ffmpeg -i input.avi -c:v libx264 -qp 0 output.mkv

In case you couldn't load libx264, remove ffmpeg and install from source with x264 enabled. Here is how to.

Hamed Tabatabaei
  • 695
  • 1
  • 7
  • 16
  • I'm currently using ffmpeg's FFV1 loss-less codec. Even though it has a 40mbit bit-rate, it's the closest I can get to true loss-less conversions without presets. – Marc Brown May 04 '13 at 15:30
  • 1
    Best answer is here: http://stackoverflow.com/questions/6701805/h264-lossless-coding/12303936#18506577 – MoDJ Nov 12 '14 at 01:18
  • 1
    I see what he adds is pixel_format:444. Although it will be theoretically more lossless to have it, but in 99.9% of cases the input itself is already chroma-subsampled to 4:2:0. So practically no advantage in that. All a person needs is "-qp 0". – Hamed Tabatabaei Nov 12 '14 at 04:10
  • 1
    Hamed, that is not tur for 10 bit, because only high444 supports lossless, high 10 is not lossless. – Валерий Заподовников Mar 25 '22 at 04:18