matt
matt

Reputation: 13

Downloading a subclip of an .mp4 from URL using Python

I'm currently working on a Python project that needs to download a segment of a .mp4 file hosted on archive.org. For example, say I'd like to just download 10 seconds of this clip, from 2:30 to 2:40. Is this possible to accomplish in Python without downloading the entire file?

I've looked into moviepy (which I'm using to edit the video -- no issues there), as well as wget and ffmpeg. Any knowledge you can share is helpful, thanks so much!

Upvotes: 1

Views: 908

Answers (1)

RoachLok
RoachLok

Reputation: 56

For this kind of tasks ffmpeg comes in very handy. There are python wrappers out there but most of them are not very complete.

I think the best solution for you is to download a compiled version from http://www.ffmpeg.org/download.html and use it through Python to download the clip you want.

Once you have downloaded ffmpeg, here's an example usage with python:

    import os
    os.system('ffmpeg -ss 00:02:30 -i "https://ia800903.us.archive.org/35/items/ArcherProductionsInc/DuckandC1951.mp4" -to 00:00:10 output.mp4')

What each parameter does:

-ss: is the time at which your clip will start.
-i : is the URL or path to the video.
-to: How long the resulting clip will be / duration of the clip.

Upvotes: 3

Related Questions