我尝试在 Android 环境中使用 ffmpeg c++ 打开后置摄像头:
AVFormatContext* formatCtx = avformat_alloc_context();
volatile int x = avformat_open_input(&formatCtx, "android_camera", NULL, NULL);
//x is always -2
很难找到有关 android_camera 的任何信息。你有什么想法可能是错的吗?
我主要错过了两件事:
avdevice_register_all();
还有
av_find_input_format("android_camera");
现在工作代码如下所示:
AVFormatContext* formatCtx = avformat_alloc_context();
avdevice_register_all();
const AVInputFormat *inputFmt = av_find_input_format("android_camera");
avformat_open_input(&formatCtx, NULL, inputFmt, NULL);