User Tools

Site Tools


howto:subtitles

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howto:subtitles [2025/02/01 23:09] Wulf Rajekhowto:subtitles [2025/07/26 18:41] (current) Wulf Rajek
Line 39: Line 39:
 or or
 Parameter:  {“action”:“subtitledelayplus”} Parameter:  {“action”:“subtitledelayplus”}
 +
 +
 +===== Extract subtitles =====
 +Extract subtitle with specific metadata title:
 +<code>
 +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
 +</code>
 +
 +===== 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:
 +<code>
 +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
 +</code>
 +
 +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:
 +<code>
 +mkvmerge -i videofile.mkv
 +</code>
 +The output will look something like this:
 +<code>
 +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
 +</code>
 +
 +For more detailed information the mkvinfo command can be used:
 +<code>
 +mkvinfo videofile.mkv
 +</code>
 +
 +To create a new mkv file with the subtitles removed and only keeping the second audio stream, use the following command:
 +<code>
 +mkvmerge -o newvideofile.mkv -a 4 -s 0 videofile.mkv
 +</code>
 +
 +To extract tracks from an mkv file, use the mkvextract command using the IDs obtained from mkvinfo:
 +<code>
 +mkvextract tracks videofile.mkv 2:subtitletrack2.srt 3:subtitletrack3.srt
 +</code>
 +
howto/subtitles.1738451378.txt.gz · Last modified: by Wulf Rajek