Kodi Community Forum

Full Version: Extract subtitles from mkv/mp4 containers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any way to extract subtitles from mkv or mp4 containers by add-on using only Kodi resources?
The naive way would be to use mkvextract, but it is not available in Kodi. Also ffmpeg has this ability, but it is statically linked in the Kodi and not available to the add-on - unless there is some API I'm not aware about.
It may be possible if someone develops a VFS addon for MKV container which will then give access to the individual streams (video, audio, subs, chapters).
VFS addons are binary addons so needs expert devs
(2019-04-10, 18:14)bkiziuk Wrote: [ -> ]The naive way would be to use mkvextract

Naive? Meh. Just create a batch/bash file (whichever your OS is) for mkvextract to make the whole process simple, and extract the subtitle file into the same folder of the video. Works for me.
(2019-04-11, 12:50)Klojum Wrote: [ -> ]Naive? Meh. Just create a batch/bash file (whichever your OS is) for mkvextract to make the whole process simple, and extract the subtitle file into the same folder of the video. Works for me.

Yea, if I wanted to do it on a single machine, that would be a good course of action. Unfortunately, I want to implement it in a python plugin which in turn can be installed on any box under Kodi. Therefore, it doesn't make much sense to hack every device to include mkvextract.
Of course the mkvextract could solve my problem if it was already included in the Kodi installation and available for plugins Wink
If your video files collection is on a network, you don't need to install mkvextract on every (Kodi) client machine. One machine with mkvextract will be enough.
If you work with separate USB drives, then you will need to do extra file juggling, yes.
depending on what you want to support and what your target with addon (if you want to be in official repo or not), you can simply include portable version of mkvextract for both windows and linux, and run it process thry python if you want to extract subtitles while inside kodi.

python:

import subprocess
subprocess.run(["ls", "-l"])
subprocess.call(["ls", "-l"])

# or

os.system("ls -l")

That would be the start - if you not targeting official repo that the easiest way, if you do then this won't be allow.
(2019-04-15, 07:27)bigretromike Wrote: [ -> ]That would be the start - if you not targeting official repo that the easiest way, if you do then this won't be allow.

Yes, targeting official repo was my intention as well.
But aside from that, I was testing the similar solution for a while and I also hit limitations on nfs/smb shares.
If .mkv is on external share, it is not possible to access it directly from the program but instead there should be xmbcvfs implemented for it.  However I can't figure out, how to access the file via xmbcvfs and pipe into mkvinfo/mkvextract.
Doing a local copy is a rather enormous task for 2 GB file.
There are some MKV Python libraries out there that may do the job.