OpenCV сообщает о TBR вместо FPS при использовании capture.get (CV_CAP_PROP_FPS) - PullRequest
1 голос
/ 22 февраля 2012

У меня есть несколько видео, которые я пытаюсь обработать, используя OpenCV и Qt 4.7.4 в Mac OS 10.6.8 (Snow Leopard). Если я создаю объект cv::VideoCapture, а затем запрашиваю частоту кадров, связанную с таким видео, я получаю TBR, а не FPS.

Например, если использовать ffprobe Video1.mp4, я получаю:

>> 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

, который правильно сообщает FPS = 27,71 и TBR = 1001. Тем не менее, если я использую следующий код OpenCV для запроса 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;

Вывод, который я получаю:

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

Который сообщает TBR вместо FPS. Такое поведение соответствует, когда я пытаюсь открыть разные видео.

Я проверил OpenCV bug tracker , и я также обнаружил, что этот вопрос переполнения стека - похожая, но не совсем та же проблема, поэтому я не знаю, что делать дальше , Любые намеки или идеи приветствуются, поскольку я много чего перепробовал и, похоже, ничего не получил.

1 Ответ

7 голосов
/ 22 февраля 2012

Я думаю, что они решили сообщить TBR, потому что это лучшее предположение ffmpeg относительно того, какова частота кадров на самом деле. Во многих контейнерах поле fps (точнее AVStream.avg_frame_rate) недоступно, поэтому на него нельзя полагаться.

Вот комментарии из источника ffmpeg к полям tbr, tbc и tbn:

TBR (лучшее предположение ffmpeg):

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 (временная база кодека):

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 (временная база потока (контейнера)):

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;

Надеюсь, это объясняет, почему вместо FPS указывается TBR. Похоже, ffmpeg испытывает затруднения при определении временной базы для вашего видеопотока, и контейнер (например, AVI, MP4, DivX, XviD и т. Д.) Предоставляет частоту кадров, поэтому ffmpeg отображает ее, даже если она может не определить это с помощью анализа. Можно ли правильно перекодировать видео?

...