ffmpeg-python
ffmpeg-python copied to clipboard
Mapping breaks `subtitles` filter: subtitles missing
Issue
I'm trying to hardcode the subtitles for a video clip, but the subtitles are not present in the output.
My code:
# Source is a file with embedded SRT subs.
source_path = "./some-file.mkv"
start=2000
end=2060
source = ffmpeg.input(source_path, ss=start, t=end-start)
video_with_subs_final = source.filter('subtitles', source_path)
result = source.audio.output(
video_with_subs_final,
'output.mkv',
crf=16,
preset="superfast",
pix_fmt="yuv420p"
).overwrite_output()
>>> result.compile()
['ffmpeg', '-ss', '2000', '-t', '60', '-i', './some-file.mkv', '-filter_complex', '[0]subtitles=./some-file.mkv[s0]', '-map', '0:a', '-map', '[s0]', '-crf', '16', '-pix_fmt', 'yuv420p', '-preset', 'superfast', 'output.mkv', '-y']

The output video has the correct duration and expected audio/video, but there aren't any hardcoded subs. The subtitles filter logs a stream mapping:
Stream mapping:
Stream #0:0 (h264) -> subtitles:default (graph 0)
Stream #0:1 -> #0:0 (ac3 (native) -> vorbis (libvorbis))
subtitles:default (graph 0) -> Stream #0:1 (libx264)
My usage of the subtitles filter seems consistent with the other examples I found in this repo, e.g.
- https://github.com/kkroening/ffmpeg-python/pull/438
- https://github.com/kkroening/ffmpeg-python/issues/416
- https://github.com/kkroening/ffmpeg-python/issues/420
Expected behavior
If I call ffmpeg from the commend line and strip out the explicit mapping, I get the expected output video (correct audio/video with subtitles):
$ ffmpeg -y -ss 2000 -t 60 -i some-file.mkv -filter_complex subtitles=./some-file.mkv -crf 16 -pix_fmt yuv420p -preset superfast soft_subs.mkv
In this case, the subtitles filter logs a different stream mapping:
Stream mapping:
Stream #0:0 (h264) -> subtitles:default (graph 0)
subtitles:default (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (ac3 (native) -> vorbis (libvorbis))
Stream #0:2 -> #0:2 (subrip (srt) -> ass (ssa))
Is there a way to make ffmpeg-python produce this behavior?
Thanks for any help!
Software versions
- macOS 11.5.2
ffmpeg-pythonversion 0.2.0ffmpegversion 5.0.1pythonversion 3.7.9