Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python library for splitting video

Tags:

python

video

I need to split big video file into smaller pieces by time. Give me your suggestions, please, and if you can some tips for library usage. Thanks.

like image 804
pss Avatar asked Jan 02 '11 21:01

pss


1 Answers

OpenCV has Python wrappers.

As you're interested in video IO, have a look at QueryFrame and its related functions there.

In the end, your code will look something like this (completely untested):

import cv

capture = cv.CaptureFromFile(filename)
while Condition1:
    # Need a frame to get the output video dimensions
    frame = cv.RetrieveFrame(capture) # Will return None if there are no frames
    # New video file
    video_out = cv.CreateVideoWriter(output_filenameX,
        CV_FOURCC('M','J','P','G'), capture.fps, frame.size(), 1)
    # Write the frames
    cv.WriteFrame(video_out, frame)
    while Condition2:
        # Will return None if there are no frames
        frame = cv.RetrieveFrame(capture)
        cv.WriteFrame(video_out, frame)

By the way, there are also ways to do this without writing any code.

like image 192
mpenkov Avatar answered Sep 19 '22 15:09

mpenkov