1

有什么方法可以使用 Libav 在 Windows 平台上捕获与 DirectShow 一样多的相机类型的帧?我需要在不使用 DirectShow 过滤器的情况下捕获相机输出,并且我希望我的应用程序可以与许多相机设备类型一起使用。

我在网上搜索了 libav 的这个功能,发现可以通过 libav 使用特殊的输入格式“vfwcap”来完成。类似的东西(不确定代码的正确性 - 我自己写的):

AVFormatParameters formatParams = NULL;
AVInputFormat* pInfmt = NULL;
pInFormatCtx*  pInFormatCtx = NULL;

av_register_all();

//formatParams.device = NULL; //this was probably deprecated and then removed
formatParams.channel = 0;
formatParams.standard = "ntsc"; //deprecated too but still available
formatParams.width = 640;
formatParams.height = 480;
formatParams.time_base.num = 1000;
formatParams.time_base.den = 30000; //so we want 30000/1000 = 30 frames per second
formatParams.prealloced_context = 0;


pInfmt = av_find_input_format("vfwcap");
if( !pInfmt )
{
  fprintf(stderr,"Unknown input format\n");
  return -1;
}

// Open video file (formatParams can be NULL for autodetecting probably)
if (av_open_input_file(&pInFormatCtx, 0, pInfmt, 0, formatParams) < 0)
   return -1; // Couldn't open device

/* Same as video4linux code*/

那么另一个问题是:Libav 支持多少设备?我所发现的关于在 Windows 上使用 libav 捕获相机输出的所有信息都是建议为此目的使用 DirectShow,因为 libav 支持的设备太少。也许现在情况已经发生了变化,它确实支持足够的设备在生产应用程序中使用它?

如果这是不可能的.. 好吧,我希望我的问题不会是无用的,并且由不同来源的代码组成的这段代码将帮助对这个主题感兴趣的人,因为在整个互联网上关于它的信息真的太少了。

4

1 回答 1

2

FFMPEG 无法在 Windows 上捕获视频。一旦我不得不自己实现这个,使用 DirectShow 捕获

于 2011-09-22T13:27:16.960 回答