Plex displays wrong colours with Dolby Vision on AppleTV 4k

Fair enough, thank you.
Will provide requested information in the coming days and try a newer ffmpeg version.

1 Like

Hi there @Ridley

sorry for taking so long but I produced the request logs.
Server and client logs with debug (server) and verbose(client) enabled
I’ll PM you the logs shortly.

I downloaded the file from the original post and transferred it into a container format Plex don’t instantly dismisses with

ffmpeg -i dolbydemoTS.ts -vcodec copy -acodec copy -strict -1 dolbydemoMP4.mp4

Ffmpeg version is 5.0.1
Plex server version is: 1.26.0.5715-8cf78dab3
Plex client is: 8.2(2517)
tvOS version is: 15.4.1(19L452)

Using the -strict 1 option changes things a bit, no video is shown at all now, same as with jus.mp4 before, just an endless loading circle.

The original file is called dolbydemoTS.ts and won’t even start to play
The transcoded file is dolbydemoMP4.mp4 and does not play anymore, endless loading spinner
The jus.mp4 file plays only audio with the same loading spinner on screen as dolbydemoMP4.mp4 while the audio is going forward.

The jus.mp4 file is 32GB big, if you have a fast connection I can rsync/scp it to you, or I can add you to the Plex server so you can DL it or test directly if you got an aTV at home/work.

All those files play perfectly on the Sony Plex app on my Sony TV and on infuse on the aTV (at least last time I checked)

I played all three files in this order:

dolbydemoTS.ts. (did not play)
dolbydemoMP4.mp4. (no video is shown, only loading spinner)
Jus.mp4 (only audio played and loading spinner)

The files were played at around 05:04 PM, so you have an easier time finding those in the log files.

Let me know if I can do anything else to help debugging.

4 Likes

The Codec ID/sample entry name/tag seems to matter to AVPlayer.

hev1 is an option for non-DV HEVC, or DV HEVC with a cross-compatible BL. It stores parameters in the stream. QuickTime Player won’t open these.
No video (endless spinner), DV not triggered, audio playing:

ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i "dolby-vision-onoff-(www.demolandia.net).ts" -map 0 -c:a copy -c:v copy -tag:v hev1 -strict unofficial dvdemo-p5-hev1.mp4
# '-tag:v hev1' is default; included for clarity
# analyzeduration and probesize because it's a garbage .ts

hvc1 is Apple’s preference for non-DV HEVC MP4 or for HEVC DV with cross-compatible BL.
Video plays, DV not triggered, busted purplegreens:

ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i "dolby-vision-onoff-(www.demolandia.net).ts" -map 0 -c:a copy -c:v copy -tag:v hvc1 -strict unofficial dvdemo-p5-hvc1.mp4
# analyzeduration and probesize because it's a garbage .ts

dvh1 is the Apple-preferred version of HEVC DV MP4 with non-cross-compatible BL (such as P5). It’s muxed like hvc1, but ffmpeg can’t produce files tagged as dvh1.

So let’s do some stupid ■■■■, modifying the previous output file:

sed 's/hvc1/dvh1/' dvdemo-p5-hvc1.mp4 > dvdemo-p5-dvh1.mp4

:star: :star: :star:
That WORKS!  
DV is triggered, video plays, color is good, audio plays.
:star: :star: :star:

11 Likes

I wonder if Plex can silently correct broken DoVi P5 hvc1 files, sending them as dvh1 to Apple devices? That’s “icky” but would fix them.

Footnote: Dolby’s mp4muxer can be made to produce files with dvh1, and those do trigger DV on the TV. But they don’t display video, and the files it produces seem to be muxed weird.

Footnote2: This is a sane, fast way to modify existing files. It can relabel hvc1dvh1. GitHub - omgcli/mp4dovi: Change video codec in MP4 files for Apple QuickTime conformance.

Edit: Or MP4Box is a much better choice than my ffmpeg | sed hack. You have to extract the component streams, but MP4Box makes good files.

# still using the sample file from the first post!
ffmpeg -i "dolby-vision-onoff-(www.demolandia.net).ts" -c copy dvdemo.h265
ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i "dolby-vision-onoff-(www.demolandia.net).ts" -c copy dvdemo.eac3
# analyzeduration and probesize because it's a garbage .ts
MP4Box -add dvdemo.h265:dv-profile=5 -add dvdemo.eac3 -new dvdemo-p5-mp4box.mp4
# it will actually autodetect dv-profile=5 from this source

Hey, folks who are complaining about files that don’t work - can you PM me links to a couple? What’s their Codec ID?

2 Likes

There’s a lot of dvhe DV P5 content out there. Unless Plex makes a change I don’t expect dvhe to work on Apple TVs. Apple expects dvh1.

Simply relabeling dvhe to dvh1 doesn’t work, because they should be muxed differently.

The straightforward solution for dvhe is to extract the raw streams and mux them with MP4Box to produce an Apple-compatible dvh1.

But that process is annoying when there are many streams. :laughing:

ffmpeg emits files with hvc1, which I think is incorrect behavior. But hvc1 is muxed similarly to dvh1 and can be easily relabeled with mp4dovi.

So a lazy, good-enough option seems to be:

ffmpeg -i input.mp4 -map 0 -c:a copy -c:v copy -bsf:v hevc_mp4toannexb -tag:v hvc1 -strict unofficial -movflags faststart output.mp4
mp4dovi -from hvc1 -to dvh1 output.mp4

Feedback and observations from others?

2 Likes

Interesting, I wonder how they did it with the infuse player.

6 Likes

Thanks!!

I couldn’t get the MP4Box method to work but I tried the mp4dovi method with 2 DV only files I had and now it automatically switches over to the old player and plays correctly on iOS/tvOS.

1 Like

@Volts great research! I guess in retrospect reading something like Apple’s guide to streaming formats (See section 1.10):
https://developer.apple.com/documentation/http_live_streaming/http_live_streaming_hls_authoring_specification_for_apple_devices

would have been prudent when Plex does the remuxing :grinning:

Anyway, what a pain, but thanks again!

1 Like

But is it really stupid if it works?

No, you’re right, that is some dumb ■■■■. :wink:

For others on a Mac, prepend "LANG=C && " to the sed command to resolve the “sed: RE error: illegal byte sequence” error. E.g. “LANG=C && sed ‘s/hvc1/dvh1/’ dvdemo-p5-hvc1.mp4 > dvdemo-p5-dvh1.mp4”

Somewhat related, this takes an age on a full feature. Is this string muxed throughout the file? Or could this be done “in place” on the first x bytes of a file?

1 Like

It could be done in place and with no backup.

But check out the mp4dovi tool for something that actually parses the file and MP4 atoms correctly and rewrites it in place. It’s very fast.

@Volts Tried the ffmpeg/mp4dovi commands on a couple mp4->mp4 files using ffmpeg-5.0.1-amd64-static and they work great! Then I tried on one of the DV .mkv files in order to remux from mkv to mp4 and then run mp4dovi but I get this error during the ffmpeg rmeux from mkv to mp4:

I guess we need to do something different to convert DV MKV files?

2 Likes

Can you share the mediainfo -f for the file that didn’t work?

I came across a similar issue when converting mkv to mp4. For me it was because the mp4 container didn’t support subrip subs so I had to convert the subs using -c:s mov_text.

Another thing I noticed is that the AVPlayer has to be able to direct play the resulting MP4 file. Meaning files with TrueHD audio tracks won’t work. Any kind of conversion including direct streaming will result in the color space error.

1 Like

That’s why I didn’t put -c:s copy in the command I suggested!

Huh. I thought mov_text would be implied by MP4 for text-based subs.

100% this. Good reminder.

Can you PM me a sample?

TrueHD works with AVPlayer in other situations. Samples made with MP4Box work well.

I expect FFmpeg to need -strict experimental for TrueHD support, but I’m seeing other weirdness too.

I suspect FFmpeg is just not the right tool for muxing DV, and the cheater command I was using was lucky but not correct.

MP4Box and the Dolby tool both seem to work well.

I tried experimental with TrueHD and ffmpeg will generate the mp4 with TrueHD, and plex will recognize the audio stream but it seems ATV AVPlayer rejects it:

If I keep everything the same but swap out the TrueHD audio stream for the EAC3 stream it works fine.

Also it seems even pgs mkv subtitles are rejected during ffmpeg remuxing with an error:

Error initializing output stream 0:24 – Subtitle encoding currently only possible from text to text or bitmap to bitmap

Any update, or anything more you need @Ridley?

3 Likes

We’re currently actively investigating this issue.

8 Likes

@Orko thank you for taking the time to grab all that stuff for them.

1 Like

PGS implies a UHD Blu-ray DV source?

If so, that would be Profile 7. Most of my comments here wouldn’t be applicable. (dvhe and dvh1 apply to DV MP4 that doesn’t have a backwards-compatible base layer. Profile 7 has an HDR10-compatible base layer, and should be hevc or hvc1.)

If not, I’m very curious. Do you have a file with PGS subs that isn’t from Blu-ray?

If you share a sample I’d love to look at it. I’ve been having good luck.

I would agree that PGS implies a Bluray DV source, although oddly when I look at the MediaInfo for the movie is shows profile 5:

Dolby Vision, Version 1.0, dvhe.05.06, BL+RPU

I was actually just curious because I though ffmpeg could do subtitle format conversions and so I expected it to be able to convert those… I guess that’s not the case.

For the clip can I simply use ffmpeg to create a shorter version of the movie? Will that maintain all the relevant data or will it loose some of the HDR/DV metadata?