FFMPEG API:如何清除实时缓冲区?

时间:2018-11-29 10:48:59

标签: ffmpeg

这是我用来访问网络摄像头的c ++代码。

int Camera::Init(char* file_name,
                char* device_name,
                char* format,
                char* resolution,
                char* frame_rate,
                char* pixel_format)
{
    av_log(NULL, AV_LOG_INFO, "---INIT STARTED\n");
    avdevice_register_all();
    av_register_all();

    AVDictionary* properties_collection = NULL;
    av_dict_set(&properties_collection, "f", format, NULL);
    av_dict_set(&properties_collection, "video_size", resolution, NULL);
    av_dict_set(&properties_collection, "framerate", frame_rate, NULL);
    av_dict_set(&properties_collection, "pix_fmt", pixel_format, NULL);
    AVInputFormat *input_format = av_find_input_format("dshow");
    char command_line[256];
    sprintf(command_line, "video=%s", device_name);
    AVFormatContext *input_context = avformat_alloc_context();
    //input_context->flags |= AVFMT_FLAG_NOBUFFER;      //DOESN'T HELP
    //input_context->max_picture_buffer = 0;            //ERR

    int err_code = 0;
    err_code = avformat_open_input(&input_context,
                                    command_line,
                                    input_format,
                                    &properties_collection);
    int i = 0;
    while (i++ < 30)
    {
        Sleep(1000);
        //avformat_flush(input_context); //DOESN'T HELP
        //av_free(input_context); //ERR
    }
    system("pause");
    return 0;
}

紧接在“ avformat_open_input()”之后,它甚至不需要调用“ av_read_frame()”就开始将帧读取到某些内部缓冲区。 大约10秒钟后,它开始给我错误消息:

[dshow @ 0014ed40] real-time buffer [VirtualBox Webcam - FULL HD 1080P Webcam] [video input] 
too full or near too full (62% of size: 3041280 [rtbufsize parameter])! 
frame dropped!
...
...
...
[dshow @ 0014ed40] real-time buffer [VirtualBox Webcam - FULL HD 1080P Webcam] [video input] 
too full or near too full (100% of size: 3041280 [rtbufsize parameter])! 
frame dropped!

如何清除此缓冲区或避免使用它?

谢谢。

P.S。请原谅我的英语。

P.P.S。祝你有美好的一天。

0 个答案:

没有答案