Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Decoding HDCD with ffmpeg gives errors (Read 2621 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Decoding HDCD with ffmpeg gives errors

I am currently decoding my HDCD's, which I already ripped to Flac. On one of the CD's each track gives two errors when decoding which I don't really understand, see the verbose logging below (for one track). What is causing this errors? The albums are ripped securely with EAC or CUERipper and verified against CTDB + AccurateRip.

I am using the 'stock' Ffmpeg from (X)ubuntu 21.10:
Code: [Select]
dpkg --list | grep ffmpeg
ii  ffmpeg                                7:4.4-6ubuntu5                      amd64        Tools for transcoding, streaming and playing of multimedia files
ii  gstreamer1.0-libav:amd64              1.18.5-1   

Decoding output:
Code: [Select]
.../hdcd/King Crimson - 1974 - Starless And Bible Black (30th Anniversary Edition)$ ffmpeg -i 01.\ King\ Crimson\ -\ The\ Great\ Deceiver.flac -af hdcd 01.\ King\ Crimson\ -\ The\ Great\ Deceiver.hdcd.flac -v verbose 
ffmpeg version 4.4-6ubuntu5 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-7ubuntu1)
  configuration: --prefix=/usr --extra-version=6ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, flac, from '01. King Crimson - The Great Deceiver.flac':
  Metadata:
    album           : Starless And Bible Black (30th Anniversary Edition)
    artist          : King Crimson
    title           : The Great Deceiver
    DATE            : 1974
    track           : 01
  Duration: 00:04:02.87, start: 0.000000, bitrate: 961 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> flac (native))
Press [q] to stop, [?] for help
[Parsed_hdcd_0 @ 0x55ad3d917240] Disabling automatic format conversion.
[graph_0_in_0_0 @ 0x55ad3d9177c0] tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3
[Parsed_hdcd_0 @ 0x55ad3d917240] Auto-convert: disabled
[Parsed_hdcd_0 @ 0x55ad3d917240] Looking for 16-bit HDCD in sample format s16
[Parsed_hdcd_0 @ 0x55ad3d917240] CDT period: 2000ms (88200 samples @44100Hz)
[Parsed_hdcd_0 @ 0x55ad3d917240] Process mode: process stereo channels together
[Parsed_hdcd_0 @ 0x55ad3d917240] Force PE: off
[Parsed_hdcd_0 @ 0x55ad3d917240] Analyze mode: [0] disabled
[flac @ 0x55ad3d8d3f80] encoding as 24 bits-per-sample
Output #0, flac, to '01. King Crimson - The Great Deceiver.hdcd.flac':
  Metadata:
    album           : Starless And Bible Black (30th Anniversary Edition)
    artist          : King Crimson
    title           : The Great Deceiver
    DATE            : 1974
    TRACKNUMBER     : 01
    encoder         : Lavf58.76.100
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s32 (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.134.100 flac
[Parsed_hdcd_0 @ 0x55ad3d917240] hdcd error: Control B check failed: 0x0093 (0x00 vs 0x6c) near 5783552
[Parsed_hdcd_0 @ 0x55ad3d917240] hdcd error: Control B check failed: 0x2436 (0x24 vs 0xc9) near 5783552
No more output streams to write to, finishing.1kbits/s speed= 153x   
size=   29424kB time=00:04:02.86 bitrate= 992.5kbits/s speed= 153x   
video:0kB audio:29416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.027989%
Input file #0 (01. King Crimson - The Great Deceiver.flac):
  Input stream #0:0 (audio): 2615 packets read (29166494 bytes); 2615 frames decoded (10710420 samples);
  Total: 2615 packets (29166494 bytes) demuxed
Output file #0 (01. King Crimson - The Great Deceiver.hdcd.flac):
  Output stream #0:0 (audio): 2325 frames encoded (10710420 samples); 2326 packets muxed (30122026 bytes);
  Total: 2326 packets (30122026 bytes) muxed
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: counter A: 0, B: 2451, C: 2452
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: pe: 0, tf: 0, almost_A: 0, checkfail_B: 1, unmatched_C: 0, cdt_expired: 0
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg 0.0: 2411
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -0.5: 9
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -1.0: 7
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -1.5: 6
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -2.0: 6
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -2.5: 2
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -3.0: 0
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 0: tg -3.5: 0
[Parsed_hdcd_0 @ 0x55ad3d917240] Channel 1: tg -4.0: 10
[Parsed_hdcd_0 @ 0x55ad3d917240] Packets: type: B, total: 4902
[Parsed_hdcd_0 @ 0x55ad3d917240] HDCD detected: yes, peak_extend: never enabled, max_gain_adj: -4.0 dB, transient_filter: not detected, detectable errors: 2 (try -v verbose)
[AVIOContext @ 0x55ad3d8d4cc0] Statistics: 2 seeks, 116 writeouts
[AVIOContext @ 0x55ad3d8d5380] Statistics: 29175367 bytes read, 0 seeks

Re: Decoding HDCD with ffmpeg gives errors

Reply #1
Can reproduce on a Windows build. On the same track, I get pretty much the same output. (117 writeouts though.)

Re: Decoding HDCD with ffmpeg gives errors

Reply #2
Aren't you supposed to decode HDCD on the entire disc before splitting it into tracks? I'm not too familiar with how ffmpeg's HDCD decoder works, but the error might be caused by track boundaries in the middle of HDCD packets.

Otherwise, it's mastering errors. (Or a bad rip, but you already confirmed that's not the issue this time.)

Re: Decoding HDCD with ffmpeg gives errors

Reply #3
You get similar on the entire CD. 12 detectable errors then.  From the output:

Code: [Select]
[Parsed_hdcd_0 @ 00000000004ee8c0] Disabling automatic format conversion.
[graph_0_in_0_0 @ 00000000004eee80] tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3
[Parsed_hdcd_0 @ 00000000004ee8c0] Auto-convert: disabled
[Parsed_hdcd_0 @ 00000000004ee8c0] Looking for 16-bit HDCD in sample format s16
[Parsed_hdcd_0 @ 00000000004ee8c0] CDT period: 2000ms (88200 samples @44100Hz)
[Parsed_hdcd_0 @ 00000000004ee8c0] Process mode: process stereo channels together
[Parsed_hdcd_0 @ 00000000004ee8c0] Force PE: off
[Parsed_hdcd_0 @ 00000000004ee8c0] Analyze mode: [0] disabled
[flac @ 00000000004eab80] encoding as 24 bits-per-sample
Output #0, flac, to 'kchdcd.flac':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s32 (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.134.100 flac
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x0093 (0x00 vs 0x6c) near 5787648
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x2436 (0x24 vs 0xc9) near 5787648
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x00ed (0x00 vs 0x12) near 32063488
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x00f9 (0x00 vs 0x06) near 32063488
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x00fe (0x00 vs 0x01) near 129126400
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x00fd (0x00 vs 0x02) near 129126400
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x02e4 (0x02 vs 0x1b) near 172072960
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x5163 (0x51 vs 0x9c) near 172072960
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x6326 (0x63 vs 0xd9) near 180914176
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x771a (0x77 vs 0xe5) near 180914176
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x9a46 (0x9a vs 0xb9) near 194174976
[Parsed_hdcd_0 @ 00000000004ee8c0] hdcd error: Control B check failed: 0x00fe (0x00 vs 0x01) near 221644800
No more output streams to write to, finishing.4kbits/s speed= 211x
size=  280845kB time=00:46:40.36 bitrate= 821.6kbits/s speed= 211x
video:0kB audio:280837kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.002882%
Input file #0 (.\King Crimson - Starless and Bible Black.wav):
  Input stream #0:0 (audio): 120602 packets read (493983504 bytes); 120602 frames decoded (123495876 samples);
  Total: 120602 packets (493983504 bytes) demuxed
Output file #0 (kchdcd.flac):
  Output stream #0:0 (audio): 26801 frames encoded (123495876 samples); 26802 packets muxed (287576910 bytes);
  Total: 26802 packets (287576910 bytes) muxed
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: counter A: 0, B: 28467, C: 28473
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: pe: 0, tf: 0, almost_A: 0, checkfail_B: 6, unmatched_C: 0, cdt_expired: 0
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg 0.0: 25779
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -0.5: 642
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -1.0: 445
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -1.5: 334
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -2.0: 145
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -2.5: 149
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -3.0: 206
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -3.5: 149
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 0: tg -4.0: 618
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: counter A: 0, B: 28467, C: 28473
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: pe: 0, tf: 0, almost_A: 0, checkfail_B: 6, unmatched_C: 0, cdt_expired: 0
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg 0.0: 25779
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -0.5: 642
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -1.0: 445
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -1.5: 334
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -2.0: 145
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -2.5: 149
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -3.0: 206
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -3.5: 149
[Parsed_hdcd_0 @ 00000000004ee8c0] Channel 1: tg -4.0: 618
[Parsed_hdcd_0 @ 00000000004ee8c0] Packets: type: B, total: 56934
[Parsed_hdcd_0 @ 00000000004ee8c0] HDCD detected: yes, peak_extend: never enabled, max_gain_adj: -4.0 dB, transient_filter: not detected, detectable errors: 12 (try -v verbose)
[AVIOContext @ 00000000004eb580] Statistics: 2 seeks, 1099 writeouts
[AVIOContext @ 00000000004cd400] Statistics: 494049084 bytes read, 1 seeks

Re: Decoding HDCD with ffmpeg gives errors

Reply #4
Sounds like mastering error, then.

Re: Decoding HDCD with ffmpeg gives errors

Reply #5
HDCD is a tricky thing.  I have a few HDCDs, and some tracks aren't appropriately encoded, like bonus tracks, for example.
EZ CD Audio Converter / FLAC or WavPack

Re: Decoding HDCD with ffmpeg gives errors

Reply #6
Aren't you supposed to decode HDCD on the entire disc before splitting it into tracks? I'm not too familiar with how ffmpeg's HDCD decoder works, but the error might be caused by track boundaries in the middle of HDCD packets.

In my CD-collection I have found 5 HDCD encoded discs which are worth decoding because they make use of one or more of the HDCD-features. I have decoded all of them track-by-track without errors, except for the one posted here. It indeed must be a mastering error then. I am curious whether it is possible to hear these errors somehow.

Approx 30 CD's in my total collection (~750 CD's) were recognized as HDCD btw, but most of them doesn´t make use of HDCD-features. Which supports the impression that most 'HDCD'-discs that were sold in the past in fact weren't using any features at all. Still, if you decide to decode them anyway, they will become quieter. Is this expected behavior of the decoding process even when no HDCD-features are used?

Re: Decoding HDCD with ffmpeg gives errors

Reply #7
I have some of the KC 30th anniversary reissues. The following are done on full .wav images:

* In the Court ...: ffmpeg finds no HDCD.

* Lizard and Three oaPP: Have HDCD features enabled,  but "detectable errors: 0"

Then with errors:

* SaBB as above and Islands also has "detectable errors: 11", that is pretty much the same; but In the Wake ... has fewer of them, only two "detectable errors". A few lines from the output:
Code: [Select]
[Parsed_hdcd_0 @ 000000000049e980] hdcd error: Control B check failed: 0x08ea (0x08 vs 0x15) near 5025792
[Parsed_hdcd_0 @ 000000000049e980] hdcd error: Control B check failed: 0x1d59 (0x1d vs 0xa6) near 5025792

[Parsed_hdcd_0 @ 000000000049e980] Channel 0: counter A: 0, B: 24590, C: 24591
[Parsed_hdcd_0 @ 000000000049e980] Channel 0: pe: 24590, tf: 0, almost_A: 0, checkfail_B: 1, unmatched_C: 0, cdt_expired
: 0
[Parsed_hdcd_0 @ 000000000049e980] Channel 0: tg 0.0: 24590
[Parsed_hdcd_0 @ 000000000049e980] Channel 1: counter A: 0, B: 24590, C: 24591
[Parsed_hdcd_0 @ 000000000049e980] Channel 1: pe: 24590, tf: 0, almost_A: 0, checkfail_B: 1, unmatched_C: 0, cdt_expired
: 0
[Parsed_hdcd_0 @ 000000000049e980] Channel 1: tg 0.0: 24590
[Parsed_hdcd_0 @ 000000000049e980] Packets: type: B, total: 49180
[Parsed_hdcd_0 @ 000000000049e980] HDCD detected: yes, peak_extend: enabled permanently, max_gain_adj: 0.0 dB, transient_filter: not detected, detectable errors: 2 (try -v verbose)
[AVIOContext @ 000000000049b580] Statistics: 2 seeks, 950 writeouts
[AVIOContext @ 000000000047d400] Statistics: 434644620 bytes read, 1 seeks




Which supports the impression that most 'HDCD'-discs that were sold in the past in fact weren't using any features at all.
The HDCD flags are "in the dither", and if I remember correctly: If a certain Pacific device was used in the conversion to 16 bits, it would insert HDCD flags with whatever HDCD features were used (including, often: "none").

Still, if you decide to decode them anyway, the will become quieter. Is this expected behavior of the decoding process even when no HDCD-features are used?
Up to opinion; if the goal is to emulate a HDCD-aware DAC, those would AFAIK reduce volume by 6 dB once it receives a HDCD packet - because then the volume would be right if and when a full peak extension would arrive. Unlike a file converter, a DAC cannot scan the full file first to know for sure that there will never be a peak extension.

Re: Decoding HDCD with ffmpeg gives errors

Reply #8
Up to opinion; if the goal is to emulate a HDCD-aware DAC, those would AFAIK reduce volume by 6 dB once it receives a HDCD packet - because then the volume would be right if and when a full peak extension would arrive. Unlike a file converter, a DAC cannot scan the full file first to know for sure that there will never be a peak extension.

Ah, I understand. I chose a pragmatic approach: my goal is therefore not to emulate as close as possible, so I decided only to decode HDCD's with enabled features. In addition my HifiBerry streaming device has a slightly different (lower) output volume than my CD-player, which makes the goal to always emulate HDCD-DAC behavior already a bit artificial for my setup.

I also realized that your explanation makes an interesting case for the three CD's I found in my collection on which only a few individual tracks are detected as HDCD. When I have some time left I will try to elaborate on that a bit further.

Re: Decoding HDCD with ffmpeg gives errors

Reply #9
HDCD messed up compilations. A HDCD-aware DAC will switch off after ten seconds. Which could easily mean, ten seconds into the next track.
And even worse if track boundaries aren't exact (which they are not, when write/pressing offsets are such a fishy topic ... and that is even before read offset); at worst, if you play track 2 that is non-HDCD and then something else in your playlist, then the very end of track2.flac could have a HDCD flag that actually was to be part of track 3 (not "intended to" for the purpose of the compilation ...) triggering the DAC.

Re: Decoding HDCD with ffmpeg gives errors

Reply #10
HDCD messed up compilations. A HDCD-aware DAC will switch off after ten seconds. Which could easily mean, ten seconds into the next track.
And even worse if track boundaries aren't exact (which they are not, when write/pressing offsets are such a fishy topic ... and that is even before read offset); at worst, if you play track 2 that is non-HDCD and then something else in your playlist, then the very end of track2.flac could have a HDCD flag that actually was to be part of track 3 (not "intended to" for the purpose of the compilation ...) triggering the DAC.

That sounds like an interesting can of worms...