如何避免不支持的帧速率错误?

hyp*_*rum 5 c camera ffmpeg d frame-rate

我在Macbook上,我正在尝试使用ffmpeg库从相机中读取视频.相机是一个10米的USB水下相机.我通过名为ffmpeg-d的D绑定使用C API.但是,在尝试打开输入时,我得到了:

[avfoundation @ 0x7fe0d2800000] Selected framerate (29.970030) is not supported by the device
[avfoundation @ 0x7fe0d2800000] Supported modes:
[avfoundation @ 0x7fe0d2800000]   160x120@[30.000030 30.000030]fps
[avfoundation @ 0x7fe0d2800000]   176x144@[30.000030 30.000030]fps
[avfoundation @ 0x7fe0d2800000]   320x240@[30.000030 30.000030]fps
[avfoundation @ 0x7fe0d2800000]   352x288@[30.000030 30.000030]fps
[avfoundation @ 0x7fe0d2800000]   640x480@[30.000030 30.000030]fps
Run Code Online (Sandbox Code Playgroud)

那我怎么能避免这个问题呢?手动设置帧率是答案吗?如果是这样,我怎么能这样做?

这是一个非常简短的程序来复制我的问题.

import std.stdio;

import ffmpeg.libavdevice.avdevice;
import ffmpeg.libavcodec.avcodec;
import ffmpeg.libavformat.avformat;
import ffmpeg.libavfilter.avfilter;
import ffmpeg.libavutil.avutil;
import ffmpeg.libavutil.mem;
import ffmpeg.libavutil.pixfmt;
import ffmpeg.libswscale.swscale;

import std.string;

void main()
{
    av_register_all();
    avdevice_register_all();

    string           cameraSource        = "USB";

    AVCodecContext*  cameraCodecContext  = null;
    AVFormatContext* cameraFormatContext = avformat_alloc_context();
    AVCodec*         cameraCodec         = null;
    AVInputFormat*   cameraFormat        = av_find_input_format("avfoundation");
    AVFrame*         rawFrame = null, convertedFrame = null;

    if (avformat_open_input(&cameraFormatContext, cameraSource.toStringz, cameraFormat, null) != 0) return;
}
Run Code Online (Sandbox Code Playgroud)

Ilj*_*ilä 6

我对D或使用的库没有任何经验,但我可以指出你正确的方向.你应该AVDictionary** options转到 avformat_open_input

options 一个填充了AVFormatContextdemuxer-private选项的字典.返回时,此参数将被销毁并替换为包含未找​​到选项的dict.可能是NULL.

对我来说,似乎该字典的结构遵循命令行选项几乎一对一,所以你应该在键"framerate"下添加值"30".