問(wèn)題描述
我剛剛用openCV2.3.1寫了一個(gè)簡(jiǎn)單的視頻閱讀例子,但是好像無(wú)論如何都打不開(kāi)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!
"
做了斷點(diǎn),發(fā)現(xiàn)每次都停在這里.那么為什么avi視頻打不開(kāi)呢?謝謝!
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)
確保視頻文件實(shí)際上與應(yīng)用程序位于同一文件夾中(我假設(shè)您已經(jīng)嘗試過(guò)),否則指定絕對(duì)路徑.
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,您可能需要一個(gè)編解碼器包來(lái)讀取視頻文件(例如,K-Lite Codec打包).
正如 Macmade 所建議的,AVI 只是一個(gè)容器,可以容納不同的音頻、視頻甚至隱藏式字幕編解碼器.此外,這里是 Zeranoe 的 Windows FFmpeg 構(gòu)建.如果您執(zhí)行以下操作,您可以獲得有關(guān)文件編解碼器內(nèi)容的更多信息:
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
您應(yīng)該會(huì)看到如下所示的輸出:
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 :
因此,如您所見(jiàn),此 .mp4 容器具有 H.264 視頻編解碼器和 AAC 音頻編解碼器.
So, as you can see this .mp4 container has a H.264 video codec and an AAC audio codec.
這篇關(guān)于為什么我不能在 openCV 中打開(kāi) avi 視頻?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!