Looking for a senior program, using the python and opencv extract MP4 video frame, and saved into the image, regardless of the video size only 236 photos, where the feeling is limited, can't find the reason, hope experienced friends to have a look at, guiding ideas, thanks in advance.
The procedure is as follows,
The import OS. Path
The pictures # 1. The folder
Path='E:/Python/03 _projects/video2pic VideoToImage' # store video pictures home directory
If not OS. Path. The exists (path) : # if there is no will to create the folder
OS. The mkdir (path)
# 2. Read the video folder
Filepath='E:/Python/03 _projects video2pic/video' # need to read the video path
PathDir=OS. Listdir (filepath) # access folder file name
# 3. Cut video frames
For allDir pathDir: in # read video file
A=1 # pictures count - do not change
C=1 # frames counter - do not change
Videopath=r 'E:/Python/03 _projects video2pic/video/' + allDir # video file path
Vc=CV. VideoCapture (videopath) # read in video file
# stored video subdirectories
Path='E:/Python/03 _projects/video2pic VideoToImage/' + allDir. Split ('.') [0]
If not OS. Path. The exists (path) : # if there is no will to create the folder
OS. The mkdir (path)
If vc. IsOpened () :
Rval, frame=vc. The read ()
The else:
Rval=False
TimeF=1 # frames between
While rval:
Rval, frame=vc. The read () # video frame read
If rval==False:
Break
If (c % timeF==0) :
CV. Imwrite (path + '/' + STR (a) + 'JPG', frame) # save the path
A=a + 1
C=c + 1
CV. WaitKey (1)
Vc. Release ()
CodePudding user response:
Extract frames, I remember the document have said that have a chance to appear inside frame drop