繁体   English   中英

FFMPEG设置网络摄像头编码器C ++

[英]FFMPEG Set Webcam Encoder C++

我正在尝试使用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示例开始,并使其可用于记录屏幕捕获记录器等虚拟网络摄像头。 但是,我需要为我的真实网络摄像头设置编码器选项,因为它默认为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;
}

有没有其他方法可以设置输入选项,以告诉摄像机使用与我的命令行示例相同的编解码器?

解决了,我必须先初始化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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM