Search code examples
pythonvideoffmpegmp4video-processing

How to create a clip from an mp4-file quickly?


I have a web app that lets users download a clip from a mp4-file specified before. Currently I use ffmpeg via python like this:

os.system('ffmpeg -i original_video -ss {start} -t {duration} result_video')

Processing 10 minutes of 720p video with this method also takes a few minutes (during the execution, ffmpeg displays speed=3x on average). Does this mean processing 10 minutes of video takes 3minutes & 20 seconds as I understand it?

Is this slow of a performance expected? Can I improve it by using an other filetype than mp4?


Solution

  • It's taking a long time because you're re-encoding the output video when you don't have to. Add the -c:v copy -c:a copy options and it will be much faster.

    os.system(f'ffmpeg -i original_video -ss {start} -t {duration} -c:v copy -c:a copy result_video')