Bake-in SRT Captions into Videos Using ffmpeg

For STEAM Powered Facebook videos and YouTube allow you to attach an SRT file for captions. However, Twitter and Instagram do not and captions need to be baked-in.

Use this bash script create new videos with the SRT captions baked-in. The script needs to be run in the directory that contains video files with their corresponding SRT files (with the .en_US language suffix). New videos with the captions baked-in will be created in the same directory.

#!/bin/bash
# Check out STEAM Powered (https://steampoweredshow.com/) where I have conversations
# with women in STEAM to learn a bit about what they do and who they are.
# https://steampoweredshow.com/learn-more/
# Usage
# =====
#
# Execute script in the directory containing the video and srts files, or modify to take
# a path argument.
#
# Expects the directory to contain the video files with correspondingly named
# srt files in the same directory.
# ie. If there is a file named video.mov, there should be a video.en_US.srt to apply.
# Outputs a new videosubs.mp4 file.
#
# For individual video files, use the ffmpeg command on its own.
# Change input video file extension as needed.
find -E . -type f -regex ".*.mov" -print0 | while IFS= read -r -d '' name;
do
f=$(basename -- "$name")
# Modify the SRT suffix to match your required language, or remove.
# Change output video file suffix and extension as needed.
ffmpeg -nostdin -i "$f" -vf subtitles="$f.en_US.srt" "${f%w.*}subs.mp4" < /dev/null
done
view raw bakesrt.sh hosted with ❤ by GitHub
Published October 1, 2021