为什么我不能在 openCV 中打开 avi 视频?

Why can#39;t I open avi video in openCV?(为什么我不能在 openCV 中打开 avi 视频?)

本文介绍了为什么我不能在 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!
";
    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();

我在std::cout<<"cannot read video! " 做了断点,发现每次都停在这里.那么为什么avi视频打不开呢?谢谢!

I made a breakpoint in std::cout<<"cannot read video! " 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打包).

正如 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 '....VideosSintelsintel_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 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为什么我不能在 openCV 中打开 avi 视频?

基础教程推荐