Connect multiple videos in one shot using OpenCV!

I wanted to connect a lot of videos such as reinforcement learning results in one shot, so I made it.

situation

A program that creates a single video by concatenating all the videos in a directory containing multiple videos.

Source

import cv2
import glob

def comb_movie(movie_files,out_path):
    
    #The format is mp4
    fourcc = cv2.VideoWriter_fourcc('m','p','4','v')

    #Acquisition of video information
    movie = cv2.VideoCapture(movie_files[0])
    fps    = movie.get(cv2.CAP_PROP_FPS)
    height = movie.get(cv2.CAP_PROP_FRAME_HEIGHT)
    width  = movie.get(cv2.CAP_PROP_FRAME_WIDTH)


    #Open the output file
    out = cv2.VideoWriter(out_path, int(fourcc), fps, (int(width), int(height)))
        
        
    for movies in (movie_files):
        print(movies)
        #Read video file, argument is video file path
        movie = cv2.VideoCapture(movies)
        
        if movie.isOpened() == True: #Check if the video file can be read normally
            ret,frame = movie.read() # read():Read the captured image data for one frame
        else:
            ret = False
        
        while ret:
            #Write the read frame
            out.write(frame)
            #Read next frame
            ret,frame = movie.read()

#Retrieve a list of videos in a directory
files = sorted(glob.glob("./movie_dir/*.mp4"))

#Output file name
out_path = "movie_out1.mp4"

comb_movie(files,out_path)


Recommended Posts

Connect multiple videos in one shot using OpenCV!
How to adapt multiple machine learning libraries in one shot
How to convert 0.5 to 1056964608 in one shot
Edit videos in Python using MoviePy
Handle multiple python versions in one jupyter
Make one Mario using Numpy and OpenCV
Consolidate multiple disks into one using LVM
Save multiple models in one form with Django
Multiple graphs are displayed in one window (python)
Try converting videos in real time with OpenCV
How to do zero-padding in one line with OpenCV
How to retrieve multiple arrays using slice in python.
Combine multiple Excel files loaded using pandas into one