通过帧视频德codeR库结构简单 [英] Simple frame by frame video decoder library
问题描述
我在寻找一个简单的C / C ++的lib,允许提取视频的第一帧作为UCHAR数组。并有一个简单的fonction进入下一个。
I'm looking for a simple c/c++ lib that would allow to extract the first frame of a video as a uchar array. And have a simple fonction to access the next one.
我知道的ffmpeg但它requiere用包之类的东西玩,我很惊讶,没有一个地方在网络上我能找到一个lib,允许这样的:
I know of FFMPEG but it requiere to play with packet and things like that, and i'm surprised that nowhere on the net i can find a lib that allow something like :
视频V = openVideo(路径);
UCHAR *数据= v.getFrame();
v.nextFrame();
Video v = openVideo("path"); uchar* data = v.getFrame(); v.nextFrame();
我只需要提取视频帧使用它作为纹理...无需后或任何重新编码...
I just need to extract frames of a video to use it as a texture...no need for reencoding after or anything...
当然东西会比读尽可能最格式将是巨大的,在东西libav codeC内置例如,P
of course something that would read the most format than possible would be great, something built upon libavcodec for example ;p
和我使用Windows 7
And i'm using Windows 7
谢谢!
推荐答案
下面是用OpenCV的一个例子:
Here's an example with OpenCV:
#include <cv.h>
#include <highgui.h>
int
main(int argc, char **argv)
{
cv::VideoCapture capture(argv[1]);
if (capture.grab())
{
cv::Mat_<char> frame;
capture.retrieve(frame);
//
// Convert to your byte array here
//
}
return 0;
}
这是未经测试,但我拆解它从一些现有的工作code,所以它不应该带你长得到它的工作。
It's untested, but I cannibalized it from some existing working code, so it shouldn't take you long to get it working.
的 CV :: Mat_&LT; unsigned char型&GT;
本质上是一个字节数组。如果您真的需要的东西,这是明确键入无符号字符*
,那么你可以MALLOC适当大小的空间,并采用了矩阵迭代
The cv::Mat_<unsigned char>
is essentially a byte array. If you really need something that's explicitly of type unsigned char *
, then you can malloc space of the appropriate size and iterate over the matrix using
您可以转换 CV ::垫
来使用像素位置(一个字节数组 CV ::垫_ ::在()
)或迭代器( CV ::垫_ ::开始()
和朋友)。
You can convert a cv::Mat
to a byte array using pixel positions(cv::Mat_::at()
) or iterators (cv::Mat_::begin()
and friends).
有很多原因,很少库暴露图像数据作为一个简单的指针,如:
There are many reasons why libraries rarely expose image data as a simple pointer, such as:
- 这意味着整个图像必须占用一个连续内存空间。这是一个大问题,大的图片的时候
- 它要求提交的数据的某一排序(像素与非平面? - 是将RGB平面存储穿插或分开),并降低了灵活性
- 取消引用指针是错误(缓冲区溢出等)的原因。
- It implies the entire image must occupy a contiguous space in memory. This is a big deal when dealing with large images
- It requires committing a certain ordering of the data (pixel vs non-planar -- are the RGB planes stored interspersed or separately?) and reduces flexibility
- Dereferencing pointers is a cause for bugs (buffer overruns, etc).
所以,如果你希望你的指针,你必须做一些工作吧。
So if you want your pointer, you have to do a bit of work for it.
这篇关于通过帧视频德codeR库结构简单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!