OpenCV로 처리하려고하는 33 초 비디오가 있습니다. 내 목표는 각 프레임이 해당하는 시간의 인스턴스 (비디오의 시작 부분에 비례)를 결정하는 것입니다. 저는 다른 프레임 속도로 녹화 된 동일한 장면의 비디오에서 프레임을 비교할 수 있도록이 작업을 수행하고 있습니다.OpenCV가 정확한 프레임 속도/카운트를보고하지 않습니다.
는 무엇의 작업은 :
- 는 FPS가 제대로 59.75로보고됩니다. 이것은
ffprobe
이보고 한 내용과 일치하므로 정확하다고 믿기 때문에 기쁩니다. 나는 데
문제는 다음과 같습니다
CAP_PROP_POS_MSEC
반환 잘못된 값. 동영상이 끝날 때까지 최대 557924ms (9 분 이상)입니다. 33 세 비디오의 경우, 이것이 옳지 않을 수 있습니다.CAP_PROP_FRAME_COUNT
도 올바르지 않습니다. 33371로보고되었는데, 59.75fps로 9 분 분량의 영상을 제공합니다. 위의 오류와 일치하지만 여전히 올바르지 않습니다.CAP_PROP_POS_FRAME
도 마찬가지입니다.
비디오는 here (약 10MB)입니다.
무엇이 잘못 될 수 있는지에 대한 아이디어가 있습니까?
ffprobe
출력 :
FFprobe version SVN-r20090707, Copyright (c) 2007-2009 Stefano Sabatini
libavutil 49.15. 0/49.15. 0
libavcodec 52.20. 0/52.20. 1
libavformat 52.31. 0/52.31. 0
built on Jan 20 2010 00:13:01, gcc: 4.4.3 20100116 (prerelease)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/misha/Dropbox/Public/sequence.mp4':
Duration: 00:00:33.37, start: 0.000000, bitrate: 2760 kb/s
Stream #0.0(und): Video: h264, yuv420p, 1920x1080, 59.75 tbr, 1k tbn, 2k tbc
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16
전체 코드 :
#include <iostream>
#include <assert.h>
#include <cv.h>
#include <highgui.h>
#include <cmath>
#include <iostream>
#include <string.h>
#include <stdio.h>
extern "C"
{
#include "options.h"
}
using namespace std;
#define DEBUG 0
static void
print_usage(char *argv0)
{
cerr << "usage: " << argv0 << " video.avi [options]" << endl;
}
int main(int argc, char** argv)
{
if (argc < 2)
{
print_usage(argv[0]);
return -1;
}
int step = 30;
struct Option options[] =
{
{ "step", 1, &step },
{ NULL, 0, NULL }
};
int ret = parse_options(2, argc, argv, options);
if (ret == 0)
{
print_usage(argv[0]);
return -1;
}
CvCapture *capture = cvCaptureFromFile(argv[1]);
int counter = 0;
while (cvGrabFrame(capture))
{
++counter;
IplImage *frame = cvRetrieveFrame(capture);
double millis = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_MSEC);
double current = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES);
double total = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
printf("%d %d/%d %f\n", counter, (int)current, (int)total, millis);
int min = (int)(millis/1000/60);
millis -= min*60000;
int sec = (int)(millis/1000);
millis -= sec*1000;
printf("%d %02d:%02d:%f\n", counter, min, sec, millis);
}
cvReleaseCapture(&capture);
return 0;
}
다음 중 어느 것을 사용하고 있습니까? Windows/Linux/Mac? – karlphillip
Linux (Ubuntu 10.04 LTS) – misha
많은 설명이 있습니다. OpenCV는 여전히 Linux에서 비디오 파일의 지원을 개선하기 위해 노력하고 있습니다. – karlphillip