jellyfin / jellyfin-webos

WebOS Client for Jellyfin
https://jellyfin.org
Mozilla Public License 2.0
647 stars 68 forks source link

remux DoVi MKV to MP4 #109

Open obi1 opened 2 years ago

obi1 commented 2 years ago

LG TVs support Dolby vision, but only in MP4 containers.

Would it be possible for Jellyfin to remux the mkv to mp4 and preserve the DoVi?

Right now I'm using ffmpeg to do this manualy before adding the file to the Jellyfin library:

ffmpeg -i input.mkv -map 0 -c copy -strict unofficial -c:s mov_text output.mp4

kvaster commented 1 year ago

One small notice: ffmpeg should be version 5 And it will be really good to have such option to remux mkv to mp4 on the fly...

marcusthorman commented 1 year ago

Additionally, from my experience, for enabling WebOS to playback DoVi content in an mp4 container, the audio track has to be transcoded to eac3, if it is not eac3 already.

I'm unsure if Jellyfin already handles this, but it is worth keeping in mind.

kvaster commented 1 year ago

I have LG OLED C2 and it's not necessary to transcode to eac3. Only DTS-* and TrueHD needs to be transcoded.

marcusthorman commented 1 year ago

I have LG OLED C2 and it's not necessary to transcode to eac3. Only DTS-* and TrueHD needs to be transcoded.

Yes, you are correct that it is only these lossless formats that need transcoding - I forgot to add this information to my comment.

Thank you for noticing :)

kvaster commented 1 year ago

DTS-* is transcoded already for LG WebOS. I've added small patch to my jellyfin installation to force transcode TrueHD aswell and it just works.

Also I should notice that remuxing DoVi to mp4 with ffmpeg must be done with ffmpeg version 5. Version 4 will not work.

marcusthorman commented 1 year ago

Cool --

At the moment I just run a simple automated bash script that does the conversion to formats that are DoVi compatible with my CX - but sure would be nice to have this functionally fully integrated into Jellyfin.

I would love to contribute with to this, but am currently too preoccupied with work and other projects...

There should be enough information here for someone to make an easy integration and make a PR.

PmNz8 commented 1 year ago

Just a small note from me: M2TS container will also trigger DV playback (confirmed on my B1 & C1 at parents house).

mtosic commented 1 year ago

Anybody knows how the player is implemented? Is it invoking native LG player and doing custom OSD over it, or it's Jellyfin implementation?

Schaka commented 1 year ago

Came here to say that Jellyfin already supports remuxing if a container isn't supported. It would seem, that the client isn't reporting it to the server correctly. If there's a way to force the client report no support for mkv (in case there's DV in the stream), everything else should hopefully work.

Imo, this is worth implementing as a hack. I'm sure the TV reports that it can play mkv containers. It's just this one edge case where it doesn't fully support them.

For anyone looking for a quick solution, you can just turn off supportsDolbyVision in webOS.js. This should force transcode to HDR or SDR (I'm not sure which).

Unfortunately, I don't really understand the rest of the code. I suspect the actual info is sent to Jellyfin is either in ´updateMediaSessionoropenUrl`.

I'll create another issue with a specific feature request for this hack

kvaster commented 1 year ago

You don't need to do anything to play the file just in HDR. If you use mkv - you have HDR instead of DV. I also tried to 'make a hack' for myself for test purposes, but for now I don't completely understand the code.

mtosic commented 1 year ago

That's not completely true. DV profile 5 doesn't have HDR fallback layer, and your .mkv file will play in green/purple tones, DV profile 8 has an HDR fallback layer, and mkv will play HDR base layer instead of DV layer.

I was looking at a code few months ago, and I think there is no conditions on specific flags in filetype (for example if file is mkv and has DV_profile=5).

I might have some time in the future to make a PR.

Kimi-Arthur commented 1 year ago

That's not completely true. DV profile 5 doesn't have HDR fallback layer, and your .mkv file will play in green/purple tones, DV profile 8 has an HDR fallback layer, and mkv will play HDR base layer instead of DV layer.

I was looking at a code few months ago, and I think there is no conditions on specific flags in filetype (for example if file is mkv and has DV_profile=5).

I might have some time in the future to make a PR.

Another solution would be "remuxing" mkvs because both DV streams can be played (in DV) via mp4 container. My guts feeling is remuxing the container is not very costly. But maybe an option to enable/disable that behavior.

Schaka commented 1 year ago

If my suggestions in #159 are implemented, it will automatically remux the container because it has no support for mkv+DV. I just need to get around to doing it and haven't had a chance yet.