opencv - OpenCV VideoCapture 如何确定 HLS 流的 CAP_PROP_FPS
问题描述
它非常清楚应用程序如何查询 OpenCV 以获取视频源的 FPS。网上有很多例子展示了通过VideoCapture调用来获取 fps。
video = cv2.VideoCapture(0);
fps = video.get(cv2.CAP_PROP_FPS)
但是,也可能存在已记录的担忧,即访问的 FPS 可能不准确。
我们正在使用 ffmpeg 将 mp4 和 avi 文件转换为 HLS。
usr/bin/ffmpeg -i data/import/ParkingLot_20211028155745_snippet.mp4 -codec copy -start_number 0 -hls_time 10 -hls_list_size 0 -framerate 15 -f hls data/fileServer/ParkingLot/ParkingLot_20211028155745_snippet.m3u8
然后,我们可以探测符合 HLS 的输出以查看其属性。
ffprobe -v quiet -print_format json -show_format -show_streams 'data/fileServer/ParkingLot/ParkingLot_20211028155745_snippet_0.ts' > thevideo.json
more thevideo.json
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "0/2",
"codec_tag_string": "[27][0][0][0]",
"codec_tag": "0x001b",
"width": 3840,
"height": 2160,
"coded_width": 3840,
"coded_height": 2160,
"closed_captions": 0,
"has_b_frames": 0,
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "16:9",
"pix_fmt": "yuvj420p",
"level": 51,
"color_range": "pc",
"color_space": "bt709",
"color_transfer": "bt709",
"color_primaries": "bt709",
"chroma_location": "left",
"refs": 1,
"is_avc": "false",
"nal_length_size": "0",
"r_frame_rate": "15/1",
"avg_frame_rate": "0/0",
"time_base": "1/90000",
"start_pts": 126000,
"start_time": "1.400000",
"bits_per_raw_sample": "8",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"variant_bitrate": "0"
}
}
],
"format": {
"filename": "data/fileServer/ParkingLot/ParkingLot_20211028155745_snippet.m3u8",
"nb_streams": 1,
"nb_programs": 1,
"format_name": "hls",
"format_long_name": "Apple HTTP Live Streaming",
"start_time": "1.400000",
"duration": "29.400000",
"size": "283",
"bit_rate": "77",
"probe_score": 100
}
}
在这里,我们看到文件的持续时间为 29.4(不到 30 秒)。我们还看到 r_frame_rate 是 15/1。奇怪的是 avg_frame_rate 是 0/0。
我们还可以找到帧数:
ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 data/fileServer/ParkingLot/ParkingLot_20211028155745_snippet.m3u8
输出为 440。
虽然我们似乎将 FPS 设置为 15,这与文件中的实际帧数及其持续时间(29.4/440 = .0668 - 66.8 毫秒,或 14.96 FPS)一致,但 VideoCapture(调用 video.get(cv2 .CAP_PROP_FPS)) 坚持输出帧率为 30 FPS。
我们不确定如何调用 ffmpeg 以确保它设置的详细信息将允许 OpenCV VideoCapture 看到 CAP_PROP_FPS 为 15。
因此,我们的问题既针对 OpenCV 社区,也针对 FFMPEG 社区(甚至更好地了解两者的人)。
在创建符合 HLS 的视频时要设置哪些关键参数,以确保 OpenCV VideoCapture 能够看到录制到该视频中的 FPS (15 FPS)?
VideoCapture 是默认假设 30FPS,还是实际上是通过查看 HLS 流来计算该值?
解决方案
推荐阅读
- directory - 如何更改 Ada 中的工作目录?
- sql - 简单的 SQL 模式设计?我们什么时候实现冗余关系?
- c++ - 形状对象C ++的不正确旋转和缩放
- html - 悬停影响不显示正确元素的不同元素
- xquery - 如何在 MarkLogic 结构查询中为 geo-elem-pair-query 设置权重?
- regex - CSS 选择器的破折号大小写正则表达式
- r - 使用 plotyly 或 Network3D 将 ggraph 转换为交互式绘图
- azure - Azure AD 中的多次登录
- python - Azure Functions IP 地址超出范围
- go - 无法通过串口解析 GPS 信息