====== Subtitles ======
===== Auto Synchronisation =====
The following python tool can be used to let it analyse the audio and subtitle and synchronise the subs to generate a new synced file. It works for offsets at the beginning, not for sync issues later in the file.
https://github.com/smacke/ffsubsync
Install on Linux Mint 22+:
pipx install git+https://github.com/smacke/ffsubsync@latest
Usage:
ffs video_file.mkv -i orig_sub.srt -o new_synced_sub.srt
===== Alternatives =====
Untested alternative without limitations:
https://github.com/kaegi/alass
Other alternative:
https://snapcraft.io/subsync
https://sc0ty.pl/
https://subsync.online/
https://github.com/sc0ty/subsync?tab=readme-ov-file
https://github.com/denizsafak/AutoSubSync
===== Yatse kodi offset =====
JSON-RPC
Method: Input.ExecuteAction
Parameter: {“action”:“subtitledelayminus”}
or
Parameter: {“action”:“subtitledelayplus”}
===== Extract subtitles =====
Extract subtitle with specific metadata title:
for f in *.mkv; do ffmpeg -hide_banner -i "$f" -c copy -map 0:s:m:title:"English [ForcedNarrative]" "${f%.*}.en.forced.srt"; done
for f in *.mkv; do ffmpeg -hide_banner -i "$f" -c copy -map 0:s:m:title:"angličtina" "${f%.*}.en.srt"; done
#extract 2 at once
for f in *.mkv; do ffmpeg -hide_banner -i "$f" -c copy -map 0:s:m:title:"English [ForcedNarrative]" "${f%.*}.en.forced.srt" -c copy -map 0:s:m:title:"angličtina" "${f%.*}.en.srt"; done
===== Set subtitle to forced =====
This copies the video and audio stream of an mp4 file, sets the first mov_text subtitle stream to 'forced' and the second to normal:
ffmpeg -i input.mp4 -vcodec copy -acodec copy -map 0:v:0 -map 0:a:0 -map 0:s:0 -c:s mov_text -disposition:s:0 forced -map 0:s:1 -disposition:s:1 0 output.mp4
For mkv files, this probably needs to be srt instead of mov_text.
===== Remove subtitles from mkv files =====
First, identify the track ids contained in the mkv file:
mkvmerge -i videofile.mkv
The output will look something like this:
kax i am at 6718
File 'videofile.mkv': container: Matroska
Track ID 0: audio (AC3/EAC3)
Track ID 1: subtitles (SubRip/SRT)
Track ID 2: subtitles (SubRip/SRT)
Track ID 3: video (MPEG-4p10/AVC/h.264)
Track ID 4: audio (DTS)
Chapters: 17 entries
Tags for track ID 0: 7 entries
Tags for track ID 1: 7 entries
Tags for track ID 2: 7 entries
Tags for track ID 3: 7 entries
Tags for track ID 4: 7 entries
For more detailed information the mkvinfo command can be used:
mkvinfo videofile.mkv
To create a new mkv file with the subtitles removed and only keeping the second audio stream, use the following command:
mkvmerge -o newvideofile.mkv -a 4 -s 0 videofile.mkv
To extract tracks from an mkv file, use the mkvextract command using the IDs obtained from mkvinfo:
mkvextract tracks videofile.mkv 2:subtitletrack2.srt 3:subtitletrack3.srt