Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cutting out a portion of video - python

I have videos of length approximately 25 min each and I wish to cut a few seconds from the start using python.

Searching about it, I stumbled upon the moviepy package for python. The problem is, it takes up a lot of time even for a single video. Following is the code snippet I use to cut 7 seconds from the start of a single video. The write process consumes a lot of time. Is there a better way to cut the videos using python?

from moviepy.editor import * clip = VideoFileClip("video1.mp4").cutout(0, 7) clip.write_videofile("test.mp4") 

Please let me know if I have missed out any details.

Any help is appreciated. Thanks!

like image 220
Pranav Arora Avatar asked May 19 '16 07:05

Pranav Arora


People also ask

What is VideoFileClip?

A video clip originating from a movie file. For instance: >>> clip = VideoFileClip("myHolidays.


2 Answers

Try this and tell us if it is faster (if it can, it will extract the video directly using ffmpeg, without decoding and reencoding):

from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip ffmpeg_extract_subclip("video1.mp4", start_time, end_time, targetname="test.mp4") 

If that doesn't help, have a look at the code

like image 93
Zulko Avatar answered Sep 22 '22 17:09

Zulko


If you are new to moviepy you should follow these steps.

Installation :

pip install --trusted-host pypi.python.org moviepy pip install imageio-ffmpeg 

Installation (in your virtualenv) version for old systems :

pip install --trusted-host pypi.python.org moviepy python import imageio imageio.plugins.ffmpeg.download() 

After these commands, you have the minimal software requirements.

Usage

from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip # ffmpeg_extract_subclip("full.mp4", start_seconds, end_seconds, targetname="cut.mp4") ffmpeg_extract_subclip("full.mp4", 60, 300, targetname="cut.mp4") 
like image 28
Samuel Dauzon Avatar answered Sep 22 '22 17:09

Samuel Dauzon