Created
May 31, 2018 15:49
-
-
Save optyler/cf56cb228be1d696128543e12a0a79b8 to your computer and use it in GitHub Desktop.
merge subtitles and mp4 into mkv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DEPENDENCIES | |
hash ffmpeg 2>/dev/null || { echo >&2 "ffmpeg required but it's not installed. Aborting."; exit 1; } | |
# CHECK INPUT FILES | |
if [ -z "$1" ]; then echo "No argument supplied, please add the movie path as first argument"; exit 2; fi | |
input=$1 | |
filename=$(basename "$input") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
output=$filename"_VOSTFR."$extension | |
srt_file="" | |
if [ -f "$filename.srt" ]; then | |
srt_file="$filename.srt" | |
else | |
if [ -f "$filename.$extension.srt" ]; then | |
srt_file="$filename.$extension.srt" | |
else | |
echo "No french sub file found, should be \"$filename.srt\" or \"$filename.$extension.srt\"" | |
exit 3; | |
fi | |
fi | |
encoding=`file -I "$srt_file" | cut -f 2 -d";" | cut -f 2 -d=` | |
if [[ $encoding == "unknown-"* ]] | |
then | |
echo "Charset of srt file not known, trying iso-8859-1"; | |
encoding="iso-8859-1" | |
fi | |
if [ "$extension" = "mkv" ]; then | |
echo "mkv file" | |
ffmpeg -i "$input" -sub_charenc $encoding -f srt -i "$srt_file" -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt "$output" | |
else | |
echo "other file" | |
ffmpeg -i "$input" -sub_charenc $encoding -f srt -i "$srt_file" -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=fre "$output" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment