OpenCV报告TBR代替FPS使用capture.get(CV_CAP_PROP_FPS) [英] OpenCV Reporting TBR instead of FPS when using capture.get(CV_CAP_PROP_FPS)

查看:1417
本文介绍了OpenCV报告TBR代替FPS使用capture.get(CV_CAP_PROP_FPS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个视频,我正在使用Mac OS 10.6.8(Snow Leopard)上的OpenCV和Qt 4.7.4进行处理。如果我创建一个 cv :: VideoCapture 对象,然后查询与这样的视频相关的帧速率,我得到的是TBR而不是FPS。



例如,如果使用 ffprobe Video1.mp4 我得到的是:

 >> ffprobe Video1.mp4 
ffprobe版本0.7.8,版权所有(c)2007-2011 FFmpeg开发者
建于2011年11月24日14:31:00与gcc 4.2.1(Apple Inc. build 5666) (点3)
配置:--prefix = / opt / local --enable-gpl --enable-postproc --enable-swscale -
enable-avfilter --enable-libmp3lame --enable -libvorbis --enable-libtheora --enable-
libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264
--enable-libvpx --enable-libspeex --mandir = / opt / local / share / man --enable-shared -
enable-pthreads --cc = / usr / bin / gcc-4.2 --arch = x86_64 --enable-yasm
libavutil 50. 43. 0 / 50. 43. 0
libavcodec 52.123。 0 / 52.123。 0
libavformat 52.111。 0 / 52.111。 0
libavdevice 52. 5. 0 / 52. 5. 0
libavfilter 1. 80. 0 / 1. 80. 0
libswscale 0. 14. 1 / 0. 14. 1
libpostproc 51. 2. 0 / 51. 2. 0

从Video1.mp4输入#0,mov,mp4,m4a,3gp,3g2,mj2:
元数据:
major_brand:isom
minor_version:0
compatible_brands:mp41avc1qt
creation_time:2012-01-09 23:09:43
encoder:vlc 1.1.3 stream输出
encoder-eng:vlc 1.1.3流输出
持续时间:00:10:10.22,开始:0.000000,比特率:800 kb / s
流#0.0(eng):视频: h264(基线),yuvj420p,704x480 [PAR 10:11 DAR 4:3],798
kb / s,27.71 fps,1001 tbr,1001 tbn,2002 tbc
元数据:
creation_time :2012-01-09 23:09:43

哪个正确报告FPS = 27.71和TBR = 1001但是,如果我使用以下OpenCV代码查询FPS:

  QString filename = QFileDialog :: getOpenFileName(this,
打开视频,
视频文件(* .mp4,* .mpg));

capture.release();
capture.open(filename.toAscii()。data());

if(!capture.isOpened()){
qDebug()<<打开视频时出错!
返回;
}


qDebug()<< Frame Rate:<< capture.get(CV_CAP_PROP_FPS);
qDebug()<< Num of Frames:<< capture.get(CV_CAP_PROP_FRAME_COUNT);
qDebug()<< OpenCV Version<< CV_VERSION;

我得到的输出是:

 帧率:1001 
帧数:610832
OpenCV版本2.3.1

哪些报告TBR而不是FPS。当我尝试打开不同的视频时,这种行为是一致的。



我查看了OpenCV的错误跟踪器这个堆栈溢出问题是一个类似的但不完全相同的问题,所以我在下一步做什么是失败的。任何提示或想法是非常受欢迎的,因为我尝试了很多东西,似乎没有地方。

解决方案

我想象他们选择报告TBR,因为这是 ffmpeg的最佳猜测,关于什么帧率实际上是。在许多容器上,fps字段(更具体地说是 AVStream.avg_frame_rate )不可用,所以不能真正依赖。



这是tbr,tbc和tbn字段上的 ffmpeg 源的注释:



TBR(ffmpeg最好的猜测):

  struct AVStream {
...
/ **
*流的真实基本帧率。
*这是所有时间戳都可以准确地代表
*的最低帧率(它是流中所有
*帧率的最小公倍数)。注意,这个值只是一个猜测!
*例如,如果时基是1/90000,并且所有帧都有
*约3600或1800计时器滴答,则r_frame_rate将为50/1。
* /
AVRational r_frame_rate;

TBC(编解码器时基):

  struct AVCodecContext {
...
/ **
*这是时间的基本单位(以秒为单位)以
*的方式表示帧时间戳。对于固定fps内容,
*时基应为1 /帧率,时间戳增量应为1.
*解码:由libavformat
*编码设置:由av_write_header中的libavformat设置
* /
AVRational time_base;

TBN(流(容器)时基)):

  struct AVStream {
...
/ **
*这是时间的基本单位以秒为单位)以
*的形式表示帧时间戳。对于固定fps内容,
*时基应为1 /帧率,时间戳增量应为
*相同1.
* - 编码:必须由用户设置。
* - 解码:由libavcodec设置。
* /
AVRational time_base;

希望这可以解释为什么报告TBR而不是FPS。似乎 ffmpeg 难以确定视频流的时基,容器(例如,AVI,MP4,DivX,XviD等)提供帧率,所以 ffmpeg 显示它,即使它不能通过分析确定它。可以正确地对视频进行重新编码吗?


I have several videos that I am trying to process using OpenCV and Qt 4.7.4 on Mac OS 10.6.8 (Snow Leopard). If I create a cv::VideoCapture object and then query for the frame rate related to such video, what I get back is the TBR and not FPS.

For instance if use ffprobe Video1.mp4 what I get is:

>> ffprobe Video1.mp4      
ffprobe version 0.7.8, Copyright (c) 2007-2011 the FFmpeg developers
built on Nov 24 2011 14:31:00 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --   
enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-
libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 
--enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --
enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
libavutil    50. 43. 0 / 50. 43. 0
libavcodec   52.123. 0 / 52.123. 0
libavformat  52.111. 0 / 52.111. 0
libavdevice  52.  5. 0 / 52.  5. 0
libavfilter   1. 80. 0 /  1. 80. 0
libswscale    0. 14. 1 /  0. 14. 1
libpostproc  51.  2. 0 / 51.  2. 0

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Video1.mp4':
Metadata:
major_brand     : isom
minor_version   : 0
compatible_brands: mp41avc1qt  
creation_time   : 2012-01-09 23:09:43
encoder         : vlc 1.1.3 stream output
encoder-eng     : vlc 1.1.3 stream output
Duration: 00:10:10.22, start: 0.000000, bitrate: 800 kb/s
Stream #0.0(eng): Video: h264 (Baseline), yuvj420p, 704x480 [PAR 10:11 DAR 4:3], 798 
kb/s, 27.71 fps, 1001 tbr, 1001 tbn, 2002 tbc
Metadata:
  creation_time   : 2012-01-09 23:09:43

Which correctly reports FPS = 27.71 and TBR = 1001. Nevertheless if I use the following OpenCV code to query for the FPS:

QString filename = QFileDialog::getOpenFileName(this,
                                        "Open Video",
                                        "Video Files (*.mp4, *.mpg)");

capture.release();
capture.open(filename.toAscii().data());

if (!capture.isOpened()){
    qDebug() <<"Error when opening the video!";
    return;
}


qDebug() << "Frame Rate:" << capture.get(CV_CAP_PROP_FPS);
qDebug() << "Num of Frames:" << capture.get(CV_CAP_PROP_FRAME_COUNT);
qDebug() << "OpenCV Version" << CV_VERSION;

The output I get is:

Frame Rate: 1001 
Num of Frames: 610832 
OpenCV Version 2.3.1 

Which reports the TBR instead of the FPS. This behavior is consistent when I try to open different videos.

I checked OpenCV's bug tracker and I also found this stack overflow question to be a similar but not quite the same problem, so I am at a loss to what to do next. Any hint or idea is most welcome since I've tried lots of things and seem to be getting nowhere.

解决方案

I imagine they chose to report TBR because that is ffmpeg's best guess as to what the framerate actually is. On many containers, the fps field (more specifically AVStream.avg_frame_rate) is not available, so it can't really be relied upon.

Here are the comments from the ffmpeg source on the tbr, tbc, and tbn fields:

TBR (ffmpeg's best guess):

struct AVStream {
...
/**
 * Real base framerate of the stream.
 * This is the lowest framerate with which all timestamps can be
 * represented accurately (it is the least common multiple of all
 * framerates in the stream). Note, this value is just a guess!
 * For example, if the time base is 1/90000 and all frames have either
 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
 */
AVRational r_frame_rate;

TBC (the codec timebase):

struct AVCodecContext {
...
/**
 * This is the fundamental unit of time (in seconds) in terms
 * of which frame timestamps are represented. For fixed-fps content,
 * time base should be 1/framerate and timestamp increments should be 1.
 * decoding: set by libavformat
 * encoding: set by libavformat in av_write_header
 */
AVRational time_base;

TBN (the stream (container) timebase):

struct AVStream {
...
/**
 * This is the fundamental unit of time (in seconds) in terms
 * of which frame timestamps are represented. For fixed-fps content,
 * timebase should be 1/framerate and timestamp increments should be
 * identically 1.
 * - encoding: MUST be set by user.
 * - decoding: Set by libavcodec.
 */
 AVRational time_base;

Hopefully, that explains why TBR is reported instead of FPS. It appears ffmpeg is having difficulty determining the time base for your video stream, and the container (e.g., AVI, MP4, DivX, XviD, etc...) supplies the framerate, so ffmpeg displays it even though it can't determine it through analysis. Is it possible to re-encode the video properly?

这篇关于OpenCV报告TBR代替FPS使用capture.get(CV_CAP_PROP_FPS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆