Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Last active September 8, 2024 14:09
Show Gist options
  • Save mttjohnson/31e9fe018c39bde826ae543bcd0007a7 to your computer and use it in GitHub Desktop.
Save mttjohnson/31e9fe018c39bde826ae543bcd0007a7 to your computer and use it in GitHub Desktop.
Add English subtitles to videos with Turkish language audio

Dependencies

Install the following dependencies

brew install pipenv
brew install ffmpeg
pipenv install --python 3.10

Instructions

Activate a pipenv shell and make sure the following python packages are installed

pipenv shell --python 3.10
pip3 install ffmpeg-python
pip3 install git+https://github.com/openai/whisper.git 

Setup input/output directories

mkdir -p input
mkdir -p output

Move files you want to process to a directory called "input"

Run the script

./vprocess.sh

Run Time Expectations

I ran this on a 15 minute video file and it took about 2 hours to process.

Special Thanks

To Alex for figuring all this out in the first place and writing the script

#!/bin/zsh
set -xe
language=Turkish
model_size=large
filenamefunc () {
for file in input/*; do
echo "$(date) ---------- starting whisper ----------"
whisper --model $model_size "$file" --language $language --task translate --fp16 False
echo "$(date) ---------- starting ffmpeg ----------"
ffmpeg -i "$file" -vf subtitles="$(basename "$file")".srt output/"$(basename "$file" .mp4)"_engsub.mp4
done
}
cleanup () {
for file in input/*; do
rm -rf "$(basename "$file")".srt
rm -rf "$(basename "$file")".vtt
rm -rf "$(basename "$file")".txt
rm -rf "$(basename "$file")".json
rm -rf "$(basename "$file")".tsv
done
}
echo "$(date) ---------- starting filenamefunc ----------"
filenamefunc
echo "$(date) ---------- starting cleanup ----------"
cleanup
echo "$(date) ---------- finished ----------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment