Nagabhushan S N
Nagabhushan S N

Reputation: 7277

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.

Upvotes: 2

Views: 2370

Answers (1)

Menth
Menth

Reputation: 398

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:

Upvotes: 6

Related Questions