cvCreateFileCapture()无法读取h 264编码的mp4文件

时间:2013-07-16 06:16:50

标签: opencv video h.264 decoder

我在opencv中有以下代码来读取mp4文件:

    CvCapture *capture =cvCreateFileCapture("DemoRecording.mp4");
    if(!capture){
        cout<<endl<<"Capture from file error"<<endl;
        return;
    }
    CvSize sz =cvSize((int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
    CvVideoWriter *writer =cvCreateVideoWriter("DemoRecording.avi", CV_FOURCC('L','A','G','S'), (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS), sz);
    IplImage *frame =cvCreateImage(sz, 8, 3);
    while(1){
        // Read Frames  
    }
    cvReleaseVideoWriter(&writer);
    cvReleaseCapture(&capture);

但是,我无法读取mp4文件。该文件使用H.264编码。我有ffmpeg显示的文件的以下详细信息:

fplay version N-42347-g299387e Copyright (c) 2003-2012 the FFmpeg developers
  built on Jul  8 2012 15:44:54 with gcc 4.7.1
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      51. 64.100 / 51. 64.100
  libavcodec     54. 33.100 / 54. 33.100
  libavformat    54. 15.102 / 54. 15.102
  libavdevice    54.  1.100 / 54.  1.100
  libavfilter     3.  1.100 /  3.  1.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'DemoRecording.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf53.31.100
  Duration: 00:00:16.23, start: 0.000000, bitrate: 819 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 540x720, 816 kb/s, 21.19 fps, 30 tbr, 600 tbn, 1200 tbc
    Metadata:
      handler_name    : VideoHandler
Frame changed from size:0x0 to size:540x720
[ffplay_buffer @ 04149040] w:540 h:720 pixfmt:yuv420p tb:1/600 fr:0/1 sar:0/1 sws_param:
[ffplay_buffersink @ 04ca69c0] No opaque field provided

我的计算机上安装了更新的k-lite编解码器包。我也有ffmpeg。使用libavcodec vfw解码mp4文件的首映专业软件能够播放该文件。

但是,openCV无法读取该文件。对此问题的任何帮助都非常感谢。

0 个答案:

没有答案
相关问题