FFMPEG Set Webcam Encoder C++
I'm trying to capture a webcam stream using the FFMPEG C API in windows. I can do what I want using the following command line options:
ffmpeg -f dshow -vcodec mjpeg -s 1280x720 -framerate 30 -i video=HX-A1:audio="Microphone (HX-A1)" outputFile.mpg
I've started out with the transcoding.c example and got it working for recording a virtual webcam like screen-capture-recorder. However, I need to set the encoder options for my real webcam because it defaults to 160x120 raw video, and I'd prefer a higher resolution. I'm trying the following to set the camera encoder options but it doesn't appear to be doing anything.
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 filen");
return ret;
}
Is there another way to set input options to tell the camera what codec to use as done in my command line example?
解决了,我必须首先启动我的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);
链接地址: http://www.djcxy.com/p/81082.html
上一篇: 虚拟摄像头驱动程序
下一篇: FFMPEG设置摄像头编码器C ++