为什么我不能在openCV中打开avi视频? [英] Why can't I open avi video in openCV?

查看:726
本文介绍了为什么我不能在openCV中打开avi视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚写了一个简单的视频阅读示例与openCV2.3.1,但似乎我无法打开avi视频反正:(

I just wrote a simple video reading example with openCV2.3.1, but it seems that I cannot open avi video anyway :(

VideoCapture capture("guitarplaying.avi");
if(!capture.isOpened()){
    std::cout<<"cannot read video!\n";
    return -1;
}
Mat frame;
namedWindow("frame");

double rate = capture.get(CV_CAP_PROP_FPS);
int delay = 1000/rate;

while(true)
{
    if(!capture.read(frame)){
        break;
    }
    imshow("frame",frame);

    if(waitKey(delay)>=0)
        break;
}

capture.release();

c $ c> std :: cout<<无法读取视频!\\\
,发现它每次都停在这里,为什么avi视频无法打开?

I made a breakpoint in std::cout<<"cannot read video!\n" and find that it stopped here every time. So why avi video cannot be opened? Thanks!

推荐答案

1)

确保视频文件实际位于

1)
Make sure the video file is actually in the same folder as the application (I'm assuming you've already tried this), otherwise specify the absolute path.

2)

如果您使用的是Windows,则可能需要使用编解码器包来阅读视频文件(例如, K-Lite Codec Pack )。

正如Macmade建议的,AVI只是一个容器,可以容纳不同的音频,视频,甚至封闭字幕编解码器。此外,这里是Zeranoe的Windows FFmpeg版本。如果您执行以下操作,您可以获取有关文件编解码器内容的进一步信息:

As Macmade suggested, AVI is merely a container which can house different audio, video, or even closed caption codecs. Also, here are Zeranoe's FFmpeg builds for Windows. You can get further information on your file's codec contents if you do the following:

ffmpeg -i guitarplaying.avi

您应该看到如下所示的输出:

You should see an output that looks like this:

ffmpeg version 0.8.7.git, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec  6 2011 09:20:43 with gcc 4.6.1
  configuration: --pkg-config=pkg-config --enable-gpl --enable-version3 --enable
-nonfree --enable-runtime-cpudetect --enable-memalign-hack --enable-postproc --a
rch=x86 --target-os=mingw32 --cross-prefix=i686-w64-mingw32- --prefix=/home/wluc
as/ffmpeg-cross/build/deploy --enable-libx264 --enable-libvpx --enable-zlib --en
able-bzlib --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libvor
bis --enable-libtheora --enable-libopenjpeg --enable-libfreetype
  libavutil    51. 30. 0 / 51. 30. 0
  libavcodec   53. 40. 0 / 53. 40. 0
  libavformat  53. 24. 0 / 53. 24. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 51. 0 /  2. 51. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '..\..\Videos\Sintel\sintel_trailer-720p
.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    title           : Sintel Trailer
    artist          : Durian Open Movie Team
    encoder         : Lavf52.62.0
    copyright       : (c) copyright Blender Foundation | durian.blender.org
    description     : Trailer for the Sintel open movie project
  Duration: 00:00:52.20, start: 0.000000, bitrate: 1165 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720,
 1033 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 126
 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    :

所以,你可以看到.mp4容器有一个H.264视频编解码器和一个AAC音频编解码器。

So, as you can see this .mp4 container has a H.264 video codec and an AAC audio codec.

这篇关于为什么我不能在openCV中打开avi视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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