简体   繁体   English

使用skvideo包python获取视频的帧频

[英]Get frame rate of a video using skvideo package python

I'm reading a video using skvideo package 我正在使用skvideo包阅读视频

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 . 我在StackOverflow上找到了很多答案来获取帧速率,但是它们都使用open-cv I don't want to use open-cv just to read frame rate. 我不想使用open-cv来读取帧速率。

You can indeed use skvideo to read video metadata. 您确实可以使用skvideo读取视频元数据。

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: 您可以从文档中找到示例,请参见下面的链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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