Programster's Blog

Tutorials focusing on Linux, programming, and open-source

FFMPEG - Apply Hardsubs To Video

Hardsubs are simply subtitles baked into the video imagery. E.g. you cannot turn them off/on, they are part of the image. Because of this, usually they are undesirable. However, if you are watching something that needs subtitles, with a tool that does not support subtitle tracks or having separate subtitle files, this may prove to be a workaround solution.

Steps

Assuming you have a subtitles SRT file to hand for the video, you can apply them as hardsubs to the video with:

#!/bin/bash
INPUT_FILENAME="someFileWithoutHardsubs.mp4"
OUTPUT_FILENAME="someVideo.hardsubbed.mp4"
SUBTITLES_FILE="subtitles.srt"

ffmpeg \
  -i $INPUT_FILENAME \
  -vf subtitles=$SUBTITLES_FILE \
  $OUTPUT_FILENAME

Unfortunately this will perform a video re-conversion, so video quality is likely to be lost unless you specify your own CRF/bitrate parameters. You may wish to perform this step with CRF 0, and perform a 2-pass encoding on the finished result. E.g.

#!/bin/bash
INPUT_FILENAME="someFileWithoutHardsubs.mp4"
OUTPUT_FILENAME="someVideo.hardsubbed.mp4"
SUBTITLES_FILE="subtitles.srt"

ffmpeg \
  -i $INPUT_FILENAME \
  -c:v libx264 \
  -crf 0 \
  -vf subtitles=$SUBTITLES_FILE \
  $OUTPUT_FILENAME

References

Last updated: 22nd October 2023
First published: 15th October 2023

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch