7

Background:

I am trying to compress lossless bluray tracks to a more storage friendly size without a huge loss in quality.

What I've been doing thus far:

Exploring compression options with ffmpeg. Mainly around h264 with the -crf argument.

Restrictions:

Linux and open source tools. Please don't suggest anything Apple/Microsoft specific.

Question:

Most of the options I see around compression involved bit rates or fixed output sizes. I am looking for a video codec that has more of a "quality threshold". I don't mind if more complex portions of the track require more bytes to deliver the same level of visual quality. Does anything like this exist?

Edit:

I am having good luck with the -qscale argument and libxvid. If I don't get any other suggestions, I'll just go with that.

5
  • 1
    What's wrong with crf in x264?
    – Gyan
    Apr 10, 2012 at 15:43
  • Documentation states that crf sacrifices runtime speed for quality. Since I could potentially run these videos on lesser machines, I didn't want to place too much burden on them. Apr 12, 2012 at 14:45
  • 2
    You can't get both quality and computational efficiency. There's a tradeoff.
    – Gyan
    Apr 12, 2012 at 16:23
  • Have you looked at Lagarith or HuffYUV? I generally use these for storing footage. They are both lossless however the compression can actually be quite good, granted I'm not sure how they compare to h264. I'm also not sure about Linux support.
    – glenneroo
    Apr 19, 2012 at 15:54
  • Your bluray source is highly unlikely to be lossless. Easy way to check: ffplay -vf showinfo. If it has any B frames, it's not lossless h.264. Jan 15, 2015 at 11:50

2 Answers 2

6

You're on the right track with -crf and x264 (the best H.264 encoder), and it should provide the "quality threshold" that you're looking for. CRF is recommended if you want a certain output quality and output file size is of less importance. Conversely, performing a two-pass encode with -b:v is recommend if you are targeting a specific output file size and quality is of less importance.

Encoding HEVC/H.265 with x265 should follow the same basic guidelines. You'll generally get better compression in exchange for a longer encoding time.

1. Choose a preset

A preset is a collection of options that will provide a certain encoding speed:compression ratio. A slower preset will provide better compression (compression is quality per filesize). General usage is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. Ignore placebo as it is a joke and a waste of time (it helps at most ~1%). If it's encoding too slowly then use a faster preset.

2. Choose a CRF value

The range for x264 is 0-51 where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality. A subjectively sane range is 18-28. Consider ~18 to be visually lossless: it should look the same as the input but it isn't technically lossless. Increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate.

General usage is to choose the highest -crf value that still provides an acceptable quality. That is if the output looks good then try a higher value and if it looks bad then choose a lower value.

3. Encode

Use these settings for the rest of your videos. They should all end up with the same quality.

Example

ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv

Also see

4
  • 3
    -ssim 1 -psnr on your ffmpeg cmdline will measure some video quality metrics (which don't always match human-perceived visual quality). Can be useful to get an idea of how much your video is getting mangled. Jan 15, 2015 at 11:52
  • At the end of 2.: “General usage is to choose the highest quality” - probably should be lowest instead of highest.
    – MarianD
    Sep 19, 2019 at 12:18
  • @MarianD Fixed, thanks. Wow, that answer is 7 years old.
    – llogan
    Sep 19, 2019 at 17:15
  • Your answers were always superior and helpful (I remember your previous name, too), thanks for them.
    – MarianD
    Sep 19, 2019 at 18:07
-3

Maybe this is going to be helpfull K-Lite Codec Pack When you install there is pack of codecs so you can choose what best fits you. This is the list of codecs: • DirectShow video decoding filters: - ffdshow [version 1.2.4475] - LAV Video [version 0.51.3] (- Decoding of: H264, VC1 (progressive only), MPEG2, MPEG4-ASP, MS-MPEG4, MJPEG, VP8, RV40, WMV1/2/3) - On2 VP7 [version 7.0.10.0] - DScaler5 MPEG-2 decoder [version 0.0.6.0 IVTC mod]

3
  • 1
    I don't see how this answers the question.
    – llogan
    Jul 26, 2012 at 18:05
  • download K-Lite Codec Pack, find options in coder/decoder and that's it. There is the option of choosing quality and the size of commpresed video. The answer is here, but I shorten in particular reason. Good answering by you though Jul 26, 2012 at 19:44
  • 1
    Your answer would be more helpful if you suggested which of the codecs would suit the questioner's needs.
    – stib
    Jan 19, 2015 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.