A simple shell script to automate the generation of subtitles for videos using Whisper AI and embed them into .mp4 files using FFmpeg.
🚀 Features:
- Automatically generates English subtitles for all
.mp4files in the directory. - Embeds the subtitles into the videos using FFmpeg.
- Converts filenames to snake-case with hyphens.
- Removes temporary files (
.srt,.tsv,.txt,.vtt,.json) after processing. - Checks for required dependencies (
python3,ffmpeg,iconv,whisper) before running.
Before running the script, make sure you have the following dependencies installed:
| Dependency | Description |
|---|---|
| Python 3 | Required for running Whisper AI |
| Whisper AI | AI model for generating subtitles |
| FFmpeg | Used to embed subtitles into the .mp4 file |
| iconv | Ensures correct encoding for subtitles |
If you don't have them installed, run the following commands:
# Install Python3 (if not installed)
sudo apt install python3 -y # Debian/Ubuntu
brew install python3 # macOS
choco install python # Windows (with Chocolatey)
# Install FFmpeg
sudo apt install ffmpeg -y # Debian/Ubuntu
brew install ffmpeg # macOS
choco install ffmpeg # Windows (with Chocolatey)
# Install iconv (already included in most Unix-based OS)
sudo apt install iconv -y # Debian/Ubuntu
# Install Whisper AI via pip
pip install openai-whisper1️⃣ Clone the repository
git clone https://github.com/yanbrasiliano/whisper-subtitle-automation.git
cd whisper-subtitle-automation2️⃣ Make the script executable
chmod +x batch_whisper_subtitles.sh3️⃣ Place your .mp4 files inside the folder
4️⃣ Run the script
./batch_whisper_subtitles.sh5️⃣ Wait for processing
- The script will automatically generate English subtitles and embed them in the video.
- The output video will have subtitles embedded and will be saved in the format:
original_file.mp4 → original-file_subtitled_en_us.mp4
6️⃣ Temporary files are automatically deleted after processing.
- The script removes all Whisper-generated files (
.srt,.tsv,.txt,.vtt,.json). - It keeps only the final
.mp4files.
In addition to the shell script, we provide a Python version that offers better performance through parallelism and asynchronous processing.
- Parallelism and Asynchronous Execution: Uses asynchronous processing to speed up performance, allowing multiple videos to be processed simultaneously.
- Flexibility: Easier to modify and extend for future improvements.
- Resource Consumption: The Python script requires more RAM and CPU power due to parallel processing.
- Additional Dependencies: Requires Python libraries like
tqdm,aiofiles, andconcurrent.futures.
1️⃣ Install the necessary dependencies:
pip install openai-whisper aiofiles tqdm2️⃣ Place your .mp4 files inside the script folder.
3️⃣ Run the Python script:
python batch_whisper_subtitles.py4️⃣ Wait for processing:
- The script will generate and embed subtitles automatically.
- The processed videos will be saved with the suffix
_subtitled_en_us.mp4.
5️⃣ Temporary Files Cleanup:
- The script automatically deletes the generated temporary files (
.srt,.tsv,.txt,.vtt,.json).
Yes! Both scripts will automatically process all .mp4 files in the directory.
The scripts will embed new AI-generated subtitles into the video.
By default, the output file is named:
original-file_subtitled_en_us.mp4.
You can modify the naming format inside the script.
Yes! Both scripts automatically delete temporary Whisper files (.srt, .tsv, .txt, .vtt, .json).
They never delete your original videos or the script itself.
Feel free to open an issue or submit a pull request if you have improvements or suggestions!
GNU License © 2025 Yan Brasiliano Silva Penalva