Answer the question
In order to leave comments, you need to log in
How and with what can I merge two video files of different resolutions in Python3?
Good afternoon. There is a script that determines the resolution of the video and creates the same resolution video from the picture, then everything is fastened together. The situation has changed and now you need to fasten ready-made video files, adjusting the resolution manually is very dreary, and attempts to combine videos of different resolutions give an unwatchable result at the output (everything is distorted and in noise). I know how to do it manually, but there are a lot of files and I would like to put everything on stream. Prompt modules, and it is better with an example how to solve this problem.
Answer the question
In order to leave comments, you need to log in
You can use the OpenCV library:
import cv2
video1 = cv2.VideoCapture('video1.mp4')
video1_width = video1.get(cv2.CAP_PROP_FRAME_WIDTH)
video1_height = video1.get(cv2.CAP_PROP_FRAME_HEIGHT)
video1_fps = video1.get(cv2.CAP_PROP_FPS)
video2 = cv2.VideoCapture('video2.mp4')
writer = cv2.VideoWriter('video3.mp4', cv2.VideoWriter_fourcc(*'MP4V'), video1_fps, (video1_width, video1_height))
writer.set(cv2.VIDEOWRITER_PROP_QUALITY, 100)
while True:
ret, frame = video2.read()
if not ret:
break
frame = cv2.resize(frame, (video1_width, video1_height))
writer.write(frame)
video1.release()
video2.release()
writer.release()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question