C++ : What#39;s the easiest library to open video file(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 链接似乎不起作用(查看错误)
Msdn links seems not to work (see the bug)
推荐答案
目前这些是 Win32 平台上最流行的视频框架:
Currently these are the most popular video frameworks available on Win32 platforms:
Windows 视频:来自 Win95 时代的旧 Windows 框架,但仍被广泛使用,因为它使用起来非常简单.不幸的是,它仅支持安装了适当 VFW 编解码器的 AVI 文件.
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 Media Player可以播放的所有格式.比较难用.
DirectShow: standard WinXP framework, it can basically load all formats you can play with Windows Media Player. Rather difficult to use.
Ffmpeg:更准确地说是 Ffmpeg 开源多媒体实用程序附带的 libavcodec 和 libavformat.它非常强大,可以读取很多格式(几乎所有你可以用 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:Apple 框架不是 Windows 平台的最佳解决方案,因为它需要安装 QuickTime 应用程序以及适合每种格式的 QuickTime 编解码器;它不支持很多格式,但它在专业领域很常见(所以一些编解码器实际上只适用于 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 后端不允许在流中查找.如果您想在 OpenCV 中使用 QuickTime,这个可以帮助您.
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++:打开视频文件最简单的库是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++:打开视频文件最简单的库是什么
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01