Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] LG webos + Dolby Vision =⛔ movie stutters then hangs when resuming or skipping ahead #248

Open
megosugit opened this issue Sep 2, 2024 · 39 comments

Comments

@megosugit
Copy link

megosugit commented Sep 2, 2024

(bug is still present with 10.9.11)

Hello all,

this specific issue doesn't seem to be addressed in other topics, some are similar but not really, and most of them are more or less inactives.
I have been hoping for a fix since I started with Jellyfin in march, but it hasn't come yet, so I'm trying my luck by opening this issue.

The issue:
When I try to resume a Dolby Vision movie, or if I start over and then skip ahead (more than a few minutes), then the movie will start normally in direct play, but after 10 seconds (sometimes a bit more, I have managed to watch more than 10min once!), it starts to freeze for a few seconds, then can eventually continue for a few more seconds but will start to hang very quickly.
If I don't touch anything for 1 or 2 minutes, I can see the movie "poster" flashing as if the movie stopped and started again, then it resumes the movie but this time it tries to transcode it, which gives bad colors and bad performance.

If I play the movie from the beginning, then it plays perfectly (in direct play).
If I start from the beginning and skip ahead without exceeding ~3min each steps, I can eventually reach the part I need to, but it takes a long time to reach the correct position, and very often, the subtitles become out of sync.
If I skip ahead more than ~3min in one go, then the "freezing/hanging/switching to transcoding" issue happens again when I stop skipping.
After reading the forum, I have disabled the "prefer mp4" option without more success.

The TV (LG G3) is new and my Jellyfin installation too, so I can't tell when the issue started, but it has been doing it since I started to use Jellyfin in march.

Currently, I have given up with Dolby Vision movies, they are unwatchable, unless I know for sure I can watch it in one go without the need to stop and resume next time, which I can very seldom do :(
I can't even disable Dolby Vision (on the TV or in Jellyfin) to avoid this issue and force HDR layer, so I'm pretty stuck whenever there is a DoVi movie.

Please find below a few examples of Video profiles that presents this issue (DV Profile 5 and 8.1 from what I can see):

Video
Title: 4K HEVC HDR
Codec: HEVC
AVC: No
Profile: Main 10
Level: 150
Resolution: 3840x1608
Aspect ratio: 2.40:1
Anamorphic: No
Interlaced: No
Framerate: 23.976025
Bitrate: 24443 kbps
Bit depth: 10 bit
Video range: HDR
Video range type: DOVIWithHDR10
DV title: DV Profile 8.1 (HDR10)
DV version major: 1
DV version minor: 0
DV profile: 8
DV level: 6
DV rpu preset flag: 1
DV el preset flag: 0
DV bl preset flag: 1
DV bl signal compatibility id: 1
Color space: bt2020nc
Color transfer: smpte2084
Color primaries: bt2020
Pixel format: yuv420p10le
Ref frames: 1

Video
Title: 4K HEVC HDR
Codec: HEVC
AVC: No
Profile: Main 10
Level: 150
Resolution: 3840x1606
Aspect ratio: 2.40:1
Anamorphic: No
Interlaced: No
Framerate: 24
Bitrate: 24795 kbps
Bit depth: 10 bit
Video range: HDR
Video range type: DOVIWithHDR10
DV title: DV Profile 8.1 (HDR10)
DV version major: 1
DV version minor: 0
DV profile: 8
DV level: 6
DV rpu preset flag: 1
DV el preset flag: 0
DV bl preset flag: 1
DV bl signal compatibility id: 1
Color space: bt2020nc
Color transfer: smpte2084
Color primaries: bt2020
Pixel format: yuv420p10le
Ref frames: 1

Video
Title: 4K HEVC HDR
Codec: HEVC
AVC: No
Profile: Main 10
Level: 150
Resolution: 3840x2160
Aspect ratio: 16:9
Anamorphic: No
Interlaced: No
Framerate: 24
Bitrate: 11494 kbps
Bit depth: 10 bit
Video range: HDR
Video range type: DOVIWithHDR10
DV title: DV Profile 8.1 (HDR10)
DV version major: 1
DV version minor: 0
DV profile: 8
DV level: 6
DV rpu preset flag: 1
DV el preset flag: 0
DV bl preset flag: 1
DV bl signal compatibility id: 1
Color space: bt2020nc
Color transfer: smpte2084
Color primaries: bt2020
Pixel format: yuv420p10le
Ref frames: 1

Video
Title: 4K - HEVC - HDR
Codec: HEVC
AVC: No
Profile: Main 10
Level: 150
Resolution: 3836x1600
Aspect ratio: 2.40:1
Anamorphic: No
Interlaced: No
Framerate: 23.976025
Bitrate: 16145 kbps
Bit depth: 10 bit
Video range: HDR
Video range type: DOVI
DV title: DV Profile 5
DV version major: 1
DV version minor: 0
DV profile: 5
DV level: 6
DV rpu preset flag: 1
DV el preset flag: 0
DV bl preset flag: 1
DV bl signal compatibility id: 0
Pixel format: yuv420p10le
Ref frames: 1

I'm ready to help as much as I can, please let me know whatever you need and I'll try to get it asap :)

@megosugit megosugit changed the title LG webos + Dolby Vision - movie stutters then hangs when resuming or skipping ahead LG webos + Dolby Vision =⛔ movie stutters then hangs when resuming or skipping ahead Sep 3, 2024
@riberts
Copy link

riberts commented Oct 9, 2024

i just tried to play a movie and seem to have the same issue..

@megosugit
Copy link
Author

i just tried to play a movie and seem to have the same issue..

what is you TV model ?

@matteocnt92
Copy link

same issue on my LG C2

@riberts
Copy link

riberts commented Oct 12, 2024

i just tried to play a movie and seem to have the same issue..

what is you TV model ?

LG G2

@Acextreme1982
Copy link

Exactly the same issue I am facing now with my LG G3. At first, I thought it was the transcoding problem but on the server side, I can access all the temporary small parts of transcoded videos and I can play those on the server itself just fine using a normal media player, including the parts that hung on my LG G3. It's definitely something else that's the problem.

@megosugit
Copy link
Author

I suspect every WebOS users have this issue with Dolby Vision content.
This should get more attention, how can we get this thread more visibility ?

I wonder if it is posted in the right place ?

@Acextreme1982
Copy link

Acextreme1982 commented Oct 16, 2024

Hmmm, well, let's do this: https://jellyfin.org/docs/general/contributing/issues

Under "Searching and Voting" section, it said the following:

If you do find an issue that matches, or closely matches, your issue, please make use of the 👍 reaction to confirm the issue also affects you or that you support the feature request. If you wish, add a comment as well describing your version of the issue or feature use case.

I just did that on your opening post. Everyone, please do that as well.

@Acextreme1982
Copy link

I suspect every WebOS users have this issue with Dolby Vision content. This should get more attention, how can we get this thread more visibility ?

I wonder if it is posted in the right place ?

Hmmm, I think you need to do a couple more things. Like:

Bugs should be tagged with [bug] at the beginning of their title.

Check the above link and see what else you need to do right, otherwise it might affect their response.

@megosugit megosugit changed the title LG webos + Dolby Vision =⛔ movie stutters then hangs when resuming or skipping ahead [bug] LG webos + Dolby Vision =⛔ movie stutters then hangs when resuming or skipping ahead Oct 17, 2024
@megosugit
Copy link
Author

megosugit commented Oct 17, 2024

Hmmm, well, let's do this: https://jellyfin.org/docs/general/contributing/issues

Under "Searching and Voting" section, it said the following:

If you do find an issue that matches, or closely matches, your issue, please make use of the 👍 reaction to confirm the issue also affects you or that you support the feature request. If you wish, add a comment as well describing your version of the issue or feature use case.

I just did that on your opening post. Everyone, please do that as well.

I did too :p
and I changed the title,
thanks

@megosugit
Copy link
Author

@gnattu or @GeorgeH005, is it something you would know about ?

@stromrickard
Copy link

I'm currently in the process of switching from Plex to Jellyfin and am reading up on any issues i might encounter and stumbled in here. I have 3 LG OLEDs, 77C1, 65C8 and a 48A1. I was however unable to replicate this on any of them. Resuming and skipping 20-30min causes no issues.
Only point of this post is to indicate that the problem might be more elusive, only certain models, firmware versions, files etc.
In case it matters, none of my TVs are on WiFi.
Tested file:
Titel4K HEVC HDR
KodekHEVC
AVCNo
ProfilMain 10
Nivå150
Upplösning3840x1606
Bildförhållande2.40:1
AnamorfiskNo
SammanflätadNo
Bildfrekvens24
Bithastighet25313 kbps
Bitdjup10 bit
Video-omfångHDR
VideointervallstypDOVIWithHDR10
DV titelDV Profile 8.1 (HDR10)
DV huvudversion1
DV mindre version0
DV profil8
DV nivå6
Förinställd flagga för DV rpu1
Förinställd flagga för DV el0
Förinställd flagga för DV bl1
DV bl signalkompatibilitets-id1
Färgrymdbt2020nc
Färgöverföringsmpte2084
Färgprimärerbt2020
Pixelformatyuv420p10le
Referensbildrutor1

@GeorgeH005
Copy link

GeorgeH005 commented Oct 17, 2024

@gnattu or @GeorgeH005, is it something you would know about ?

This was an issue that had come up during testing, but only when using the fmp4 container. When using ts, I wasn't able to replicate it. The only slightly enlightening error that had occurred was the app crashing (when using fmp4) reportedly due to running out of memory. Csn't tell you much more than that. Maybe the Jellyfin webUI (that this app is wrapping) is just too heavy? Haven't conducted any research so I can't answer that.

Edit: I am using a C3 and the tests were conducted on WebOS 23

@Acextreme1982
Copy link

My files are in MKV container and as far as I know, all 3 files are using Profile 8.1 and all 3 had the same issue.

@ppskj178
Copy link

I struggled with this for a while and eventually gave up.

Even videos by the same person have different symptoms.

Fortunately, recent videos seem to be less prone to the problem.

My guess is that the root of the problem lies with LG.

Dolby Vision only works with MP4 and the
FLAC codec only supports audio, not video.
TVs are meant for video only, and yet they have worse video compatibility than PCs and phones.

This is a serious problem.

@megosugit
Copy link
Author

I struggled with this for a while and eventually gave up.

Even videos by the same person have different symptoms.

Fortunately, recent videos seem to be less prone to the problem.

My guess is that the root of the problem lies with LG.

Dolby Vision only works with MP4 and the FLAC codec only supports audio, not video. TVs are meant for video only, and yet they have worse video compatibility than PCs and phones.

This is a serious problem.

you can still put a thumb up on the first post, to gain more visibility, maybe it will be fixed eventually :)

@ppskj178
Copy link

Have you tried to see if you can reproduce the same issue in other ways: plex, dlna, usb...
If it's in mp4 format, I guess I can test it. Is this issue only happening with mkv?

@GeorgeH005
Copy link

Have you tried to see if you can reproduce the same issue in other ways: plex, dlna, usb... If it's in mp4 format, I guess I can test it. Is this issue only happening with mkv?

USB is fine even with mp4 if I remember correctly, plex and dlna I haven't tested. I could test Plex, but I would have to reconvert a file to mp4.

@klawson6
Copy link

Hi folks, I've narrowed my problem down to this issue as well.

LG OLED C2 (WebOS v8.3.0-29 (number1-nameri)
Jellyfin v10.9.11

Playing .mkv files with Dolby Vision Profile 8.1 fails. Either first few frames then stops or green screen tearing and static.

Seems to be exactly this combo .mkv with DV (only have profile 8.1 to test with).

DV with .mp4 works fine and HDR10 on both containers works fine.

Playing .mkv + DV via USB doesn't trigger the DV or HDR toaster pop up so unsure if it's playing with either but it does play regardless.

@ppskj178
Copy link

Have you tried to see if you can reproduce the same issue in other ways: plex, dlna, usb... If it's in mp4 format, I guess I can test it. Is this issue only happening with mkv?

USB is fine even with mp4 if I remember correctly, plex and dlna I haven't tested. I could test Plex, but I would have to reconvert a file to mp4.

If so, it sounds like it might be a remux issue. We might want to try raising an issue on the server side

@GeorgeH005
Copy link

I had thought the same back then as well, but it was in a good enough point in my case, that it wasn't worth debugging the web client or server side. My suspicions lie on the client side. I will try to see if I find something worth exploring.

@megosugit
Copy link
Author

How can I help on my side?

I can reproduce it easily, please let me know what kind of log could be interesting

@gnattu
Copy link
Member

gnattu commented Oct 26, 2024

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.

The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

@GeorgeH005
Copy link

The problem seems to be that the hls player doesn't like not having the segments ready when seeking or resuming. If you look at the Jellyfin-web code, there was a hack for safari that made sure that there were segments available on playback start. By hacking that a bit to work on seek and on web0s (essentially forcing it to use live.m3u8 rather than master.m3u8) web0s can seek freely anywhere that has already been transcoded. This prevents the stall that we were seeing. Maybe we can introduce some kind of loading until there are segments ready instead of feeding it the url immediately and leaving it to handle it?

@GeorgeH005
Copy link

This issue seems better suited to Jellyfin-web as this repo contains a wrapper that does not interfere with playback.

@Acextreme1982
Copy link

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.

The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

Hmmm, ok, so I went and remux the .MKV file into MP4 using the above command you provided, using the ffmpeg in JellyFin's Server folder and absolutely no issues. I can see the dolby vision and dolby atmos popup on the top right hand corner of the TV when I play it with the JellyFin client on my LG G3 TV. So definitely it's an MKV + Dolby Vision problem in combination with LG TVs.

@GeorgeH005
Copy link

GeorgeH005 commented Oct 27, 2024

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.
The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

Hmmm, ok, so I went and remux the .MKV file into MP4 using the above command you provided, using the ffmpeg in JellyFin's Server folder and absolutely no issues. I can see the dolby vision and dolby atmos popup on the top right hand corner of the TV when I play it with the JellyFin client on my LG G3 TV. So definitely it's an MKV + Dolby Vision problem in combination with LG TVs.

LG TVs are UNable to playback Dolby Vision in MKV, neither with Jellyfin, nor with DLNA, not even with USB. That much we knew. The problem is that LG's hls player does not like not having fmp4 fragments ready as soon as it needs them it seems, which is a problem when we are transcoding/remuxing. The issue described here is reproducible even without dolby vision. I believe, apart from maybe implementing some extra loading in order to wait for the server to have some fragments ready, there is not much we can do.

@megosugit
Copy link
Author

I'm not sure to understand. My LG TV can play DV in mkv very well with jellyfin, unless I skip ahead more than ~3min or if I resume a movie I already started.

Would it help if I try from a usb stick or with dlna to confirm if the issue is still present?

@GeorgeH005
Copy link

GeorgeH005 commented Oct 27, 2024

I'm not sure to understand. My LG TV can play DV in mkv very well with jellyfin, unless I skip ahead more than ~3min or if I resume a movie I already started.

Would it help if I try from a usb stick or with dlna to confirm if the issue is still present?

Because we are remuxing on the fly to mp4 or ts respectively. If we weren't dolby vision would not be triggered. You can try it for yourself if you want with an mkv and a USB but there was a relevant pull request that had all the details regarding this.

@ppskj178
Copy link

ppskj178 commented Oct 28, 2024

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.
The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

Hmmm, ok, so I went and remux the .MKV file into MP4 using the above command you provided, using the ffmpeg in JellyFin's Server folder and absolutely no issues. I can see the dolby vision and dolby atmos popup on the top right hand corner of the TV when I play it with the JellyFin client on my LG G3 TV. So definitely it's an MKV + Dolby Vision problem in combination with LG TVs.

LG TVs are UNable to playback Dolby Vision in MKV, neither with Jellyfin, nor with DLNA, not even with USB. That much we knew. The problem is that LG's hls player does not like not having fmp4 fragments ready as soon as it needs them it seems, which is a problem when we are transcoding/remuxing. The issue described here is reproducible even without dolby vision. I believe, apart from maybe implementing some extra loading in order to wait for the server to have some fragments ready, there is not much we can do.

This inspired me to test it out and I found a workaround.

When remuxing, I wait until the orange gauge on the dashboard is full before I change the playback location. This worked for me.

If anyone else is like me, it would be a huge help right now if this orange bar could be displayed in the client as well.

@ppskj178
Copy link

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.

The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

@gnattu
As you said, I will try to use the mp4 format in the future.
Do you think this will work with other clients?

I'd like to know if the LG TV is the most picky device.
If you know of other types of clients that are picky about media files, please let me know

@gnattu
Copy link
Member

gnattu commented Oct 28, 2024

As you said, I will try to use the mp4 format in the future.
Do you think this will work with other clients?

mp4 has much better compatibility in general as mkv is a very complex container.

I'd like to know if the LG TV is the most picky device.
If you know of other types of clients that are picky about media files, please let me know

There are a lot of picky devices for direct play, but for most of them Jellyfin could do on-the-fly remuxing to make it work without a transcoding, and the HLS player quirks is what makes it work badly on LG TVs.

@ppskj178
Copy link

As you said, I will try to use the mp4 format in the future.
Do you think this will work with other clients?

mp4 has much better compatibility in general as mkv is a very complex container.

I'd like to know if the LG TV is the most picky device.
If you know of other types of clients that are picky about media files, please let me know

There are a lot of picky devices for direct play, but for most of them Jellyfin could do on-the-fly remuxing to make it work without a transcoding, and the HLS player quirks is what makes it work badly on LG TVs.

thnak you

@Acextreme1982
Copy link

I am very certain it is a client specific issue and it is even webOS/TV model specific issue. The problem is some webOS TV model has a very buggy native HLS player that is unable to handle Dolby Vision correctly and that is what Jellyfin is using to do the on-the-fly remuxing to enable dolby vision. The problem is that:

  • LG TVs won't play Dolby Vision in mkv, it will always use the HDR10 fallback
  • Some LG TV models do not handle Dolby Vision in HLS either, makes the server side remuxing also not working

Currently your best choice is to manually remux the file into mp4 if you want to keep dolby vision and make your TV happly. We can do little for this other than some very unfortunate option like "disable dolby vision for this TV" so that the server will send the mkv as-is and just play the HDR10 fallback.
The way to remux to mp4 is to jellyfin-ffmpeg (the upstream one may work worse), for example:

ffmpeg -i input.mkv -c:v copy -c:a copy -strict -2 out.mp4

Hmmm, ok, so I went and remux the .MKV file into MP4 using the above command you provided, using the ffmpeg in JellyFin's Server folder and absolutely no issues. I can see the dolby vision and dolby atmos popup on the top right hand corner of the TV when I play it with the JellyFin client on my LG G3 TV. So definitely it's an MKV + Dolby Vision problem in combination with LG TVs.

LG TVs are UNable to playback Dolby Vision in MKV, neither with Jellyfin, nor with DLNA, not even with USB. That much we knew. The problem is that LG's hls player does not like not having fmp4 fragments ready as soon as it needs them it seems, which is a problem when we are transcoding/remuxing. The issue described here is reproducible even without dolby vision. I believe, apart from maybe implementing some extra loading in order to wait for the server to have some fragments ready, there is not much we can do.

I am not quite sure I understand you. Why is LG's HLS player being brought up? I am using Jellyfin's app on my TV to connect to my Jellyfin server to play the mkv files. Is the Jellyfin app actually using the HLS player to play the on-the-fly remux files?

@GeorgeH005
Copy link

@gnattu Changing one line in the web client to make webOS use hls.js seems to work well! Under direct play conditions dolby vision is triggered as usual, and when forcing a transcode or a remux, seeking works well even with fmp4. If you have any thoughts on what should be changed/tested I would be happy to help! It seems like a good solution for now.

@gnattu
Copy link
Member

gnattu commented Oct 28, 2024

Changing one line in the web client to make webOS use hls.js seems to work well

We were not using HLS.js for a reason as some models works exceptionally bad with that.

@gnattu
Copy link
Member

gnattu commented Oct 28, 2024

I am not quite sure I understand you. Why is LG's HLS player being brought up? I am using Jellyfin's app on my TV to connect to my Jellyfin server to play the mkv files. Is the Jellyfin app actually using the HLS player to play the on-the-fly remux files?

Because LG TVs cannot play Dolby Vision as Dolby Vision in mkv, so the server has to remux it, and the remux is delivered with HLS, which uses native HLS player of the LG TV.

@GeorgeH005
Copy link

Changing one line in the web client to make webOS use hls.js seems to work well

We were not using HLS.js for a reason as some models works exceptionally bad with that.

That's a shame, could still be a solution for newer models.

@ppskj178
Copy link

ppskj178 commented Nov 1, 2024

AI-generated script.
It has been tested for basic behavior, but has not yet been tested in many environments. Use with caution.

#!/bin/bash

mkv2mp4() {
    if [ -z "$1" ]; then
        echo "Usage: mkv2mp4 <directory_path> [default audio track number (starts from 0)]"
        echo "Use only for HEVC videos that support Dolby Vision."
        return 1
    fi

    # Modify and use the path correctly.
    FFMPEG="/usr/lib/jellyfin-ffmpeg/ffmpeg"
    
    if [ ! -f "$FFMPEG" ]; then
        echo "Error: Cannot find ffmpeg: $FFMPEG"
        return 1
    fi

    directory="$1"
    audio_track="$2"
    
    log_dir="${directory}/conversion_logs"
    mkdir -p "$log_dir"
    log_file="${log_dir}/conversion_$(date +%Y%m%d_%H%M%S).log"
    
    echo "Conversion start time: $(date)" | tee -a "$log_file"
    echo "----------------------------------------" | tee -a "$log_file"
    
    find "$directory" -type f -name "*.mkv" -print0 | while IFS= read -r -d $'\0' input_file; do
        filename="${input_file%.*}"
        mp4_file="${filename}.mp4"
        
        if [ -f "$mp4_file" ] && [ -s "$mp4_file" ]; then
            echo "Skip: $mp4_file (already exists)" | tee -a "$log_file"
            continue
        fi
        
        echo "Processing: $input_file" | tee -a "$log_file"
        
        # Improved subtitle extraction
        echo "Extracting subtitles..." | tee -a "$log_file"
        
        # Extract subtitle stream information
        $FFMPEG -i "$input_file" 2>&1 | while IFS= read -r line; do
            if [[ $line =~ Stream.*Subtitle ]]; then
                stream_index=$(echo "$line" | grep -o "#0:[0-9]*" | cut -d':' -f2)
                language=$(echo "$line" | grep -oP "^.*?\((\w{2,3})\)" | grep -oP "\((\w{2,3})\)" | tr -d '()')
                
                # Check subtitle codec type
                codec_type=$(echo "$line" | grep -oP "Subtitle: \K[^,]*")
                
                # Check subtitle type
                subtitle_type=""
                if [[ $line =~ \(forced\) ]]; then
                    subtitle_type="forced"
                elif [[ $line =~ \(hearing[[:space:]]impaired\) ]] || [[ $line =~ \(SDH\) ]]; then
                    subtitle_type="sdh"
                elif [[ $line =~ \(dub\) ]]; then
                    subtitle_type="dub"
                fi
                
                # Set output file extension
                case $codec_type in
                    "subrip") ext="srt" ;;
                    "ass" | "ssa") ext="ass" ;;
                    "hdmv_pgs_subtitle") ext="sup" ;;
                    "dvd_subtitle") ext="sub" ;;
                    *) ext="srt" ;; # Default is srt
                esac
                
                # Generate output filename
                if [ ! -z "$subtitle_type" ]; then
                    output_subtitle="${filename}.${language}.${subtitle_type}.${ext}"
                else
                    output_subtitle="${filename}.${language}.${ext}"
                fi
                
                if [ -f "$output_subtitle" ] && [ -s "$output_subtitle" ]; then
                    echo "Skip: $output_subtitle (already exists)" | tee -a "$log_file"
                    continue
                fi
                
                echo "Extracting subtitle: $output_subtitle (codec: $codec_type)" | tee -a "$log_file"
                
                # Use copy codec for ASS/SSA, PGS(SUP) subtitles
                if [ "$codec_type" = "hdmv_pgs_subtitle" ] || [ "$codec_type" = "ass" ] || [ "$codec_type" = "ssa" ]; then
                    $FFMPEG -nostdin -i "$input_file" -map 0:${stream_index} -c:s copy \
                        -y "$output_subtitle" 2>> "$log_file" || {
                        echo "Error: Failed to extract subtitle - $output_subtitle" | tee -a "$log_file"
                        rm -f "$output_subtitle"
                    }
                # Convert to srt for other cases
                else
                    $FFMPEG -nostdin -i "$input_file" -map 0:${stream_index} -c:s srt \
                        -y "$output_subtitle" 2>> "$log_file" || {
                        echo "Error: Failed to extract subtitle - $output_subtitle" | tee -a "$log_file"
                        rm -f "$output_subtitle"
                    }
                fi
            fi
        done
        
        # MP4 Conversion
        echo "Converting to MP4..." | tee -a "$log_file"
        
        # Audio track settings
        audio_options=""
        if [ ! -z "$audio_track" ]; then
            audio_count=$($FFMPEG -i "$input_file" 2>&1 | grep -c "Stream.*Audio")
            if [ "$audio_track" -lt "$audio_count" ]; then
                for ((i=0; i<audio_count; i++)); do
                    if [ "$i" -ne "$audio_track" ]; then
                        audio_options="$audio_options -disposition:a:$i 0"
                    fi
                done
                audio_options="$audio_options -disposition:a:$audio_track default"
            else
                echo "Error: Invalid audio track number. (Available tracks: 0-$((audio_count-1)))" | tee -a "$log_file"
                return 1
            fi
        fi
        
        # Execute MP4 conversion
        $FFMPEG -nostdin -i "$input_file" -map 0:v -map 0:a -c copy \
            -tag:v hvc1 \
            -movflags +faststart+use_metadata_tags+write_colr \
            -write_tmcd 0 \
            -strict -2 \
            $audio_options \
            -y "$mp4_file" 2>> "$log_file" || {
            echo "Error: MP4 conversion failed - $mp4_file" | tee -a "$log_file"
            rm -f "$mp4_file"
        }
        
        echo "----------------------------------------" | tee -a "$log_file"
    done
    
    echo "Conversion end time: $(date)" | tee -a "$log_file"
}

mkv2mp4 "$1" "$2"

@xavier8706
Copy link

xavier8706 commented Nov 13, 2024

AI-generated script. It has been tested for basic behavior, but has not yet been tested in many environments. Use with caution.

#!/bin/bash

mkv2mp4() {
if [ -z "$1" ]; then
echo "Usage: mkv2mp4 <directory_path> [default audio track number (starts from 0)]"
echo "Use only for HEVC videos that support Dolby Vision."
return 1
fi

......
mkv2mp4 "$1" "$2"

I am currently using this script and accoring to few testing on my LG C2 (which is having the issue) after conversion to mp4 it works.

I was wondering if there would be any way to automate this conversion using tdarr tool ? (as a kind of automated workaround)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants