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: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.) (Read 5751 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

... and a ffmpeg-to-wavpack oddity - all for sudden it encodes 24 bits as 24 as it should, rather than as 32.

I played around with a Blu-Ray image - only one. Questions are of the kind, "does ffmpeg do Atmos right?" and "are there core streams that are dropped upon encoding to presumably-lossless?"

What I did:
 * Extracted each audio stream by ffmpeg -map <argument> -vn -acodec copy streamnumber<num>.m2ts, and
 * then attempted to remux each to MP4 or mka (or native like .ac3 or .dts)
 * had ffmpeg encode some to flac and WavPack
 * opened in foobar2000 with foo_input_ffmpeg to handle *.m2ts and *.dts
 * Used foo_audiomd5 can get ffmpeg's MD5 sums even for streams fb2k cannot decode.
 

Stream 1: ffmpeg identifies as
Audio: truehd (Dolby TrueHD + Dolby Atmos) (AC-3 / 0x332D4341), 48000 Hz, 7.1, s32 (24 bit)
 * ffmpeg question: Does ffmpeg read that correctly so that a further encode to FLAC is indeed lossless?
One reason to ask is that FLAC gets it down to half size. Is the Atmos part just gone?
 * oddity: remux that single stream to a single .m2ts, and fb2k reports it as 0.06 shorter. It probably is, and the container reports the longest stream it has?
 * fb2k: It reads FLAC's default channels the same way as the TRUEHD assigmennt: 8: FL FR FC LFE BL BR SL SR. Not so for 5.1 below.


Stream 2: ffmpeg identifies as
Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 640 kb/s
 * Extracting it to .ac3 (which fb2k identifies as "ATSC A/52A (AC-3)") or .mka, 640 is correct. Extracting it to .m2ts, I get a 747 kb/s stream and a different size, but I guess that the .m2ts overhead is quite large compared to audio.
 * foobar2000's bitcompare says the two it can read, differ at the -31.51 dBFS mark. Huh? (ffmpeg evaluates all three to the same MD5.)


Stream 3: ffmpeg identifies as
Audio: dts (dca) (DTS-HD MA) ([134][0][0][0] / 0x0086), 48000 Hz, 5.1(side), s32p (24 bit)
 * I don't know if DTS-HD MA is "integer LPCM"? If so, same ffmpeg question as under Stream 1. Is it read correctly, so an encode to FLAC/WavPack is indeed lossless?
(Is a core stream dropped or anything? Anyway, FLAC/WavPacking it gets it down from 5Mbit/s to 4.)
 * ffmpeg-ing it to .wv gives 24 bits. What? ffmpeg notoriously puts everything > 16 in 32-bit WavPack, so why not here?
 * ffmpeg to FLAC: does not set channel mask, and foobar2000 interprets FLAC's "back/surround left, back/surround right" as BL BR while this identifies as SL SR. Hence it refuses to bitcompare against the DTS-HD MA.


Stream 4:
Audio: pcm_bluray (HDMV / 0x564D4448), 48000 Hz, stereo, s32 (24 bit), 2304 kb/s
 * There is nothing special about "pcm_bluray" being any other pcm than 24/48 stereo? ffmpeg refuses to remux it into .mka and .mp4 ... but it does remux into .asf as a "Stream #0:0: Audio: none ([128][0][0][0] / 0x0080), 48000 Hz, stereo, 2304 kb/s".  Trying to get ffmpeg to remux into .avi generates a file with bitrate 44994, and that it cannot read. Way to go ... of course, AVI isn't the brightest thing, but why not reject what you cannot do.

 

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #1
Is the Atmos part just gone?
Yes, but the TrueHD part should be lossless.

foobar2000's bitcompare says the two it can read, differ at the -31.51 dBFS mark. Huh?
Downmixing? Dialog normalization? Dynamic range compression?

I don't know if DTS-HD MA is "integer LPCM"?
It is. Unlike stream 1, ffmpeg can decode everything it recognizes in stream 3. (But you won't know if you're missing something ffmpeg doesn't recognize...)

ffmpeg-ing it to .wv gives 24 bits. What? ffmpeg notoriously puts everything > 16 in 32-bit WavPack, so why not here?
This stream decodes to a planar format (s32p), which is supported by ffmpeg's built-in WavPack encoder. The other streams decode to a packed format (s32), which is supported by ffmpeg's subpar libwavpack wrapper. (Wait, how old is your copy of ffmpeg? Didn't they get rid of the libwavpack wrapper a while ago?)

There is nothing special about "pcm_bluray" being any other pcm than 24/48 stereo?
There's nothing special, it's ordinary PCM.

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #2
foobar2000's bitcompare says the two it can read, differ at the -31.51 dBFS mark. Huh?
Downmixing? Dialog normalization? Dynamic range compression?
But why? (Reproduced with portable out of the box fb2k, it shouldn't be my fault.)

ffmpeg-ing it to .wv gives 24 bits. What? ffmpeg notoriously puts everything > 16 in 32-bit WavPack, so why not here?
This stream decodes to a planar format (s32p), which is supported by ffmpeg's built-in WavPack encoder. The other streams decode to a packed format (s32), which is supported by ffmpeg's subpar libwavpack wrapper. (Wait, how old is your copy of ffmpeg? Didn't they get rid of the libwavpack wrapper a while ago?)
None of my ffmpegs up to this 7.1 have ever given out 24-bit .wv unless forced by -bits_per_raw_sample.

Upon encoding either stream - both "to 32" and the right way, it reports:
encoder         : Lavc61.19.100 wavpack

Code: [Select]
ffmpeg version 7.1-essentials_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      59. 39.100 / 59. 39.100
  libavcodec     61. 19.100 / 61. 19.100
  libavformat    61.  7.100 / 61.  7.100
  libavdevice    61.  3.100 / 61.  3.100
  libavfilter    10.  4.100 / 10.  4.100
  libswscale      8.  3.100 /  8.  3.100
  libswresample   5.  3.100 /  5.  3.100
  libpostproc    58.  3.100 / 58.  3.100


Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #3
foobar2000's bitcompare says the two it can read, differ at the -31.51 dBFS mark. Huh?
Downmixing? Dialog normalization? Dynamic range compression?
But why? (Reproduced with portable out of the box fb2k, it shouldn't be my fault.)
Frankly this sounds like a bug. I replicated the problem with a random AC3 file: the file alone vs muxed in Matroska changes the decoded output. Changing the AC3 dialog normalization setting from default "off" to enabled "1" value didn't seem to have a difference. Peter has been pinged.

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #4
Frankly this sounds like a bug. I replicated the problem with a random AC3 file: the file alone vs muxed in Matroska changes the decoded output. Changing the AC3 dialog normalization setting from default "off" to enabled "1" value didn't seem to have a difference. Peter has been pinged.

As for ffmpeg and AC3 - https://ffmpeg.org/ffmpeg-codecs.html#AC_002d3-Decoder-Options
-drc_scale 0 always must be put in command line options before input file if you want to decode AC3 properly. DRC is enabled by default. Because AC3 specification says to do so. Yes, it is as stupid as it is.

ffmpeg -drc_sacale 0 -i ...

fb2k already has this option in advanced preference.

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #5
Learned something today, good ...

Is there no flag to tell from the stream what to use?  And if any such flag exists: does ffmpeg -codec copy transfer it upon remuxing?

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #6
I get the same output wether I omit drc_scale or not. (ffmpeg 7.1.3)

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #7
I get the same output wether I omit drc_scale or not. (ffmpeg 7.1.3)
Not all AC3 streams have DRC info.

Re: Blu-Ray audio codecs: do ffmpeg decode them as should? (Also tried fb2k.)

Reply #8
Not all AC3 streams have DRC info.

Gotcha.  I'll add it to my command anytime I deal with AC3 to be safe. 

I just started looking into re-encoding some Blu-Ray audio codecs recently.  I bought a portable(ish) media player to swap between TVs and I found out it doesn't support TrueHD (but does support AC3, EAC3 and AC4+Atmos)