gpac / gpac

GPAC Ultramedia OSS for Video Streaming & Next-Gen Multimedia Transcoding, Packaging & Delivery
https://gpac.io
GNU Lesser General Public License v2.1
2.76k stars 532 forks source link

Dolby Vision with multiple audio tracks #2694

Closed andrasmaroy closed 10 months ago

andrasmaroy commented 11 months ago

Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

Detailed guidelines: http://gpac.io/bug-reporting/

I'm struggling with muxing dolby vision mkv's into mp4. Usual suspect is an LG tv (B9).

What I'v ran into is that for files that have multiple audio tracks the tv will only recognize dolby vision when playing with the first audio track for other tracks it falls back to HDR10. I'm completely puzzled by this as I don't see how the audio tracks relate to dolby vision. This behaviour is regardless of which track is actually used, if I add the audio streams in reversed order then still the first audio stream works correclty (originally last).

This issue doesn't seem to be specific to one file, all sources I tried (though limited, only 4 files) behaved the same. If I drop the second audio track then the file plays correctly, again regardless of which track is left.

I went through all the issues I found about dolby vision here and tried the varios options from there to avail.

The process I followed:

  1. Extract HEVC and audio streams using ffmpeg ffmpeg -y -i /media/movie.mkv -map 0:1 -c:a:0 copy /media/audio_streams/Hungarian/0.hun.0.eac3 -map 0:2 -c:a:0 copy /media/audio_streams/English/1.eng.0.eac3 -map 0:0 -c:v:0 copy -bsf:v hevc_mp4toannexb /media/movie.hevc
  2. Extract DV RPU with dovi_tool dovi_tool -c -m 2 extract-rpu /media/movie.hevc -o /media/movie.rpu.bin
  3. Downscale HEVC stream to 1080p with ffmpeg ffmpeg -y -hwaccel qsv -i /media/movie.hevc -map 0:0 -c:0 hevc_qsv -qp 25 -preset fast -pix_fmt + -x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:range=limited:transfer=smpte2084:colormatrix=bt2020nc:range=limited:master-display='G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(10000000,0)':dolby-vision-profile=8.1:dolby-vision-rpu='/media/movie.rpu.bin' -vf scale_qsv=w=1920:h=1080 /media/movie-1080p.hevc
  4. Inject DV RPU to the downscaled stream with dovi_tool dovi_tool inject-rpu -i /media/movie-1080p.hevc --rpu-in /media/movie.rpu.bin -o /media/movie.rpu.hevc
  5. Package all streams into mp4 with MP4Box MP4Box -new -add /media/movie.rpu.hevc:dvp=f8.1.hdr10 -add /media/audio_streams/Hungarian/0.hun.0.eac3 -lang 2=hun -name 2=Hungarian -delay 2=0 -add /media/audio_streams/English/1.eng.0.eac3 -lang 3=eng -name 3=English -delay 3=0 -brand mp42 -ab isom -ab dby1 --force_dv /media/movie.mp4

Altough I'm resizing the streams, it doesn't seem be the cause of this, if I skip that step the behaviour is still the same.

I'm using the following versions:

jeanlf commented 10 months ago

Could you try either disabling the additional audio tracks or only removing them from the movie ? You can update the flags using MP4Box -add src:tkhd=enable (see MP4Box -h tkhd)

andrasmaroy commented 10 months ago

Yes, if I completely remove the audio tracks, or only have 1, then DV works correctly. My point is that I'd like to maintain multiple audio tracks along with DV.

jeanlf commented 10 months ago

I mean not removing the track, but deactivating them - some UIs still allow track selection on tracks not enabled or not in movie

andrasmaroy commented 10 months ago

Ah, understood, I'll try it and get back with the results.

andrasmaroy commented 10 months ago

I've tried with the following command, but it is behaving exactly the same.

MP4Box -new -add movie.rpu.hevc -add 0.hun.0.eac3:tkhd=enable -lang 2=hun -name 2=Hungarian -delay 2=0 -add 1.eng.0.eac3:tkhd=enable -lang 3=eng -name 3=English -delay 3=0 -brand mp42 -ab isom -ab dby1 --force_dv movie.mp4

I've tried both tkhd=enable and tkhd=-enable but it made no difference.

jeanlf commented 10 months ago

I've tried both tkhd=enable and tkhd=-enable but it made no difference.

can you try using tkhd=enable,movie for first track and tkhd=enable (or tkhd=-enable) for second ?

andrasmaroy commented 10 months ago

Tried with 0.hun.0.eac3:tkhd=enable,movie and 1.eng.0.eac3:tkhd=enable, but still the same. Both track show up in the selector the same and just like originally the hungarian track (as it is the first) plays with Dolby Vision, english track plays as HDR.

I'm not sure if it is any help, but I'm using Jellyfin to play the track back, version 10.8.11.

jeanlf commented 10 months ago

could you try another player ? I doubt the issue comes from gpac here...

andrasmaroy commented 10 months ago

You are correct, playing back the same file from a pendrive with the built in player works correctly. I'll raise this issue with Jellyfin instead.

I'm sorry for not checking this before, thank you for the assistance!

andrasmaroy commented 7 months ago

Just to confirm in case anyone looks at this in the future: the issue was Jellyfin wrongly reporting no support for multiple audio tracks, forcing the server to transcode the file when selecting the non-default audio track.