Created
July 17, 2018 16:56
-
-
Save AruniRC/3e6d0a777b0770ba301a87198fe81034 to your computer and use it in GitHub Desktop.
Get number of frames using Scikit-video and Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Sometimes it is useful to know the total number of video frames before starting to iterate. | |
This is not possible using the default video reader in Sk-video. | |
The snippet below shows how to do this using the FFMPEG reader instead. | |
''' | |
if osp.exists(video_path): | |
vid_reader = skvideo.io.FFmpegReader(video_path) # NOTE: not the standard skvideo.io.vreader | |
else: | |
raise IOError('Path to video not found: \n%s' % video_path) | |
# Knowing number of frames from FFMPEG metadata w/o without iterating over all frames | |
(numframe, _, _, _) = vid_reader.getShape() # numFrame x H x W x channels | |
videogen = vid_reader.nextFrame() # generator for iterating over all video frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's also important to call vid_reader.close() after the read process to prevent mem leak.