kkroening / ffmpeg-python

Python bindings for FFmpeg - with complex filtering support
Apache License 2.0
9.88k stars 883 forks source link

Can someone help me convert this code to ffmpeg_python please ? #741

Open TanMink opened 1 year ago

TanMink commented 1 year ago

ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -i video5.mp4 -i video6.mp4 \ -map 0 -c:v mpeg4 -q:v 1 -aspect 16:9 video1.avi \ -map 1 -c:v mpeg4 -q:v 1 -aspect 16:9 video2.avi \ -map 2 -c:v mpeg4 -q:v 1 -aspect 16:9 video3.avi \ -map 3 -c:v mpeg4 -q:v 1 -aspect 16:9 video4.avi \ -map 4 -c:v mpeg4 -q:v 1 -aspect 16:9 video5.avi \ -map 5 -c:v mpeg4 -q:v 1 -aspect 16:9 video6.avi

Dyupich commented 1 year ago

Try this:

import ffmpeg

def main():
    videos = ["video1.mp4", "video2.mp4", "video3.mp4"]

    for i, video in enumerate(videos):
        (
            ffmpeg
                .input(video)
                .output(f"{video[:-4]}.avi", **{"map": f"{i}", "c:v": "mpeg4", "aspect": "16:9"})
                .run(quiet=False, overwrite_output=False)
        )

if __name__ == '__main__':
    main()