Skip to content

Instantly share code, notes, and snippets.

@taking
Last active March 30, 2023 02:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taking/6bf5dbe7b173aea794b6dc9b545b9302 to your computer and use it in GitHub Desktop.
Save taking/6bf5dbe7b173aea794b6dc9b545b9302 to your computer and use it in GitHub Desktop.
ffmpeg를 이용한 영상에서 한글 자막 (Korea Subtitle) 추출, 삽입, 자막 맞추기
for i in *.mp4
do
i="${i%.mp4}"
mkvmerge -o "$i.mkv" "$i.mp4" --language 0:kor --default-track 0:yes "$i.kor.srt" --language 0:eng "$i.en.srt"
mkvpropedit "$i.mkv" --edit info --set "title=$i" --set "writing-application=mkvmerge v34.0.0 ('Sign and Seen') 64-bit - TAKING" --set "muxing-application=libebml v1.3.7 + libmatroska v1.5.0"
done
for i in *.mkv
do
i="${i%.mkv}"
ffmpeg -i "$i.mkv" -map 0:m:language:kor "$i.kor.srt"
done
#!/bin/bash
# Renames subtitles files according to tv shows names found in a directory
# Acceped syntaxes for season/episode are: 304, s3e04, s03e04, 3x04 (case insensitive)
#
# Usage:
# Put this gist somewhere in your $PATH, like /usr/local/bin/subtitles-renamer
# Chmod +x it
# cd ~/YourHolidaysTvShowsWithSubtitles
# subtitles-renamer
#
# Note: zipfiles will be unzipped and .zip will be removed
#
# There are bashisms to work with regular expressions,
# so you really need bash or a shell compatible
# unzip files, maybe there are subtitles in it...
for f in *.zip; do
if [ -e "$f" ]; then
unzip "$f"
rm "$f"
fi
done
# switch into case insensitive
shopt -s nocasematch
# search subtitles
for f in *.{srt,ssa,sub} ; do
if [ -e "$f" ]; then
if [[ "$f" =~ ([0-9]+)([0-9][0-9]) || "$f" =~ s([0-9]+)e([0-9]+) || "$f" =~ ([0-9]+)x([0-9]+) ]]; then
echo "Found '$f'"
let SEASON="10#${BASH_REMATCH[1]}" # eventually delete leading 0
EPISODE=${BASH_REMATCH[2]}
# search for a matching film
for video in *.{avi,mp4,mkv} ; do
if [ -e "$video" ]; then
if [[ "$video" =~ ${SEASON}${EPISODE} || "$video" =~ s0?${SEASON}e${EPISODE} || "$movie" =~ ${SEASON}x${EPISODE} ]]; then
NEW_NAME=`echo "${video%.*}".kor.srt`
if [ "$f" = "${NEW_NAME}" ]; then
echo " Already ok"
elif [ -e "${NEW_NAME}" ]; then
echo " A file named '${NEW_NAME}' already exist, skipping"
else
mv "$f" "${NEW_NAME}"
echo " Renamed '$f' in '${NEW_NAME}'"
fi
break;
fi
fi
done
fi
fi
done
# reswitch into case sensitive
shopt -u nocasematch
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment