The free and libre command line tool ffmpeg, in addition to encode videos, can also “draw” subtitles onto a video. Using ffmpeg we can enable filters that allow us to manipulate the video we are working on. One of these filter/manipulation is to basically print/incrust/draw texts onto a video.
For the following explanation I will assume that we have:
- a video file and a subtitle file that match the video. In my explanation I’ll use subtitle.srt for the subtitle file and input.mov for the video;
- we know how to use ffmpeg (refer to this article to know how).
As a remark, I will add that applying filters with ffmpeg, such as this subtitle filter, means re-encoding the video with the subtitles. So, even if we can go from the mov format to a mov format, for example, ffmpeg will still re-encode the video while adding the subtitles on top of the image. If we wish our video with the burnt subtitles to be the master file, then adding the subtitles from the editing software might a more adequate solution.
Let us begin.
A video demonstration
The command
The basic command to burn the subtitles (subtitles.srt) onto a video (input.mov) is the following: ffmpeg -i input.mov -vf subtitles=input.srt output.mp4
What matters here is -vf subtitles=input.srt
-vf
: as mentioned above, ffmpeg uses filters to incrust text onto a video, and to call such filter we use the option-filter:v
whose shorthand is-vf
1;subtitles
: this is the name of the filter, so ffmpeg knows what it is dealing with.2=
: the equal sign tells ffmpeg what to look for, it gives a value to the filter and here the value is the name and location of the subtitle file we want to burn,input.srt
.
As for:
-i input.mov
: it sets our input as being the file ‘input.mov’,- and
output.mp4
sets out final video as being named ‘output’ and to be encoded as a H264 mp4 file. Indeed, by putting.mp4
as an extension, ffmpegs will interpret this as us wanting to encode the file using the H264 codec.3 It is possible to change the output format. A list of supported formats can be obtain by typingffmpeg -formats
or by visiting ffmpeg’s page on the subject.
An example
So now in practical terms:
- open the terminal/console;
- go to the folder where the files are located using the
cd
command:cd "C:\Path to\Your folder"
.4 This is for comfort as so we won’t have to put the full path of the file each time we need it.5 - enter the following command:
ffmpeg -i input.mov -vf subtitles=input.srt output.mp4
- the progression of our burning will then appear, showing something like this:
frame= 738 fps= 86 q=26.0 size= 1536kB time=00:01:01.25 bitrate= 205.4kbits/s speed=7.13x
, and will eventually disappear, indicating to us that the burning is done. - so we can now found the final video output (
output.mp4
) in the folder in which we pointed the terminal (using thecd
command). Once we play it we’ll see subtitles onto the video.
The End