<p>You're on the right track with <code>-crf</code> 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 <code>-b:v</code> is recommend if you are targeting a specific output file size and quality is of less importance.</p>

<p>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.</p>

<h1>1. Choose a preset</h1>

<p>A preset is a collection of options that will provide a certain <em>encoding speed:compression ratio</em>. 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: <code>ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo</code>. Ignore <code>placebo</code> 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.</p>

<h1>2. Choose a CRF value</h1>

<p>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.</p>

<p>General usage is to choose the highest <code>-crf</code> 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.</p>

<h1>3. Encode</h1>

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

<h2>Example</h2>

<pre><code>ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
</code></pre>

<h2>Also see</h2>

<ul>
<li><a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="nofollow noreferrer">FFmpeg Wiki: H.264</a></li>
<li><a href="https://trac.ffmpeg.org/wiki/Encode/H.265" rel="nofollow noreferrer">FFmpeg Wiki: H.265</a></li>
</ul>

CC BY-SA 3.0
2015-01-15T11:52:11.073Z
`-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.
Peter Cordes
CC BY-SA 4.0
2019-09-19T12:18:53.000Z
At the end of 2.: “General usage is to choose the highest quality” - probably should be **lowest** instead of **highest**.
MarianD
CC BY-SA 4.0
2019-09-19T17:15:16.467Z
@MarianD Fixed, thanks. Wow, that answer is 7 years old.
llogan
CC BY-SA 4.0
2019-09-19T18:07:22.887Z
Your answers were always superior and helpful (I remember your previous name, too), thanks for them.
MarianD
CC BY-SA 4.0
2012-07-26T18:30:16.033Z
2019-09-19T17:13:49.983Z
2019-09-19T17:13:49.983Z
llogan
<p>Maybe this is going to be helpfull <a href="http://rbytes.net/linux/k-lite-codec-pack-review/" rel="nofollow">K-Lite Codec Pack</a>
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]</p>

CC BY-SA 3.0
2012-07-26T18:05:41.867Z
I don't see how this answers the question.
llogan
CC BY-SA 3.0
2012-07-26T19:44:21.407Z
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
Mors Violenta
CC BY-SA 3.0
2015-01-19T13:03:27.993Z
Your answer would be more helpful if you suggested which of the codecs would suit the questioner's needs.
stib
CC BY-SA 3.0
2012-07-26T17:21:05.970Z
2012-07-26T17:21:05.970Z
Mors Violenta
<p><strong>Background:</strong></p>

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

<p><strong>What I've been doing thus far:</strong></p>

<p>Exploring compression options with ffmpeg. Mainly around h264 with the -crf argument. </p>

<p><strong>Restrictions:</strong></p>

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

<p><strong>Question:</strong></p>

<p>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?</p>

<p><strong>Edit:</strong></p>

<p>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.</p>

CC BY-SA 3.0
2012-04-10T15:43:10.523Z
What's wrong with crf in x264?
Gyan
CC BY-SA 3.0
2012-04-12T14:45:40.230Z
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.
Bryan Austin
CC BY-SA 3.0
2012-04-12T16:23:46.333Z
You can't get both quality and computational efficiency. There's a tradeoff.
Gyan
CC BY-SA 3.0
2012-04-19T15:54:45.967Z
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
CC BY-SA 3.0
2015-01-15T11:50:22.963Z
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.
Peter Cordes
<video><codec><linux><video-quality>
What video codecs can provide "adaptive quality"?
Bryan Austin
# What video codecs can provide "adaptive quality"?

(Asked by: username_0 on 2012-04-09)

**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.

**Tags:** video, codec, linux, video-quality

> **Comments:**
> **username_1**: What's wrong with crf in x264?  
> **username_0**: 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.  
> **username_1**: You can't get both quality and computational efficiency. There's a tradeoff.  
> **username_2**: 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.  
> **username_3**: 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.  

---

## 2 answers

### Answer by username_4 on 2012-07-26. Score: 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

FFmpeg Wiki: H.264
FFmpeg Wiki: H.265

> **Comments:**
> **username_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.  
> **username_5**: At the end of 2.: “General usage is to choose the highest quality” - probably should be **lowest** instead of **highest**.  
> **username_4**: @username_5 Fixed, thanks. Wow, that answer is 7 years old.  
> **username_5**: Your answers were always superior and helpful (I remember your previous name, too), thanks for them.  

---

### Answer by username_6 on 2012-07-26. Score: -3

Maybe this is going to be helpfull [K-Lite Codec Pack](http://rbytes.net/linux/k-lite-codec-pack-review/)
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]

> **Comments:**
> **username_4**: I don't see how this answers the question.  
> **username_6**: 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  
> **username_7**: Your answer would be more helpful if you suggested which of the codecs would suit the questioner's needs.  

---

