简体   繁体   中英

Get frame rate of a video using skvideo package python

I'm reading a video using skvideo package

video = skvideo.io.vread(video_path)

This returns the frames only. But I want to read the frame rate as well, so that while saving the processed video, I can save it with the same frame rate.

I found many answers on StackOverflow to get frame rate but they all use open-cv . I don't want to use open-cv just to read frame rate.

You can indeed use skvideo to read video metadata.

For example:

import skvideo.io
import skvideo.datasets
import json
metadata = skvideo.io.ffprobe(skvideo.datasets.bigbuckbunny())
print(metadata.keys())
print(json.dumps(metadata["video"], indent=4))

That would print all video metadata.

If you are only interested in framerate you can get it like this:

import skvideo.io
import skvideo.datasets

# Example video file
filename = skvideo.datasets.bigbuckbunny()

# Read actual video data and do something with it later on..
videodata = skvideo.io.vread(filename)

# Read video metadata and do something with it..
videometadata = skvideo.io.ffprobe(filename)
frame_rate = videometadata['video']['@avg_frame_rate']

You can find examples from the documentation, please see links below:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM