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

标签 c++ windows ffmpeg

我正在尝试使用 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);

关于c++ - FFMPEG 设置网络摄像头编码器 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33266560/

相关文章:

c++ - 错误 : the application was unable to start correctly

video - 如何使用 FFMPEG 获得最佳的总体 FLV 质量?

audio - 使用ffmpeg转换多文件夹中的多文件

c++ - 在 C++ 中交换数组值

c++ - Cocos2d-x 如何启用/禁用 ccTouchMoved 事件?

c++ - 通用 lambda 的编译器推导类型

opencv - 使用 ffmpeg、OpenCV 的硬件加速 h264 解码

C++/Lua : Implement Qt/QtLua with QWebView

windows - 如何修复 Matlab 中 10800x10800 矩阵的内存不足错误?

c# - 如何在用户注销或关闭 Windows 时延迟关闭应用程序?