我正在使用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
那么我该如何避免这个问题呢?手动设置帧率会是答案吗?如果是,我该如何做到呢?
这里有一个非常简短的程序可以复制我的问题。
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;
}
ffmpeg -f avfoundation -video_size 640x480 -framerate 30 -i "USB" out.png
可行。如何在API中复制它? - hpm