Home > other >  Python opncv2 pictures turn video problem
Python opncv2 pictures turn video problem

Time:10-09

The video file to each frame write to the output. The avi, but only 6 k, if he does not support continuous writing, he only kept a frame?? (they want to achieve. Write a program to the incoming two video 0, 1, and then they synthesis of a large size of the video 2, then the content of the 2 on the left is 0, the right is 1, the content of the broadcast, now settle for second best, I'll make a video of each frame, synthetic image collection, finally this, in turn, save the image collection into video, but each video is only 6 k, covers? Only save the last frame??? The great god has good implementation scheme welcome guidance,)



The HTML code is as follows, novice, may not be standard, still hope to give directions (comment better design) :
# coding: utf-8
The import OS
The import cv2
The import numpy as np
The import time
The from PIL import Image



Cap=cv2. VideoCapture (' E: \ \ 00 mp4) # is correct, no problem of

# Define the codec and create VideoWriter object

Fourcc=cv2. VideoWriter_fourcc (* 'XVID')
Out=cv2. VideoWriter (' output. Avi, fourcc, 20.0, (768432)) # each frame of video high 768 wide 432

Frames=[] # save every frame image collection
While (cap) isOpened ()) :

Ret, frame=cap. The read () # skip judgment, practice shows no effect
Frames. Append (frame)
If cv2. WaitKey (2)==27:
Break

# frames=array (frames)
For frame in frames:

Out. Write (frame) # write each frame to the output video file. The avi, but only 6 k, if he does not support continuous writing, he only kept a frame??

# release window
Cap. Release ()
Out. Release ()
Cv2. DestroyAllWindows ()



CodePudding user response:

Will * 'XVID' for 'X', 'V', 'I', 'D', and note if each file exists,
  • Related