chorus2 icon indicating copy to clipboard operation
chorus2 copied to clipboard

Subtitles in the HTML5 player

Open NerosTie opened this issue 8 years ago • 17 comments

Is it possible for the HTML5 player to read the subtitles in the same folder of the movie? Same question for a subtitle inside a .mkv file.

Thanks!

NerosTie avatar Dec 19 '16 23:12 NerosTie

This would not be easy, We'll need to wait for the Kodi API to support it and even then, there will likely be issues due to web players using WebVTT rather than SRT. Ideally we would want transcoding and the subtitles burned into the video before streaming.

So it will likely be a long wait for this feature.

jez500 avatar Dec 20 '16 07:12 jez500

No sound (with AC3 and DTS) and no subtitles, it will be, indeed, a long wait! A little bit sad because the video in the html5 player is very good in Chorus2! Also, I think the vlc webplayer and the xvid webplayer options are obsoletes.

NerosTie avatar Dec 20 '16 14:12 NerosTie

Absolutely signed. html5 player is a awsome feature but has no sound for 90% of the videos.

ghost avatar Jan 06 '17 18:01 ghost

@derdigge - No sound is because of AC3 and DTS codecs, which chrome have flagged as Wont fix https://bugs.chromium.org/p/chromium/issues/detail?id=243861

Support Kodi transcoding!

jez500 avatar Jan 08 '17 01:01 jez500

@derdigge I don't understand why they don't implement the codecs. If VLC and Kodi can, why not chrome/chromium? By the way, can it works with Firefox?

NerosTie avatar Jan 08 '17 05:01 NerosTie

In my case, the subtitles are embedded in the video themselves, not external files. I believe there are JavaScript based HTML5 video players that can show these. Perhaps the player in Chorus can be replaced with one of these?

petterreinholdtsen avatar Apr 14 '20 07:04 petterreinholdtsen

Usually, external subtitles are used to avoid irreversible changes to the video ontology. It will be very complicated to decode video in browser with JavaScript. I think the best solution is to transcode the video in Kodi software and directly transmit the standard video stream to the browser for playback.

bzp2010 avatar Apr 14 '20 08:04 bzp2010

The Chromium mechanism described in https://jitsi.org/news/e2ee/ ie thes Insertable Streams, allowing javascript to hook into the video while it is being decoded and displayed, might perhaps help? Or perhaps it only apply to WebRTC?

petterreinholdtsen avatar Apr 14 '20 08:04 petterreinholdtsen

I think it's probably a video decoder running in JavaScript. WebRTC is only used to transmit the encoded video stream. If you want to realize the subtitle of the web page, you should use JavaScript to decode and render the subtitle file, such as srt or ass, instead of changing it in the video stream.

bzp2010 avatar Apr 15 '20 10:04 bzp2010

Hi, any updates regarding the possibility of this? Seems like such a shame this issue has gone stale...

YoyoBesser avatar Feb 13 '21 18:02 YoyoBesser

I used this method to solve this problem I will talk about windows but it should be same on another OS

edit this file ‪C:\Program Files\Kodi\addons\webinterface.default\videoPlayer.html and add these lines on html5 if condition

                $player.append($('<track>', {
                    "kind": "captions",
                    "src": subtitle,
                    "srclang": "Farsi",
                    "default": "true"
                }));

so it would be :

            if(player == 'html5'){
                $player = $('<video>', {
                    "id": id,
                    "class": "video-js vjs-default-skin",
                    "controls": "controls",
                    "preload": "auto",
                    "autoplay": "autoplay",
                    "data-setup": JSON.stringify({}),
                    "poster": getBaseURL() + bg
                });
                $player.append($('<source>', {
                    "type": 'video/mp4',
                    "src": getBaseURL() + src
                }));

                $player.append($('<track>', {
                    "kind": "captions",
                    "src": subtitle,
                    "srclang": "Farsi",
                    "default": "true"
                }));

                $player.attr('width', width).attr('height', height);
            }

in "src" variable we have current playing file path, convert your srt sutitle file to vtt and save with same name of your video file on video file directory

so we should have vtt file path like this var subtitle = getBaseURL() + src.replace(".mkv", ".vtt").replace(".avi", ".vtt").replace(".mp4", ".vtt")

it should be work . its a temproray fix the CC icon should be appear at the right bottom side of the page

P4R54 avatar Feb 19 '21 20:02 P4R54

Awesome, thanks for answering!

YoyoBesser avatar Feb 19 '21 23:02 YoyoBesser

I've looking for this! Thanks. I paste those lines

$player.append($('', { "kind": "captions", "src": getBaseURL() + src.replace(".mkv", ".vtt").replace(".avi", ".vtt").replace(".mp4", ".vtt"), "srclang": "Español", "default": "true" }));

but when I open the browser. The CC option appears but no subtitle. Converted to vtt and renamed it with the same video file name.

neroxyr avatar Jun 18 '21 00:06 neroxyr

its working for me. manually check if your vtt file is accessible from browser and also check your video file extension because i've only added mkv, avi and mp4 to this code

P4R54 avatar Jun 19 '21 06:06 P4R54

What about reading the subtitles from the mkv file? All my movies have the subtitles included in the video file.

-- Happy hacking Petter Reinholdtsen

petterreinholdtsen avatar Jun 19 '21 07:06 petterreinholdtsen

What about reading the subtitles from the mkv file? All my movies have the subtitles included in the video file. -- Happy hacking Petter Reinholdtsen

dont have any idea, as i know if html5 player support this feature we can add to kodi

P4R54 avatar Jun 19 '21 07:06 P4R54

Hi.

You can convert srt file on the fly by adding these functions:

    function getVTT(link, callB) {
            var client = new XMLHttpRequest();
            client.open('GET', link);
            client.onreadystatechange = function() {
                    if(client.readyState === XMLHttpRequest.DONE && client.status === 200) {
                            var blobVTT = convertSRT(client.responseText)
                            callB(blobVTT);
                    }
            }
            client.send();
    }

    function convertSRT(content) {
            content = content.replace(/(\d+:\d+:\d+)+,(\d+)/g, '$1.$2');
            content = "WEBVTT\r\n\r\n" + content;
            var blob = new Blob([content], {type: 'text/vtt'});
            return window.URL.createObjectURL(blob);
    }

Then, on the HTML5 part of the code would become:

        // Make the html5 player
        if(player == 'html5'){
            $player = $('<video>', {
                "id": id,
                "class": "video-js vjs-default-skin",
                "controls": "controls",
                "preload": "auto",
                "autoplay": "autoplay",
                "data-setup": JSON.stringify({}),
                "poster": getBaseURL() + bg,
            });
            $player.append($('<source>', {
                "type": 'video/mp4',
                "src": getBaseURL() + src
            }));
            var subtitleLink = (getBaseURL() + src).slice(0, -3) + "srt"; // Subtitle with same name as video on the same folder
            getVTT(subtitleLink, function(blobVTT){
                    var vid = videojs(id);
                    vid.addRemoteTextTrack({
                            "kind": 'subtitle',
                            "src": blobVTT,
                            "srclang": 'en_US',
                            "label": 'MyLabel',
                            "default": 'true',
                    }, false);
                    var tracks = vid.remoteTextTracks();
                    // Replace with for loop if more than one subtitle added
                    tracks[0].mode = 'showing';
            });
            $player.attr('width', width).attr('height', height);
        }

RubenTeixeira avatar Oct 12 '21 09:10 RubenTeixeira