Cutting part of a video - python

I have a video about 25 minutes long each and I want to cut a few seconds from the start using python.

Searching for this question, I came across a pypyp package for python. The problem is that it takes a lot of time even for one video. Below is a snippet of code that I use to cut off 7 seconds from the start of one video. The recording process takes a lot of time. Is there a better way to crop a video 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 any details.

Any help is appreciated. Thanks!

+17
python video moviepy
source share
3 answers

Try this and tell us if it is faster (if possible, it will extract the video directly with ffmpeg, without decoding and transcoding):

 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 work, take a look at the code

+29
source share
 from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip ffmpeg_extract_subclip("video1.mp4", t1, t2, targetname="test.mp4") 

t1 and t2 in this code represent the start time and end time of the trim. The video before t1 and after t2 will be omitted.

+2
source share

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

Installation (in your virtualenv):

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

After these commands, you have the minimum software requirements.

using

 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") 
0
source share

All Articles