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

Moritz Barsnick barsnick at gmx.net
Wed Jul 13 15:53:31 EEST 2022


On Wed, Jul 06, 2022 at 13:36:30 -0700, Jim DeLaHunt wrote:
> On 2022-07-06 02:46, Pavel Yermolenko via ffmpeg-user wrote:
> > 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.

> So I guess that this asks you to do either (and stand by for a discussion of
> the really big problem with this):
>
> ffmpeg
>     .input(input_dir+video_file)
>     .input(input_dir+subtl_file)
>     .get_args(map='0:v', map='0:a', c='copy', map='1', 'c:s:0'='mov_text', 'metadata:s:s:0'='language=fra') ***Big problem!
>     .output(input_dir+'output.mp4')
>     .run()

In their test code, there is an "example" for maps:
https://github.com/kkroening/ffmpeg-python/blob/6189cd6861a90f6f52e6a8ba2db0fada54134194/ffmpeg/tests/test_ffmpeg.py#L657

> args = ffmpeg.output(i1['1'], i1['2'], TEST_OUTPUT_FILE1).get_args()
for "-map 0:1 -map 0:2".

You can probably reverse-engineer that, if the documentation doesn't
suffice.

Cheers,
Moritz


More information about the ffmpeg-user mailing list