[FFmpeg-user] generating `-map` options from ffmpeg-python [was: Re: How to embed subtitles into video using Python]

Jim DeLaHunt list+ffmpeg-user at jdlh.com
Wed Jul 13 20:21:13 EEST 2022


On 2022-07-13 05:53, Moritz Barsnick wrote:

> 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 [the *ffmpeg-python*] 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.

Good catch!  That line does generate `-map` options to FFmpeg. That 
proves it is possible.

The value of `i1` in that line is the return from a call to 
`ffmpeg.input()`. The documentation for that, at 
<https://kkroening.github.io/ffmpeg-python/index.html#ffmpeg.input>, 
does not suffice for me at least to understand what the type of `i1` is, 
and what is the result of getting the index '1' from `i1`. I think you 
are right, it will require reading the code.

> Cheers,
> Moritz
Thank you,

      —Jim DeLaHunt




More information about the ffmpeg-user mailing list