brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -vf subtitles= burns subtitles into the video picture

Ffmpeg
~/tips/tip-ffmpeg-subtitles-burn-in

ffmpeg -i clip.mp4 -vf subtitles=clip.nl.srt -c:a copy clip-subbed.mp4

Draws an .srt or embedded subtitle track permanently onto the picture of a video.

In Jellyfin subtitles are a separate track you switch on and off, which is how I like them. But when you send a clip to someone whose phone player won’t load an .srt file, you want the text in the picture itself. ffmpeg’s subtitles filter draws them onto every frame.

ffmpeg -i clip.mp4 -vf subtitles=clip.nl.srt -c:a copy clip-subbed.mp4

That reads clip.nl.srt, renders the lines onto the video and copies the audio as it is. The subtitles don’t have to be a separate file: if they’re already inside an MKV, subtitles=movie.mkv uses the default subtitle track from that file, and subtitles=movie.mkv:si=1 the second one. The filter also has a force_style option to change the font or colour.

Before you start, check that your build has it with ffmpeg -filters | grep subtitles. The filter needs ffmpeg compiled with libass, and without it the filter simply isn’t there.

Now the catch, and it’s a big one. Burned-in subtitles are pixels, so you can’t switch them off or change the language later. Keep the original file. Drawing on the picture also means the video has to be re-encoded, so -c copy for the video is out and this takes as long as any other encode. File names with colons, commas or quotes clash with the filter syntax and need escaping, so I’d rename the subtitle file to something plain before running the command.

Further reading: FFmpeg filters: subtitles, ffmpeg documentation

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link