【问题标题】:FFMPEG Set Webcam Encoder C++FFMPEG 设置网络摄像头编码器 C++
【发布时间】:2015-10-21 18:24:15
【问题描述】:

我正在尝试在 Windows 中使用 FFMPEG C API 捕获网络摄像头流。我可以使用以下命令行选项做我想做的事:

ffmpeg -f dshow -vcodec mjpeg -s 1280x720 -framerate 30 -i video=HX-A1:audio="Microphone (HX-A1)" outputFile.mpg

我从 transcoding.c 示例开始,并让它用于录制像 screen-capture-recorder 这样的虚拟网络摄像头。但是,我需要为我的真实网络摄像头设置编码器选项,因为它默认为 160x120 原始视频,而且我更喜欢更高的分辨率。我正在尝试以下设置相机编码器选项,但它似乎没有做任何事情。

AVDictionary *opt = NULL;
av_dict_set(&opt, "vcodec", "mjpeg", 0);
av_dict_set(&opt, "s", "1280x720", 0);
av_dict_set(&opt, "framerate", "30", 0);
if ((ret = avformat_open_input(&ifmt_ctx, filename, inputFormat, &opt)) < 0) {
    av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
    return ret;
}

是否有另一种方法来设置输入选项来告诉相机使用什么编解码器,就像我在命令行示例中所做的那样?

【问题讨论】:

    标签: c++ windows ffmpeg


    【解决方案1】:

    已解决,我必须先初始化我的 AVFormatContext,然后打开 MJPEG 解码器,并在打开之前设置 AVFormatContext 的视频解码器和编解码器 ID。

    AVDictionary* dictionary = NULL;
    av_dict_set(&dictionary, "video_size", "1280x720", NULL);
    av_dict_set(&dictionary, "framerate", "30", NULL);
    
    ifmt_ctx = avformat_alloc_context();
    ifmt_ctx->video_codec_id = AV_CODEC_ID_MJPEG;
    av_format_set_video_codec(ifmt_ctx, opened_mjpeg_codec);
    
    avformat_open_input(&ifmt_ctx, filename, inputFormat, &dictionary);
    

    【讨论】:

    • 截至 2021 年,对于 ffmpeg 版本 4.3.2,这仍然是一个非常有用的答案。 'vcodec' 选项在命令行上确实有效,但在 avformat_open_input 中作为字典选项提供时无效。在格式上下文上显式设置 video_codec_id 似乎仍然是唯一可行的解​​决方案。
    猜你喜欢
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2010-10-20
    • 2015-05-26
    • 2013-08-12
    • 1970-01-01
    相关资源
    最近更新 更多