![Offline Offline](./styles/bmd_universal/imageset/en/icon_user_offline.png)
- Posts: 966
- Joined: Mon Dec 19, 2016 10:51 am
Ready your pitchforks, I’m going to be controversial:
Can H.264 be used as an intermediate or even master archival codec?
(TL:DR Yes.)
Uli and Marc have repeatedly stated that H.264 is not an intermediate codec and that generational loss gives cartoonishly bad results even after only 10 generations. (ref: viewtopic.php?f=21&t=192146&sid=52b4e1a802f383efb1d5217acff07391#p1006541 and viewtopic.php?f=21&t=192146&sid=52b4e1a802f383efb1d5217acff07391#p1006556 )
In order to make my case I need to explain two very important things: CRF and QP.
The long version of the explanation is at https://slhck.info/video/2017/02/24/crf-guide.html
It’s also helpful to understand how JPEG is compressed, as the quantization matrix compression is roughly identical between H.264 and JPEG: https://en.wikipedia.org/wiki/JPEG#JPEG_codec_example
The short version is that CRF sets how much a file is compressed as a visual factor
QP sets how much a file is compressed as a mathematical factor.
Statement: H.264 is awful
Statement: H.264 deteriorates after 10 generations:
Statement: H.264 looks like an overstylized art project.
Statement: H.264 looked like a video effect filter from the eighties.
Counter statement: H.264 is lossless, both visually and mathematically.
So, who is correct?
In order to answer that, we need to read the H.264 specification:
So, yes, H.264 can be lossless.
As proof of that, here is a video showing not 10 but 60 generations of CRF encoded video:
Yes, that is 2160p at 300%. At 3 seconds and 1 frame in, at 59.94 fps.
![](https://i.ytimg.com/vi/A1rMSKpItOo/hqdefault.jpg)
(source video is at https://drive.google.com/drive/folders/ ... sp=sharing along with two exports of the 2160p timeline at generation 0 and 60)
(for those playing along at home:
At https://media.xiph.org/video/av2/ download sparks_aom_5764-6024
ffmpeg -i libx264_gen0_CRF_0_faster.mov -c:v libx264 -crf 0 -preset faster libx264_gen1_CRF_0_faster.mov
Here is the short mediainfo of the generation 0 and generation 60 files:
Generation 0: Video: MPEG4 Video (H264) 4096x2160 59.94fps 1909057kbps [V: h264 high 10 L5.2, yuv420p10le, 4096x2160, 1909057 kb/s]
Generation 60: Video: MPEG4 Video (H264) 4096x2160 59.94fps 1804717kbps [V: h264 high 10 L5.2, yuv420p10le, 4096x2160, 1804717 kb/s]
Writing library : x264 core 164 r3172 c1c9931
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=4 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=24 / lookahead_threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=20 / rc=crf / mbtree=1 / crf=0.0 / qcomp=0.60 / qpmin=0 / qpmax=81 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00 )
After 60 generations the file lost 5% of the bitrate which is a lot when you consider that CRF 0 should be lossless.
To see how much the file changed, I’m going to do SSIM, PSNR, MSAD, CORR and VMAF comparisons between the Gen 0 and Gen 60 CRF 0 files:
SSIM: Y:0.993719 (22.019606) U:0.992436 (21.212376) V:0.991997 (20.967383) All:0.993218 (21.686425)
PSNR y:46.574179 u:48.013342 v:47.574161 average:46.942391 min:42.924770 max:54.994300
MSAD: Y:0.002768 U:0.002454 V:0.002614 average:0.002612 min:0.001163 max:0.004453
CORR: Y:0.999781 U:0.996666 V:0.996602 average:0.997683 min:0.995516 max:0.999591
VMAF:
0.6.1: 99.9775
0.6.1-4K: 99.9906
To sum those numbers up: 99.3%, 99.995%, 99.95% and 99.97 or 99.99% similar after 60 generations
Doing the same with QP 0:
Generation 0: Video: MPEG4 Video (H264) 4096x2160 59.94fps 3952660kbps [V: h264 high 4:4:4 predictive L6.0, yuv420p10le, 4096x2160, 3952660 kb/s]
Generation 25: Video: MPEG4 Video (H264) 4096x2160 59.94fps 3952660kbps [V: h264 high 4:4:4 predictive L6.0, yuv420p10le, 4096x2160, 3952660 kb/s]
Note that I didn’t do 60 generations here, only 25.
But at a loss of 0 byte I did not see the need to continue.
So that’s the longer version from a technical standpoint:
Yes, H.264 can be used as an intermediate and master archival codec IF used properly as designed.
The above is made with x264, which gained lossless encoding 15 years ago (ref https://code.videolan.org/videolan/x264 ... a2f884a859).
With Davinci Resolve:
Sadly Davinci does not support 10 bit H.264 exports, so lossless is impossible directly from the standard Deliver settings.
However with Voukoder it is possible to use x264, which makes all the above settings possible, but only in the Studio version.
Can H.264 be used as an intermediate or even master archival codec?
(TL:DR Yes.)
Uli and Marc have repeatedly stated that H.264 is not an intermediate codec and that generational loss gives cartoonishly bad results even after only 10 generations. (ref: viewtopic.php?f=21&t=192146&sid=52b4e1a802f383efb1d5217acff07391#p1006541 and viewtopic.php?f=21&t=192146&sid=52b4e1a802f383efb1d5217acff07391#p1006556 )
In order to make my case I need to explain two very important things: CRF and QP.
The long version of the explanation is at https://slhck.info/video/2017/02/24/crf-guide.html
It’s also helpful to understand how JPEG is compressed, as the quantization matrix compression is roughly identical between H.264 and JPEG: https://en.wikipedia.org/wiki/JPEG#JPEG_codec_example
The short version is that CRF sets how much a file is compressed as a visual factor
QP sets how much a file is compressed as a mathematical factor.
Statement: H.264 is awful
Statement: H.264 deteriorates after 10 generations:
Statement: H.264 looks like an overstylized art project.
Statement: H.264 looked like a video effect filter from the eighties.
Counter statement: H.264 is lossless, both visually and mathematically.
So, who is correct?
In order to answer that, we need to read the H.264 specification:
ITU-T Rec. H.264 (05/2003) wrote:“This Recommendation | International Standard was developed in response to the growing need for higher compression of moving pictures for various applications such as videoconferencing, digital storage media, television broadcasting, internet streaming, and communication. It is also designed to enable the use of the coded video representation in a flexible manner for a wide variety of network environments. The use of this Recommendation | International Standard allows motion video to be manipulated as a form of computer data and to be stored on various storage media, transmitted and received over existing and future networks and distributed on existing and future broadcasting channels.“
Rec. ITU-T H.264 (08/2021) wrote:“The coded representation specified in the syntax is designed to enable a high compression capability for a desired image quality. With the exception of the transform bypass mode of operation for lossless coding in the High 4:4:4 Intra, CAVLC 4:4:4 Intra, and High 4:4:4 Predictive profiles, and the I_PCM mode of operation in all profiles, the algorithm is typically not lossless, as the exact source sample values are typically not preserved through the encoding and decoding processes.”
So, yes, H.264 can be lossless.
As proof of that, here is a video showing not 10 but 60 generations of CRF encoded video:
Yes, that is 2160p at 300%. At 3 seconds and 1 frame in, at 59.94 fps.
![](https://i.ytimg.com/vi/A1rMSKpItOo/hqdefault.jpg)
(source video is at https://drive.google.com/drive/folders/ ... sp=sharing along with two exports of the 2160p timeline at generation 0 and 60)
(for those playing along at home:
At https://media.xiph.org/video/av2/ download sparks_aom_5764-6024
ffmpeg -i libx264_gen0_CRF_0_faster.mov -c:v libx264 -crf 0 -preset faster libx264_gen1_CRF_0_faster.mov
Here is the short mediainfo of the generation 0 and generation 60 files:
Generation 0: Video: MPEG4 Video (H264) 4096x2160 59.94fps 1909057kbps [V: h264 high 10 L5.2, yuv420p10le, 4096x2160, 1909057 kb/s]
Generation 60: Video: MPEG4 Video (H264) 4096x2160 59.94fps 1804717kbps [V: h264 high 10 L5.2, yuv420p10le, 4096x2160, 1804717 kb/s]
Writing library : x264 core 164 r3172 c1c9931
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=4 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=24 / lookahead_threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=20 / rc=crf / mbtree=1 / crf=0.0 / qcomp=0.60 / qpmin=0 / qpmax=81 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00 )
After 60 generations the file lost 5% of the bitrate which is a lot when you consider that CRF 0 should be lossless.
To see how much the file changed, I’m going to do SSIM, PSNR, MSAD, CORR and VMAF comparisons between the Gen 0 and Gen 60 CRF 0 files:
SSIM: Y:0.993719 (22.019606) U:0.992436 (21.212376) V:0.991997 (20.967383) All:0.993218 (21.686425)
PSNR y:46.574179 u:48.013342 v:47.574161 average:46.942391 min:42.924770 max:54.994300
MSAD: Y:0.002768 U:0.002454 V:0.002614 average:0.002612 min:0.001163 max:0.004453
CORR: Y:0.999781 U:0.996666 V:0.996602 average:0.997683 min:0.995516 max:0.999591
VMAF:
0.6.1: 99.9775
0.6.1-4K: 99.9906
To sum those numbers up: 99.3%, 99.995%, 99.95% and 99.97 or 99.99% similar after 60 generations
Doing the same with QP 0:
Generation 0: Video: MPEG4 Video (H264) 4096x2160 59.94fps 3952660kbps [V: h264 high 4:4:4 predictive L6.0, yuv420p10le, 4096x2160, 3952660 kb/s]
Generation 25: Video: MPEG4 Video (H264) 4096x2160 59.94fps 3952660kbps [V: h264 high 4:4:4 predictive L6.0, yuv420p10le, 4096x2160, 3952660 kb/s]
Note that I didn’t do 60 generations here, only 25.
But at a loss of 0 byte I did not see the need to continue.
So that’s the longer version from a technical standpoint:
Yes, H.264 can be used as an intermediate and master archival codec IF used properly as designed.
The above is made with x264, which gained lossless encoding 15 years ago (ref https://code.videolan.org/videolan/x264 ... a2f884a859).
With Davinci Resolve:
Sadly Davinci does not support 10 bit H.264 exports, so lossless is impossible directly from the standard Deliver settings.
However with Voukoder it is possible to use x264, which makes all the above settings possible, but only in the Studio version.
Davinci Resolve Studio 19B3 Build 33, Windows 11, Nvidia 3060 TI, 555.85 Studio