DEV Community

Jens Louw-Christensen
Jens Louw-Christensen

Posted on

ffmpeg subtitles cheat sheet: burn in, soft tracks, convert, shift and extract

Every command I reach for when a video needs subtitles: burn them in, add a track viewers can turn off, convert, shift and pull them out.

Burn subtitles into the picture

For TikTok, Reels and Shorts, which don't use uploaded subtitle files:

ffmpeg -i video.mp4 -vf "subtitles=subs.srt" -c:a copy out.mp4
Enter fullscreen mode Exit fullscreen mode

Change the look while burning (font, size, outline, distance from the bottom):

ffmpeg -i video.mp4 -vf "subtitles=subs.srt:force_style='FontName=Montserrat,FontSize=22,Outline=2,MarginV=60'" -c:a copy out.mp4
Enter fullscreen mode Exit fullscreen mode

An ASS file keeps its own styles and karaoke timing, so use the ass filter:

ffmpeg -i video.mp4 -vf "ass=subs.ass" -c:a copy out.mp4
Enter fullscreen mode Exit fullscreen mode

On Windows, a path with a drive letter needs the colon escaped inside the filter: subtitles='C\:/clips/subs.srt'.

Add a subtitle track viewers can switch off

MP4 takes the mov_text codec, MKV takes SRT as it is:

ffmpeg -i video.mp4 -i subs.srt -c copy -c:s mov_text -metadata:s:s:0 language=eng out.mp4
ffmpeg -i video.mp4 -i subs.srt -c copy -c:s srt out.mkv
Enter fullscreen mode Exit fullscreen mode

Convert, shift and extract

ffmpeg -i subs.vtt subs.srt                   # VTT to SRT
ffmpeg -itsoffset 1.5 -i subs.srt shifted.srt # every subtitle 1.5 s later (a negative number moves them earlier)
ffmpeg -i movie.mkv -map 0:s:0 subs.srt       # the first subtitle track out of a video
Enter fullscreen mode Exit fullscreen mode

Without a terminal

The same jobs run in the browser, with nothing uploaded: SRT to VTT, VTT to SRT, shift subtitles and clean up a broken SRT.

For animated word-by-word captions, where each word lights up as it's spoken, Cuecaps transcribes the video on your own computer and exports the MP4, a transparent overlay or an ASS file with word timing for the ass filter above.

Top comments (0)