1

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?

2
  • 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
    Commented Sep 2, 2014 at 11:13
  • @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
    Commented Sep 2, 2014 at 12:32

2 Answers 2

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.

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.
    – timonsku
    Commented Sep 3, 2014 at 13:37
  • @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
    Commented Sep 3, 2014 at 13:40
  • 1
    The important term is 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
    Commented Sep 3, 2014 at 13:50
1

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.

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.

Your Answer

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

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