Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid an unsupported frame rate error?

I am on a Macbook and I am trying to read video from a camera using the ffmpeg library. The camera is a 10 meter USB underwater camera. I am using the C API through a D binding called ffmpeg-d. However, upon trying to open the input, I get this:

[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

So how can I avoid this problem? Would setting the framerate manually be the answer? And if so, how could I do that?

Here is a really short program to replicate my problem.

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;
}
like image 986
hpm Avatar asked Apr 04 '16 08:04

hpm


1 Answers

I have no experience at all with D or the libraries in use, but I can point you in the right direction. You should pass AVDictionary** options to avformat_open_input

options A dictionary filled with AVFormatContext and demuxer-private options. On return this parameter will be destroyed and replaced with a dict containing options that were not found. May be NULL.

To me it seems that the structure of that dictionary follows the command line options pretty much 1-to-1, so you should add the value "30" under the key "framerate".

like image 103
Ilja Everilä Avatar answered Oct 03 '22 20:10

Ilja Everilä