Skip to content

Instantly share code, notes, and snippets.

@nimahkh
Last active October 26, 2023 22:40
Show Gist options
  • Save nimahkh/36c0dac31d9cb5363cf356095014524f to your computer and use it in GitHub Desktop.
Save nimahkh/36c0dac31d9cb5363cf356095014524f to your computer and use it in GitHub Desktop.
add srt subtitle into mkv video with FFMPEG- put all off your mkv and srt files with same names ina folder and run sh command. all of the converted files will be in the added folder inside the current folder.
#!/bin/bash
#author: [email protected]
#ffmpeg command from : https://gist.github.com/kurlov/32cbe841ea9d2b299e15297e54ae8971
NOCOLOR='\033[0m';
RED='\033[0;31m';
GREEN='\033[0;32m';
[ -d added ] || mkdir added
addToMKV(){
for i in ./*.mkv
do
if [ -f "added/${i%.*}-added-subtitle.mkv" ]; then
echo -e "${RED}${i%.*}-added-subtitle.mkv Exists in added directory${NOCOLOR}"
else
ffmpeg -hide_banner -loglevel panic -i "$i" -sub_charenc 'UTF-8' -f srt -i "${i%.*}.srt" -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt "added/${i%.*}-added-subtitle.mkv";
echo -e "${GREEN}${1} converted successfully ${i%.*}-with-subtitle.mkv${NOCOLOR}";
fi
done
}
echo -e "Converting is starting:";
addToMKV
@sureshharan7
Copy link

sureshharan7 commented May 24, 2020

How to use this. I couldnt understand this. If u have any youtube channel please upload a video about this. Or else please give a step by step procedure of how to use this

@Bosturk
Copy link

Bosturk commented May 28, 2020

How to use this. I couldnt understand this. If u have any youtube channel please upload a video about this. Or else please give a step by step procedure of how to use this

This is made for linux, but you can run it using wsl on windows (https://www.windowscentral.com/install-windows-subsystem-linux-windows-10).

@sureshharan7
Copy link

sureshharan7 commented May 31, 2020 via email

@hurelhuyag
Copy link

Thank you very much. Now I can watch movies in my tv with subtitles.

@Foxtrod89
Copy link

works like magic pot, for some video you would probably need to map another audio channel which is -map 0:1

@marcusmuller
Copy link

How to use this. I couldnt understand this. If u have any youtube channel please upload a video about this. Or else please give a step by step procedure of how to use this

This is made for linux, but you can run it using wsl on windows (https://www.windowscentral.com/install-windows-subsystem-linux-windows-10).

I made a version for windows.

copy the code to notepad and save as "add_sub.bat"
then execute.

https://pastebin.com/44N4ZkM0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment