<p>You have a misunderstanding of how compression works.  In all but a few specialized types of lossy compression, when you compress something a second time, even in a much higher quality level than previous encodings, you still lose additional quality.  </p>

<p>Using a slower encoding from the same original source with constant quality will often produce a smaller file of similar quality, but if you encode the already compressed version over again, you will still always end up with a lower quality video due to second generation quality losses from compressing twice.</p>

CC BY-SA 3.0
2014-09-03T13:37:15.157Z
I'm curious what are these specialized codecs you mention? I've never seen a lossy codec that would not ditch more information when re-compressing with the same encoding.
timonsku
CC BY-SA 3.0
2014-09-03T13:40:54.500Z
@ProfessorSparkles - I forget which, I'm not even sure they are used for video and it is a limited number of things you can do without having further loss of quality.  I'll try doing some digging to find them again.  I know they aren't super commonly used because the compression isn't as good, but I do know they exist.
AJ Henderson
CC BY-SA 3.0
2014-09-03T13:50:23.980Z
The important term is [idempotence](http://en.wikipedia.org/wiki/Idempotence).  Apparently some JPEG and JPEG-2000 implementations actually pull this off for certain re-compressions.  No algorithm does it 100% of the time that I know of, but some are able to do it some of the time.
AJ Henderson
CC BY-SA 3.0
2014-09-02T13:38:35.500Z
2014-09-02T13:38:35.500Z
AJ Henderson
<p>Just to add a bit to AJ Henderson correct answer.
You do can compress in a lossless way with h264, this is the lossless predictive profile and is achieved by encoding with a CRF setting of 0.</p>

<p>Though while you get lossless h264 compression that way you will endup with a larger file than your source file.
Lossy compression cant be done twice without loosing more information with each iteration, it already says that that in itself, its "lossy" it looses information every time you encode with it, hence only a lossless encoding will preserve all information and that is the CRF 0 setting (which produces huge files).</p>

<p>What your read as constant quality just means you will have a constant bit-rate and x264 wont alter the bitrate in order to preserve more information in certain frames or use less space where it doesn't need as much space to save the given information in the frame.</p>

<p>That being said, if the encodes you have are of a high quality and there aren't any visible artifacts present, you might be fine with re-compressing it, if disk space is of the most importance here. Though you loose information that might be useful for possibly enhancing aspects of the video in the far future that aren't relevant right now.</p>

CC BY-SA 3.0
2014-09-03T13:50:49.277Z
2014-09-03T13:50:49.277Z
timonsku
<p>According to the documentation for libx264 (h264) encoding, we can use a preset of veryfast, faster, fast, medium, slow, etc.
<a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="nofollow">https://trac.ffmpeg.org/wiki/Encode/H.264</a></p>

<blockquote>
  <p>...for constant quality encoding, you will simply save bitrate by
  choosing a slower preset.</p>
</blockquote>

<p>So while using constant quality, a slower preset doesn't have any affect on video quality, but it can compress the file size smaller.</p>

<p>This theoretically means it should be possible to take a video compressed with preset "veryfast", and recompress it with "slow"- resulting in a smaller file with no loss of video quality.</p>

<p>Has anyone ever done this or know how it can be done?</p>

CC BY-SA 3.0
2014-09-02T11:13:51.607Z
I'm not clear why you would compress and recompress -- if 'slow' gives you the size and quality you want, why do it in two steps? What do you think you gain from the original 'veryfast' step?
Jim Mack
CC BY-SA 3.0
2014-09-02T12:32:13.673Z
@JimMack Why do you assume that we are compressing new or original videos? We have have hundreds of older videos that were created with less optimal compression and it would be good to reduce their size now.
Sepero
<ffmpeg><encoding><libx264>
ffmpeg re-encode libx264 without quailty loss?
Sepero
# ffmpeg re-encode libx264 without quailty loss?

(Asked by: username_0 on 2014-09-02)

According to the documentation for libx264 (h264) encoding, we can use a preset of veryfast, faster, fast, medium, slow, etc.
<https://trac.ffmpeg.org/wiki/Encode/H.264>

> ...for constant quality encoding, you will simply save bitrate by
> choosing a slower preset.

So while using constant quality, a slower preset doesn't have any affect on video quality, but it can compress the file size smaller.

This theoretically means it should be possible to take a video compressed with preset "veryfast", and recompress it with "slow"- resulting in a smaller file with no loss of video quality.

Has anyone ever done this or know how it can be done?

**Tags:** ffmpeg, encoding, libx264

> **Comments:**
> **username_1**: I'm not clear why you would compress and recompress -- if 'slow' gives you the size and quality you want, why do it in two steps? What do you think you gain from the original 'veryfast' step?  
> **username_0**: @JimMack Why do you assume that we are compressing new or original videos? We have have hundreds of older videos that were created with less optimal compression and it would be good to reduce their size now.  

---

## 2 answers

### Answer by username_2 on 2014-09-02. Score: 1

You have a misunderstanding of how compression works. In all but a few specialized types of lossy compression, when you compress something a second time, even in a much higher quality level than previous encodings, you still lose additional quality.

Using a slower encoding from the same original source with constant quality will often produce a smaller file of similar quality, but if you encode the already compressed version over again, you will still always end up with a lower quality video due to second generation quality losses from compressing twice.

> **Comments:**
> **username_3**: I'm curious what are these specialized codecs you mention? I've never seen a lossy codec that would not ditch more information when re-compressing with the same encoding.  
> **username_2**: @ProfessorSparkles - I forget which, I'm not even sure they are used for video and it is a limited number of things you can do without having further loss of quality.  I'll try doing some digging to find them again.  I know they aren't super commonly used because the compression isn't as good, but I do know they exist.  
> **username_2**: The important term is [idempotence](http://en.wikipedia.org/wiki/Idempotence).  Apparently some JPEG and JPEG-2000 implementations actually pull this off for certain re-compressions.  No algorithm does it 100% of the time that I know of, but some are able to do it some of the time.  

---

### Answer by username_3 on 2014-09-03. Score: 1

Just to add a bit to username_2 correct answer.
You do can compress in a lossless way with h264, this is the lossless predictive profile and is achieved by encoding with a CRF setting of 0.

Though while you get lossless h264 compression that way you will endup with a larger file than your source file.
Lossy compression cant be done twice without loosing more information with each iteration, it already says that that in itself, its "lossy" it looses information every time you encode with it, hence only a lossless encoding will preserve all information and that is the CRF 0 setting (which produces huge files).

What your read as constant quality just means you will have a constant bit-rate and x264 wont alter the bitrate in order to preserve more information in certain frames or use less space where it doesn't need as much space to save the given information in the frame.

That being said, if the encodes you have are of a high quality and there aren't any visible artifacts present, you might be fine with re-compressing it, if disk space is of the most importance here. Though you loose information that might be useful for possibly enhancing aspects of the video in the far future that aren't relevant right now.


---

