C ++:什么是最简单的库打开视频文件 [英] C++ : What's the easiest library to open video file

查看:433
本文介绍了C ++:什么是最简单的库打开视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开一个小视频文件并映射内存中的每一帧(应用一些自定义过滤器)。我不想处理视频编解码器,我宁愿让库为我处理。

I would like to open a small video file and map every frames in memory (to apply some custom filter). I don't want to handle the video codec, I would rather let the library handle that for me.

我试图使用Direct Show与SampleGrabber过滤器使用此示例 http://msdn.microsoft.com/en-us/library/ms787867 (VS .85).aspx),但我只设法抓住一些帧(而不是每一帧!)。我在视频软件编程是相当新的,也许我不使用最好的库,或者我做错了。

I've tried to use Direct Show with the SampleGrabber filter (using this sample http://msdn.microsoft.com/en-us/library/ms787867(VS.85).aspx), but I only managed to grab some frames (not every frames!). I'm quite new in video software programming, maybe I'm not using the best library, or I'm doing it wrong.

我已经粘贴了我的部分代码(主要是从msdn示例中修改的副本/粘贴),不幸的是它不会像预期的那样抓住25帧。 ..

I've pasted a part of my code (mainly a modified copy/paste from the msdn example), unfortunately it doesn't grabb the 25 first frames as expected...

[...]

hr = pGrabber->SetOneShot(TRUE);
hr = pGrabber->SetBufferSamples(TRUE);

pControl->Run(); // Run the graph.
pEvent->WaitForCompletion(INFINITE, &evCode); // Wait till it's done.

// Find the required buffer size.
long cbBuffer = 0;
hr = pGrabber->GetCurrentBuffer(&cbBuffer, NULL);

for( int i = 0 ; i < 25 ; ++i )
{
    pControl->Run(); // Run the graph.
    pEvent->WaitForCompletion(INFINITE, &evCode); // Wait till it's done.

    char *pBuffer = new char[cbBuffer];
    hr = pGrabber->GetCurrentBuffer(&cbBuffer, (long*)pBuffer);

    AM_MEDIA_TYPE mt;
    hr = pGrabber->GetConnectedMediaType(&mt);
    VIDEOINFOHEADER *pVih;
    pVih = (VIDEOINFOHEADER*)mt.pbFormat;

    [...]
}

[...]

有视频软件经验的人,谁可以建议我关于代码或其他更简单的库?

Is there somebody, with video software experience, who can advise me about code or other simpler library?

感谢

编辑:
Msdn链接似乎无法正常工作(请参阅bug

推荐答案

目前这些是Win32平台上最流行的视频框架:

Currently these are the most popular video frameworks available on Win32 platforms:


  1. Windows的视频:旧的Windows框架来自Win95的时代,但仍然被广泛使用,因为它使用非常简单。不幸的是它只支持已经安装了正确的VFW编解码器的AVI文件。

  1. Video for Windows: old windows framework coming from the age of Win95 but still widely used because it is very simple to use. Unfortunately it supports only AVI files for which the proper VFW codec has been installed.

DirectShow:标准的WinXP框架,它基本上可以加载所有可以播放的格式Windows媒体播放器。很难使用。

DirectShow: standard WinXP framework, it can basically load all formats you can play with Windows Media Player. Rather difficult to use.

Ffmpeg :更准确地说是libavcodec和libfformat附带的Ffmpeg开源多媒体实用程序。它非常强大,可以读取很多格式(几乎所有你可以使用 VLC ),即使你没有在系统上安装的编解码器。这是非常复杂的使用,但你可以总是得到启发的ffplay的代码附带它或开源软件中的其他实现。无论如何,我认为它仍然比DS更容易使用(和更快)。它需要由Windows上的MinGW连接,但所有步骤都解释得非常好在这里(在这一刻链接

Ffmpeg: more precisely libavcodec and libavformat that comes with Ffmpeg open- source multimedia utility. It is extremely powerful and can read a lot of formats (almost everything you can play with VLC) even if you don't have the codec installed on the system. It's quite complicated to use but you can always get inspired by the code of ffplay that comes shipped with it or by other implementations in open-source software. Anyway I think it's still much easier to use than DS (and much faster). It needs to be comipled by MinGW on Windows, but all the steps are explained very well here (in this moment the link is down, hope not dead).

QuickTime

QuickTime: the Apple framework is not the best solution for Windows platform, since it needs QuickTime app to be installed and also the proper QuickTime codec for every format; it does not support many formats, but its quite common in professional field (so some codec are actually only for QuickTime). Shouldn't be too difficult to implement.

Gstreamer :最新的开源框架。我不太了解它,我想它包装了一些其他系统(但我不知道)。

Gstreamer: latest open source framework. I don't know much about it, I guess it wraps over some of the other systems (but I'm not sure).

除了DirectShow,所有这些框架都在OpenCv Highgui中实现为后端。 Win32 OpenCV的默认框架是使用VFW(因此只能打开一些AVI文件),如果你想使用其他人,你必须下载CVS而不是官方发布,仍然做一些黑客的代码,它还是不是太完整,例如FFMPEG后端不允许在流中寻找。
如果要使用QuickTime with OpenCV,可以帮助您。

All of this frameworks have been implemented as backend in OpenCv Highgui, except for DirectShow. The default framework for Win32 OpenCV is using VFW (and thus able only to open some AVI files), if you want to use the others you must download the CVS instead of the official release and still do some hacking on the code and it's anyway not too complete, for example FFMPEG backend doesn't allow to seek in the stream. If you want to use QuickTime with OpenCV this can help you.

这篇关于C ++:什么是最简单的库打开视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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