Rafostar / gnome-shell-extension-cast-to-tv

Cast files to Chromecast, web browser or media player app over local network.
GNU General Public License v2.0
292 stars 17 forks source link

Transcoding not working with non English subtitles #104

Closed hedwigz closed 4 years ago

hedwigz commented 4 years ago

First and foremost, this extension is awesome, I really appreciate your work.

I have a movie file and an Hebrew .srt file.
I mark both files in nautilus and then choose to transcode video+audio (otherwise there's no sound).
The casting doesn't work with an ffmpeg error.
I did some research myself and looks like adding charenc to the subtitles filter may solve the issue.
I manually added the following code just to test:

function getSubsPath()
{
    var subsPathEscaped = (bridge.selection.subsPath) ? bridge.selection.subsPath : bridge.selection.filePath;
    var index = subsPathEscaped.length;

    while(index--)
    {
        if(shared.escapeChars.includes(subsPathEscaped.charAt(index)))
            subsPathEscaped = subsPathEscaped.replaceAt(index, '\\' + subsPathEscaped.charAt(index));
    }

    return subsPathEscaped+':charenc=-sub_charenc:ISO-8859-8';
}

The above worked and the cast didn't crash.
However, for some reason now there are double subtitles on the video!!
It's like one is from the burning of the subtitles and the second is the chromecast parsing the subtitles from the MKV file? I am not sure.

CPU: i7-7700HQ GPU: Intel UHD Graphics 630

The following is the log without any code changes

➜  node_scripts DEBUG=bridge,ffmpeg node server
  bridge New playlist contents: ["/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO.mkv"] +0ms
  bridge New selection contents: {"streamType":"VIDEO_ENCODE","transcodeAudio":true,"subsPath":"/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO-heb.srt","filePath":"/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO.mkv"} +50ms
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, matroska,webm, from '/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO.mkv':
  Metadata:
    encoder         : libebml v1.3.0 + libmatroska v1.4.1
    creation_time   : 2020-01-27T15:09:41.000000Z
  Duration: 02:32:33.47, start: 0.000000, bitrate: 4928 kb/s
    Chapter #0:0: start 0.000000, end 284.617000
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 284.617000, end 451.533000
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 451.533000, end 601.807000
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 601.807000, end 938.309000
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 938.309000, end 1214.167000
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 1214.167000, end 1298.792000
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 1298.792000, end 1559.886000
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 1559.886000, end 1916.867000
    Metadata:
      title           : Chapter 08
    Chapter #0:8: start 1916.867000, end 2048.748000
    Metadata:
      title           : Chapter 09
    Chapter #0:9: start 2048.748000, end 2352.258000
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 2352.258000, end 2525.888000
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 2525.888000, end 2755.993000
    Metadata:
      title           : Chapter 12
    Chapter #0:12: start 2755.993000, end 2917.654000
    Metadata:
      title           : Chapter 13
    Chapter #0:13: start 2917.654000, end 3081.067000
    Metadata:
      title           : Chapter 14
    Chapter #0:14: start 3081.067000, end 3302.663000
    Metadata:
      title           : Chapter 15
    Chapter #0:15: start 3302.663000, end 3469.788000
    Metadata:
      title           : Chapter 16
    Chapter #0:16: start 3469.788000, end 3626.027000
    Metadata:
      title           : Chapter 17
    Chapter #0:17: start 3626.027000, end 3992.476000
    Metadata:
      title           : Chapter 18
    Chapter #0:18: start 3992.476000, end 4318.802000
    Metadata:
      title           : Chapter 19
    Chapter #0:19: start 4318.802000, end 4572.764000
    Metadata:
      title           : Chapter 20
    Chapter #0:20: start 4572.764000, end 4769.502000
    Metadata:
      title           : Chapter 21
    Chapter #0:21: start 4769.502000, end 5057.748000
    Metadata:
      title           : Chapter 22
    Chapter #0:22: start 5057.748000, end 5363.969000
    Metadata:
      title           : Chapter 23
    Chapter #0:23: start 5363.969000, end 5595.158000
    Metadata:
      title           : Chapter 24
    Chapter #0:24: start 5595.158000, end 5890.285000
    Metadata:
      title           : Chapter 25
    Chapter #0:25: start 5890.285000, end 6056.451000
    Metadata:
      title           : Chapter 26
    Chapter #0:26: start 6056.451000, end 6202.305000
    Metadata:
      title           : Chapter 27
    Chapter #0:27: start 6202.305000, end 6348.200000
    Metadata:
      title           : Chapter 28
    Chapter #0:28: start 6348.200000, end 6637.947000
    Metadata:
      title           : Chapter 29
    Chapter #0:29: start 6637.947000, end 6817.333000
    Metadata:
      title           : Chapter 30
    Chapter #0:30: start 6817.333000, end 7066.581000
    Metadata:
      title           : Chapter 31
    Chapter #0:31: start 7066.581000, end 7215.645000
    Metadata:
      title           : Chapter 32
    Chapter #0:32: start 7215.645000, end 7521.866000
    Metadata:
      title           : Chapter 33
    Chapter #0:33: start 7521.866000, end 7757.350000
    Metadata:
      title           : Chapter 34
    Chapter #0:34: start 7757.350000, end 7920.471000
    Metadata:
      title           : Chapter 35
    Chapter #0:35: start 7920.471000, end 8125.383000
    Metadata:
      title           : Chapter 36
    Chapter #0:36: start 8125.383000, end 8302.101000
    Metadata:
      title           : Chapter 37
    Chapter #0:37: start 8302.101000, end 8445.409000
    Metadata:
      title           : Chapter 38
    Chapter #0:38: start 8445.409000, end 8786.582000
    Metadata:
      title           : Chapter 39
    Chapter #0:39: start 8786.582000, end 9153.472000
    Metadata:
      title           : Chapter 40
    Stream #0:0(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
    Stream #0:1(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x804 [SAR 1:1 DAR 160:67], 23.98 fps, 23.98 tbr, 1k tbn, 2k tbc (default)
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (ac3 (native) -> flac (native))
Press [q] to stop, [?] for help
[flac @ 0x561f99908740] encoding as 24 bits-per-sample
[Parsed_subtitles_0 @ 0x561f99f7de60] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.7.2 (COMPLEX)
[Parsed_subtitles_0 @ 0x561f99f7de60] Using font provider fontconfig
[srt @ 0x561f9a391640] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x561f99f7de60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x561f9a391640] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x561f99f7de60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x561f9a391640] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
...
[Parsed_subtitles_0 @ 0x561f99f7de60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x561f9a391640] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x561f99f7de60] Error decoding: Invalid data found when processing input (ignored)
[AVFilterGraph @ 0x561f99f7c600] Error initializing filter 'subtitles' with args '/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO-heb.srt'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid data found when processing input
Error while processing the decoded data for stream #0:1
Conversion failed!
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, matroska,webm, from '/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO.mkv':
  Metadata:
    encoder         : libebml v1.3.0 + libmatroska v1.4.1
    creation_time   : 2020-01-27T15:09:41.000000Z
  Duration: 02:32:33.47, start: 0.000000, bitrate: 4928 kb/s
    Chapter #0:0: start 0.000000, end 284.617000
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 284.617000, end 451.533000
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 451.533000, end 601.807000
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 601.807000, end 938.309000
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 938.309000, end 1214.167000
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 1214.167000, end 1298.792000
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 1298.792000, end 1559.886000
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 1559.886000, end 1916.867000
    Metadata:
      title           : Chapter 08
    Chapter #0:8: start 1916.867000, end 2048.748000
    Metadata:
      title           : Chapter 09
    Chapter #0:9: start 2048.748000, end 2352.258000
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 2352.258000, end 2525.888000
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 2525.888000, end 2755.993000
    Metadata:
      title           : Chapter 12
    Chapter #0:12: start 2755.993000, end 2917.654000
    Metadata:
      title           : Chapter 13
    Chapter #0:13: start 2917.654000, end 3081.067000
    Metadata:
      title           : Chapter 14
    Chapter #0:14: start 3081.067000, end 3302.663000
    Metadata:
      title           : Chapter 15
    Chapter #0:15: start 3302.663000, end 3469.788000
    Metadata:
      title           : Chapter 16
    Chapter #0:16: start 3469.788000, end 3626.027000
    Metadata:
      title           : Chapter 17
    Chapter #0:17: start 3626.027000, end 3992.476000
    Metadata:
      title           : Chapter 18
    Chapter #0:18: start 3992.476000, end 4318.802000
    Metadata:
      title           : Chapter 19
    Chapter #0:19: start 4318.802000, end 4572.764000
    Metadata:
      title           : Chapter 20
    Chapter #0:20: start 4572.764000, end 4769.502000
    Metadata:
      title           : Chapter 21
    Chapter #0:21: start 4769.502000, end 5057.748000
    Metadata:
      title           : Chapter 22
    Chapter #0:22: start 5057.748000, end 5363.969000
    Metadata:
      title           : Chapter 23
    Chapter #0:23: start 5363.969000, end 5595.158000
    Metadata:
      title           : Chapter 24
    Chapter #0:24: start 5595.158000, end 5890.285000
    Metadata:
      title           : Chapter 25
    Chapter #0:25: start 5890.285000, end 6056.451000
    Metadata:
      title           : Chapter 26
    Chapter #0:26: start 6056.451000, end 6202.305000
    Metadata:
      title           : Chapter 27
    Chapter #0:27: start 6202.305000, end 6348.200000
    Metadata:
      title           : Chapter 28
    Chapter #0:28: start 6348.200000, end 6637.947000
    Metadata:
      title           : Chapter 29
    Chapter #0:29: start 6637.947000, end 6817.333000
    Metadata:
      title           : Chapter 30
    Chapter #0:30: start 6817.333000, end 7066.581000
    Metadata:
      title           : Chapter 31
    Chapter #0:31: start 7066.581000, end 7215.645000
    Metadata:
      title           : Chapter 32
    Chapter #0:32: start 7215.645000, end 7521.866000
    Metadata:
      title           : Chapter 33
    Chapter #0:33: start 7521.866000, end 7757.350000
    Metadata:
      title           : Chapter 34
    Chapter #0:34: start 7757.350000, end 7920.471000
    Metadata:
      title           : Chapter 35
    Chapter #0:35: start 7920.471000, end 8125.383000
    Metadata:
      title           : Chapter 36
    Chapter #0:36: start 8125.383000, end 8302.101000
    Metadata:
      title           : Chapter 37
    Chapter #0:37: start 8302.101000, end 8445.409000
    Metadata:
      title           : Chapter 38
    Chapter #0:38: start 8445.409000, end 8786.582000
    Metadata:
      title           : Chapter 39
    Chapter #0:39: start 8786.582000, end 9153.472000
    Metadata:
      title           : Chapter 40
    Stream #0:0(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
    Stream #0:1(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x804 [SAR 1:1 DAR 160:67], 23.98 fps, 23.98 tbr, 1k tbn, 2k tbc (default)
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (ac3 (native) -> flac (native))
Press [q] to stop, [?] for help
[flac @ 0x55c7153ca740] encoding as 24 bits-per-sample
[Parsed_subtitles_0 @ 0x55c715a3fe60] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.7.2 (COMPLEX)
[Parsed_subtitles_0 @ 0x55c715a3fe60] Using font provider fontconfig
[srt @ 0x55c715e53980] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x55c715e53980] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x55c715e53980] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x55c715e53980] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
...
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
[srt @ 0x55c715e53980] Invalid UTF-8 in decoded subtitles text; maybe missing -sub_charenc option
[Parsed_subtitles_0 @ 0x55c715a3fe60] Error decoding: Invalid data found when processing input (ignored)
[AVFilterGraph @ 0x55c715a3e600] Error initializing filter 'subtitles' with args '/home/amit/Downloads/ford_v_ferrari/Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO-heb.srt'
Error reinitializing filters!                                                                            
Failed to inject frame into filter network: Invalid data found when processing input
Error while processing the decoded data for stream #0:1
Exiting normally, received signal 2.
Rafostar commented 4 years ago

Hi, Thanks for your report. I need to add automatic character detection to the transcoding. It currently defaults to 'UTF-8'. For now you should be safe if you manage to convert subtitles to the 'UTF-8' file prior to casting using some external tool e.g. ffmpeg and then cast with those subs.

ffmpeg -sub_charenc "ISO-8859-8" -i "Ford.v.Ferrari.2019.1080p.WEB-DL.H264.AC3-EVO-heb.srt" subtitles.srt

If this will not work for you there are also other tools to convert to UTF-8. I will try to add auto subs detection in the near future.

hedwigz commented 4 years ago

This works, thanks :)
Actually the better encoding was WINDOWS-1255 (the ISO failed to decode some lines - just if anyone else gets here)
Now there's a different problem though:
The subtitles are duplicated
BTW: I also cannot move forward or backwards when using transcode - I remember I could with other movies. Why is that?

Rafostar commented 4 years ago

I am reworking the subtitles extraction code along with communication between GJS (gnome) and nodejs on git devel branch. It is currently half broken so I do not recommend using this yet.

I will let you know once I finish and merge it to master.

BTW: I also cannot move forward or backwards when using transcode - I remember I could with other movies. Why is that?

We cannot transcode file in seekable parts on the fly. ffmpeg transcodes and sends output to your receiver from start to finish, so seeking is not possible. We are not saving the output to the hard drive, but keep it inside RAM (to not wear your drive without good reason) and send it to Chromecast from there. The send data is removed from RAM to free it, so we cannot move backwards either. Unless you have a "Chromecast Ultra" you will not be able to play 5.1 audio movies without transcoding. If you want seeking then recommended solution would be either transcoding the movie prior to casting by yourself or to always try to find and use videos with stereo sound.

hedwigz commented 4 years ago

I see.
Any other solution you can recommend to stream movies from my laptop to my Shield TV? (not necessarily Chromecast)

Rafostar commented 4 years ago

@amits1995

Any other solution you can recommend to stream movies from my laptop to my Shield TV? (not necessarily Chromecast)

This extension is my little project I made to be able to easily cast files to my Chromecast and to Raspberry Pi with single right click from Nautilus file manager. I do not have an Android smart TV (or Shield), but if you want to be able to access your movies library from it, then setting up a SFTP file server on your laptop and installing KODI on your shield might be a solution that would not require transcoding.

Rafostar commented 4 years ago

OK. I updated the subtitles character detection node module. Hopefully this one will better detect subtitles language. The extraction code was redone from scratch, and the "doubled subtitles" problem should now be eliminated too.

There is now also added option to convert only audio (copy video) that will be useful for movies that have only incompatible audio track and an option to not burn subtitles during video transcode (lower cpu usage).

hedwigz commented 4 years ago

OK. I updated the subtitles character detection node module. Hopefully this one will better detect subtitles language. The extraction code was redone from scratch, and the "doubled subtitles" problem should now be eliminated too.

There is now also added option to convert only audio (copy video) that will be useful for movies that have only incompatible audio track and an option to not burn subtitles during video transcode (lower cpu usage).

Awesome!

SharonHart commented 4 years ago

Hi, @amits1995 your subtitles punctuation appears normally? For me, it's as if it's for a 'left to right' language. f.e: שלום. instead of .שלום Works fine with a standard video player.

Rafostar commented 4 years ago

@SharonHart This seems similar to common issue described here: https://stackoverflow.com/questions/44504944/converting-from-windows-1256-to-utf-8-causes-punctuation-issue/44656643

Usually this is caused by badly made subtitles file. Check if you always have the same problem with different subtitles from different sources.

SharonHart commented 4 years ago

@Rafostar Will try that, although with VLC it works fine. Maybe it was during the process of me adding the art file as a subtitles track to the mkv file. This app is a lifesaver by the way, thanks!