media icon indicating copy to clipboard operation
media copied to clipboard

Support Dolby TrueHD in Fragmented MP4

Open Hiroki-Tamaru opened this issue 1 year ago • 2 comments

Version

Media3 1.3.1

More version details

Tested with debug build. Also tested with version 1.3.0.

Devices that reproduce the issue

Fire TV Stick 4K - 2nd Generation (2023) - 8GB (Build Model: AFTKM)

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

  1. Use the ExoPlayer demo in this repository.
  2. Play a Dolby TrueHD Fragmented MP4 file by adding it to media.exolist.json.
  3. Observe the playback behavior.

Expected result

  • The video player's time should progress normally.
  • Playback should not stop.
  • No "Audio sink error" should appear in the console.

Actual result

  • The video player's time progresses very slowly and sometimes even decreases.
  • For video files (not audio-only), the video also progresses very slowly.
  • Playback stops after 55 seconds of real-time (corresponding to 4 seconds of displayed time).
  • A large number of Audio sink errors appear in the console.
Audio sink error
androidx.media3.exoplayer.audio.AudioSink$UnexpectedDiscontinuityException: Unexpected audio track timestamp discontinuity: expected 1000000226666, got 1000000014166
at androidx.media3.exoplayer.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:994)
at androidx.media3.exoplayer.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:744)
at androidx.media3.exoplayer.mediacodec.MediaCodecRenderer.bypassRender(MediaCodecRenderer.java:2310)
at androidx.media3.exoplayer.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:822)
at androidx.media3.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:1112)
at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:544)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
  • The non-fragmented version of the same content can be played without any problem.

Media

Dolby TrueHD 48kHz audio-only fragmented mp4 (10sec fragment): https://d2pbyw961c6y8f.cloudfront.net/dolby_truehd/sunahara_5.1.4_48kHz_dthd_part1_fragmented.mp4 This is a Dolby TrueHD mp4 file created by dolby's official encoder (dolby enocoding engine) and fragmented using MP4Box tool.

Dolby TrueHD 48kHz audio-only mp4 : https://d2pbyw961c6y8f.cloudfront.net/dolby_truehd/sunahara_5.1.4_48kHz_dthd_part1.mp4 This is the non-fragmented version of the same content. This can be played without any problem.

Bug Report

  • [X] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

Hiroki-Tamaru avatar Jul 01 '24 23:07 Hiroki-Tamaru

When I investigated the source code (Mp4Extractor.java and FragmentedMp4Extractor.java), I found that Mp4Extractor uses TrueHdSampleRechunker, while FragmentedMp4Extractor does not. This might be the cause of this issue. Therefore, rather than being a bug, it may be more accurate to say that the combination of Fragmented MP4 files and TrueHD audio is not yet supported. Is there any plan to support this in the future?

Hiroki-Tamaru avatar Oct 08 '24 02:10 Hiroki-Tamaru

Thanks for pointing out this can likely be fixed by using TrueHdSampleRechunker in FragmentedMp4Extractor. I'm afraid we are unlikely to work on this soon, but we would consider a high quality PR implementing this.

icbaker avatar Oct 08 '24 11:10 icbaker