[FFmpeg-user] How to embed subtitles into video using Python

Pavel Yermolenko py.missuri at sunrise.ch
Wed Jul 6 12:46:10 EEST 2022


Hello,

I'm looking for a command format to embed subtitles into video (not to 
burn them).

This command, that I found somewhere on the web works fine - the 
subtitles are just embedded into video, quite rapid process.

ffmpeg -i video.mp4 -i video.srt -map 0:v -map 0:a -c copy -map 1 -c:s:0 
mov_text -metadata:s:s:0 language=fra output.mp4

I need to process many files in batch mode, so I decided to use Python.

In Python there is ffmeg support package: *ffmpeg-python*.

ffmpeg-python 0.2.0 <https://pypi.org/project/ffmpeg-python/>

Unfortunately in the documentation there is no examples on how to 
process subtitles.

The only example I found (snippet below) burns subtitles into video ... 
quite time-consuming process.

import ffmpeg
input_dir = 'mydir/'
video_file = 'video.mp4'
subtl_file = 'subtitles.srt'

(
     ffmpeg
     .input(input_dir+video_file)
     .filter('subtitles', input_dir+subtl_file)
     .output(input_dir+'output.mp4')
     .run()
)

What option in the command I wrote at the beginning causes the subtitles 
to be embedded as metadata, and not rendered with particular frames?

Thanks.

Sincerely.

Pavel.





More information about the ffmpeg-user mailing list