gpt4 book ai didi

c++ - 用 C 编写的 ffmpeg 程序,无法在 macOS Catalina 10.15.7 中打开我的相机

转载 作者:行者123 更新时间:2023-12-04 23:01:18 30 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"

AVFormatContext* openCamera(void) {
avdevice_register_all();
AVFormatContext *ctx = avformat_alloc_context();
AVInputFormat *ifmt = av_find_input_format("avfoundation");
if (ifmt != NULL) {
AVDictionary *opts = NULL;
av_dict_set(&opts, "video_size", "1280x720", 0);
av_dict_set(&opts, "framerate", "30", 0);
av_dict_set(&opts, "pixel_format", "uyvy422", 0);

int ret = avformat_open_input(&ctx, "0", ifmt, &opts);
if (ret != 0) {
printf("no");
avformat_free_context(ctx);
return NULL;
}
}
return ctx;
}

int main(int argc, const char *argv[]) {
openCamera();
}

我的代码在 Xcode 上运行。添加 plist 文件后,正在运行的程序摄像头会打开大约半秒钟,然后关闭。和控制台输出
2022-02-22 00:39:19.372178+0800 ffmpeg-tool[5977:195724] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x10640cf60> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2022-02-22 00:39:19.434783+0800 ffmpeg-tool[5977:195724] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2022-02-22 00:39:19.435262+0800 ffmpeg-tool[5977:195724] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2022-02-22 00:39:19.501780+0800 ffmpeg-tool[5977:195724] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x10640f860> 30010C1C-93BF-11D8-8B5B-000A95AF9C6A
2022-02-22 00:39:19.605797+0800 ffmpeg-tool[5977:195724] Metal API Validation Enabled
2022-02-22 00:39:21.701071+0800 ffmpeg-tool[5977:195724] [] CMIOHardware.cpp:917:CMIODeviceStopStream the System is exiting
2022-02-22 00:39:21.701268+0800 ffmpeg-tool[5977:195724] [] CMIOHardware.cpp:1332:CMIOStreamCopyBufferQueue the System is exiting
2022-02-22 00:39:21.701538+0800 ffmpeg-tool[5977:195724] [] CMIOHardware.cpp:333:CMIOObjectGetPropertyData the System is exiting
2022-02-22 00:39:21.701767+0800 ffmpeg-tool[5977:195724] [] CMIO_DALA_System.cpp:264:GetPropertyData error 1970171760 (unop) getting property selector (inot) scope (glob) element 0
2022-02-22 00:39:21.702472+0800 ffmpeg-tool[5977:195724] [] CMIOHardware.cpp:333:CMIOObjectGetPropertyData the System is exiting
2022-02-22 00:39:21.702662+0800 ffmpeg-tool[5977:195724] [] CMIO_DALA_System.cpp:264:GetPropertyData error 1970171760 (unop) getting property selector (inot) scope (glob) element 0
Program ended with exit code: 0
我怎么解决这个问题?

最佳答案

从您发布的代码看来,它所做的只是打开相机,然后返回主程序,程序完成后它将退出并关闭连接。如果您想保持连接打开并从相机读取数据,您可能希望开始循环读取数据包。

关于c++ - 用 C 编写的 ffmpeg 程序,无法在 macOS Catalina 10.15.7 中打开我的相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71210124/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com