企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] 雷神传送门:[https://blog.csdn.net/leixiaohua1020/article/details/39702113](https://blog.csdn.net/leixiaohua1020/article/details/39702113) ## 概述 FFmpeg中有一个和多媒体设备交互的类库:Libavdevice。使用这个库可以读取电脑(或者其他设备上)的多媒体设备的数据,或者输出数据到指定的多媒体设备上。 ## libavdevice使用 使用libavdevice的时候需要包含其头文件: ``` #include "libavdevice/avdevice.h" ``` 然后,在程序中需要注册libavdevice: ``` avdevice_register_all(); ``` 接下来就可以使用libavdevice的功能了。 使用libavdevice读取数据和直接打开视频文件比较类似。因为系统的设备也被FFmpeg认为是一种输入的格式(即AVInputFormat)。使用FFmpeg打开一个普通的视频文件使用如下函数: ``` AVFormatContext *pFormatCtx = avformat_alloc_context(); avformat_open_input(&pFormatCtx, "test.h265",NULL,NULL); ``` 使用libavdevice的时候,唯一的不同在于需要首先查找用于输入的设备。在这里使用av_find_input_format()完成: ``` AVFormatContext *pFormatCtx = avformat_alloc_context(); AVInputFormat *ifmt=av_find_input_format("vfwcap"); avformat_open_input(&pFormatCtx, 0, ifmt,NULL); ``` 上述代码首先指定了vfw设备作为输入设备,然后在URL中指定打开第0个设备(在我自己计算机上即是摄像头设备)。 在Windows平台上除了使用vfw设备作为输入设备之外,还可以使用DirectShow作为输入设备: ``` AVFormatContext *pFormatCtx = avformat_alloc_context(); AVInputFormat *ifmt=av_find_input_format("dshow"); avformat_open_input(&pFormatCtx,"video=Integrated Camera",ifmt,NULL) ; ``` ## 调用摄像头 [https://blog.csdn.net/weixin\_39743893/article/details/80714217](https://blog.csdn.net/weixin_39743893/article/details/80714217) 遇到的问题,就是直接使用引用库就行。在mac上不要使用vcpkg生成的变量${FFMPEG_LIBRARIES} 会造成qt调用obcj的问题。 ``` Undefined symbols for architecture x86\_64: "\_AVMediaTypeAudio", referenced from: \_avf\_read\_header in libavdevice.a(avfoundation.o) "\_AVMediaTypeMuxed", referenced from: \_avf\_read\_header in libavdevice.a(avfoundation.o) "\_AVMediaTypeVideo", referenced from: \_avf\_read\_header in libavdevice.a(avfoundation.o) "\_CGBitmapContextCreate", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_CGColorSpaceCreateWithName", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_CGContextDrawImage", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_CGContextRelease", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_CGGetActiveDisplayList", referenced from: \_avf\_read\_header in libavdevice.a(avfoundation.o) "\_CGImageGetHeight", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_CGImageGetWidth", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_CGLGetCurrentContext", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_NSRectFromString", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_NSUndefinedKeyException", referenced from: \_avf\_read\_header in libavdevice.a(avfoundation.o) \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_AVCaptureAudioDataOutput", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_AVCaptureDevice", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_AVCaptureDeviceInput", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_AVCaptureScreenInput", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_AVCaptureSession", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_AVCaptureVideoDataOutput", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_CIColor", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_CIContext", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_CIFilter", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_CIImage", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_CIVector", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_NSAutoreleasePool", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) "\_OBJC\_CLASS\_$\_NSNumber", referenced from: objc-class-ref in libavdevice.a(avfoundation.o) objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_NSOpenGLPixelFormat", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_OBJC\_CLASS\_$\_NSString", referenced from: objc-class-ref in libavfilter.a(vf\_coreimage.o) "\_SDL\_CreateTexture", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_CreateWindowAndRenderer", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_DestroyRenderer", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) \_sdl2\_write\_packet in libavdevice.a(sdl2.o) \_sdl2\_write\_trailer in libavdevice.a(sdl2.o) "\_SDL\_DestroyTexture", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) \_sdl2\_write\_packet in libavdevice.a(sdl2.o) \_sdl2\_write\_trailer in libavdevice.a(sdl2.o) "\_SDL\_DestroyWindow", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) \_sdl2\_write\_packet in libavdevice.a(sdl2.o) \_sdl2\_write\_trailer in libavdevice.a(sdl2.o) "\_SDL\_GetError", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_Init", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_PollEvent", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_Quit", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) \_sdl2\_write\_packet in libavdevice.a(sdl2.o) \_sdl2\_write\_trailer in libavdevice.a(sdl2.o) "\_SDL\_RenderClear", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_RenderCopy", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_RenderPresent", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_SetWindowPosition", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_SetWindowTitle", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_ShowWindow", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_SDL\_UpdateTexture", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_UpdateYUVTexture", referenced from: \_sdl2\_write\_packet in libavdevice.a(sdl2.o) "\_SDL\_WasInit", referenced from: \_sdl2\_write\_header in libavdevice.a(sdl2.o) "\_kCGColorSpaceGenericRGB", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIAttributeClass", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIAttributeDefault", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIAttributeSliderMax", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIAttributeSliderMin", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIAttributeType", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCICategoryGenerator", referenced from: \_init in libavfilter.a(vf\_coreimage.o) "\_kCIFormatARGB8", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_kCIInputImageKey", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) "\_kCIOutputImageKey", referenced from: \_apply\_filter in libavfilter.a(vf\_coreimage.o) ld: symbol(s) not found for architecture x86\_64 ``` ## Video codec rawvideo not compatible with flv 在mac上捕获不到摄像头,捕获屏幕,然后推流出现的错误。 原因 文件使用的视频格式是 rawvideo, 这个太新了,由于flv 已经不更新了,所以不能在 flv文件中写入 rawvideo格式的视频。你转成  flv文件之所以可以推流是因为在转格式的时候 视频格式也发生了变化,就成了flv可以支持的视频格式,所以才能推流成功。