Verketten Sie alle Videos im Verzeichnis zu einem Video
$ python3 combine_videos.py -i sample_videos/ -o output.mp4
29.0 1280 720
Filename: video01.mp4
Filename: video02.mp4
Filename: video03.mp4
Done.
combine_videos.py
#coding=utf-8
import os
import cv2
import glob
import argparse # 1.Argparse importieren
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input_dir', help='input video directory')
parser.add_argument('-o', '--output_video', help='output video filename')
args = parser.parse_args()
def combine_videos(directory, result):
#Geben Sie das einzugebende Video an(Nach Zeichenfolge sortieren)
videos_list = glob.glob('{}/*'.format(directory))
videos_list.sort()
#Geben Sie MP4V als Format an
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
#Erfassung von Videoinformationen
movie = cv2.VideoCapture(videos_list[0])
fps = movie.get(cv2.CAP_PROP_FPS)
height = movie.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = movie.get(cv2.CAP_PROP_FRAME_WIDTH)
print(fps, int(width), int(height))
#Öffnen Sie die Ausgabedatei
out = cv2.VideoWriter(result, int(fourcc), fps, (int(width), int(height)))
#Video wird geladen
for video in videos_list:
movie = cv2.VideoCapture(video)
print('Filename: ', video.split('/')[-1])
while True:
ret, frame = movie.read()
out.write(frame)
if not ret:
break
print('Done.')
if __name__ == '__main__':
combine_videos(args.input_dir, args.output_video)
Recommended Posts