【问题标题】:How to capture camera devices on Windows using Libav?如何使用 Libav 在 Windows 上捕获相机设备?
【发布时间】:2011-11-22 20:13:10
【问题描述】:

有没有什么方法可以像 DirectShow 一样在 Windows 平台上使用 Libav 从多种相机类型中捕获帧?我需要在不使用 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 支持的设备太少。也许现在情况已经改变,它确实支持足够的设备在生产应用程序中使用它?

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

【问题讨论】:

  • 对于那些感兴趣的人,有一个名为“libvidcap”的独立跨平台库,用于处理视频捕获。您可以在sourceforge 上查看。

标签: c++ windows ffmpeg video-capture libav


【解决方案1】:

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

【讨论】:

  • 我上面写的代码证明它是部分可能的。我想知道有多少设备可以使用这种方法。至于 DircetShow,我们在一个应用程序中使用它以及 libav。但如果可以通过 Libav 实现,我会在没有 DirectShow 的情况下这样做。
  • TBH 我以前从未见过这种方法。看起来它是传统的 Video For Windows 方法。
  • 看起来你是对的。使用如此古老的技术从新的相机设备上进行捕捉似乎很危险。
  • 这个答案不再正确。
猜你喜欢
  • 1970-01-01
  • 2011-09-03
  • 1970-01-01
  • 2014-12-03
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多