Opened 18 months ago

Closed 6 months ago

Last modified 6 months ago

#9958 closed defect (fixed)

thd encoder bug: Plex and LG C9 have same artefacts

Reported by: Balling Owned by:
Priority: minor Component: avcodec
Version: git-master Keywords: thd
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by Balling)

Summary of the bug: first of all there is no bug with our ffmpeg decoder, it is all 24 bits lossless and gapless. But that is an illusion: for a very long time Plex Transcoder.exe with EasyAudioEncoder.exe decoder could not decode produced by ffmpeg thd. Now it can thanks to Paul's fixes, so it is now obvious it has same artefacts SAME AS in LG C9 HW decoder, bitstreamed by Lavfilters. I would imagine drp.exe (Dolby reference player) will also have those. Official encoder does not have such artefacts (DEE or Dolby media encoder).

How to reproduce: buy LG C9 or use instruction to get EAE.exe decoder. https://forum.doom9.org/showpost.php?p=1974530&postcount=185

Then decode this sample, encoded with git-master ffmpeg (48k has the same artefacts): https://0x0.st/oJBN.thd

and compare how ffmpeg decodes it with how Plex and LG C9 does, here is it (16 bit has the same artefacts, artefacts start at 00:01:02): https://0x0.st/oJBb.wav

Dolby Media Encoder at least appears to be without artefacts, alas it cannot encode 44.1, so I did on 16 bits ffmpeg.exe -i "sample.thd" -ar 48000 48.wav (https://0x0.st/oJBA.wav) and encoded with Dolby Media Encoder: https://0x0.st/oJBa.mlp

I will just mention how much bigger the ffmpeg file is, compared to oJBa.mlp. https://0x0.st/oJBM.thd

Mono does not have such artefacts.

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (20)

comment:1 by Carl Eugen Hoyos, 18 months ago

Resolution: needs_more_info
Status: newclosed

comment:2 by Balling, 18 months ago

Resolution: needs_more_info
Status: closedreopened

Please reread. The command line is not done with ffmpeg. But with plex. In fact nothing is done with ffmpeg, except encoding.

Last edited 18 months ago by Balling (previous) (diff)

comment:3 by Carl Eugen Hoyos, 18 months ago

Resolution: needs_more_info
Status: reopenedclosed

comment:4 by Balling, 18 months ago

Resolution: needs_more_info
Status: closedreopened

This is how I encoded 48 sample, e.g.

PS ffmpeg.exe -i 48_2.wav -strict -2 awsfdafda1.thd
ffmpeg version N-108353-g7cd252ee41-20220925 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (crosstool-NG 1.25.0.55_3defb7b)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20220925
  libavutil      57. 36.102 / 57. 36.102
  libavcodec     59. 46.100 / 59. 46.100
  libavformat    59. 33.100 / 59. 33.100
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 49.100 /  8. 49.100
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from '48_2.wav':
  Metadata:
    artist          : Николай Басков
    date            : 2018
    genre           : Gospel Pop
    title           : Молите Господа О Нас
    album           : Верую
    track           : 08
    encoder         : Lavf59.33.100
  Duration: 00:04:33.39, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 2 channels, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> truehd (native))
Press [q] to stop, [?] for help
Output #0, truehd, to 'awsfdafda1.thd':
  Metadata:
    artist          : Николай Басков
    date            : 2018
    genre           : Gospel Pop
    title           : Молите Господа О Нас
    album           : Верую
    track           : 08
    encoder         : Lavf59.33.100
  Stream #0:0: Audio: truehd, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      encoder         : Lavc59.46.100 truehd
size=   39907kB time=00:04:33.39 bitrate=1195.8kbits/s speed=95.6x
video:0kB audio:39907kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

comment:5 by Carl Eugen Hoyos, 18 months ago

Component: undeterminedavcodec
Priority: normalminor

The usage of strict -2 indicates a minor issue.

comment:6 by Balling, 18 months ago

That is what can remove experemental status. You did get Plex, Carl? Then you can check some older encodes, those were not even decoding at all in Plex, it did not like the bitstream, even though it was just a couple of flags.

BTW, it would be nice to get all those samples somewhere safer. :)

Last edited 18 months ago by Balling (previous) (diff)

comment:7 by Balling, 18 months ago

Also, I cut mono from the stereo with -af channelmap=channel_layout=mono:map=0 and the encoded by ffmpeg mono thd has no difference with decoding by Plex. No artefacts. Bitperfect, except for some zero bytes in the end.

Last edited 7 months ago by Balling (previous) (diff)

comment:8 by Balling, 18 months ago

Description: modified (diff)

comment:9 by Balling, 18 months ago

Owner: set to richarddpl
Status: reopenedopen

Assigning to owner of Twitter. Is it possible that our decoder of official thd is still partially lossy? Off-by-ones are either on our side on Dolby's. We need to know.

Carl, can you backup the 0x0 links? Or should I?

Last edited 18 months ago by Balling (previous) (diff)

comment:10 by Balling, 18 months ago

Owner: changed from richarddpl to Elon Musk

Try this.

comment:11 by Elon Musk, 18 months ago

Owner: Elon Musk removed

I do not want to have anything in common with you.

in reply to:  6 comment:12 by Balling, 15 months ago

Replying to Balling:

Then you can check some older encodes, those were not even decoding at all in Plex, it did not like the bitstream, even though it was just a couple of flags.

I got the confirmation that some commit fixed Oppo stereo thd playback too. Not only Plex. https://forum.doom9.org/showpost.php?p=1976413&postcount=24

I also got Dolby Reference player and there artefacts are much less profound, at least in 32 bit float. But I still think there is a bug, AT LEAST compression algorithm code is horrible. BUT!! https://0x0.st/oJBa.mlp is not apparently lossless, it has some small amount of byte differences (!). So there is also a bug in Dolby Media Encoder or there is an additional off-by-one bug in our decoder.

comment:13 by Elon Musk, 6 months ago

Resolution: needs_more_info
Status: openclosed

Input file is gone.

comment:14 by Balling, 6 months ago

Resolution: needs_more_info
Status: closedreopened

7z with 2 files: https://0x0.st/HWH7.7z

I hope you do have Plex.

comment:15 by Elon Musk, 6 months ago

The 16bit encoder mode producing invalid bitstream have been fixed in another recent commit.
So are all those files you uploaded actual ffmpeg encoded files? If yes they are no longer relevant. Please provide input files (not produced by experimental new or older mlp/thd encoder) that still gives invalid output when encoded by FFmpeg's thd/mlp encoder and gives artifacts on hw decoders.

comment:16 by Balling, 6 months ago

Checked HEAD of master the files are encoded the same (will also check 0be5da9cfa745ca734c50d75491fd2d79c374789 tomorrow). Which you could have checked yourself, BTW.

Again, do you need Plex? You did not answer so I will attach Plex decoder flac for you, it has artefacts at 00:01:02, so FFmpeg encoder is wrong. Again, same happens with HW decoder in LG C9.

https://0x0.st/HWTl.flac

Last edited 6 months ago by Balling (previous) (diff)

comment:17 by Balling, 6 months ago

Very bad your recent 3 thd encoder changes broke it all, the decoding is mostly noise now.

Same in plex and DRP and LG C9: [truehd_eae @ 00000171d45ae340] EAE output unaligned (got 40, expected 640)

Same for -lpc_type cholesky

Last edited 6 months ago by Balling (previous) (diff)

comment:18 by Elon Musk, 6 months ago

Resolution: fixed
Status: reopenedclosed

Was buggy matrix code, disabled until properly resolved.

comment:19 by Balling, 6 months ago

Cool. Fixed (even cholesky), indeed :) Checked Plex, lossless with the source (even some zero samples in the end in our ffmpeg TrueHD decoder are fixed). Insane code skills.

d7579189f762065f8efd63aea12e6e59c303d5ae !!!

comment:20 by Elon Musk, 6 months ago

Added back somehow limited stereo decorrelation code, to help compress fully mono/out of phase stereo parts and when left is rational multiple of right channel.

Note: See TracTickets for help on using tickets.