FFmpeg读取Mac摄像头的问题
来源:互联网 发布:华南理工网络教育 编辑:程序博客网 时间:2024/06/05 03:24
在这篇文章中讲解了怎么使用FFmpeg读取摄像头,包括Windows,Linux和Mac。经过测试,发现在Mac 下avformat_open_input总是出错,提示Input/Output error。后来发现对于Mac下通过avfoudmation读取摄像头,需要提前设置framerate和video_size。正确的代码如下:
#include <iostream>extern "C" {#include "libavcodec/avcodec.h"#include "libavformat/avformat.h"#include <libavdevice/avdevice.h>}using namespace std;int main(int argc, const char *argv[]) { int ret = 0; int videoStreamIndex = -1; AVFormatContext *s = NULL; AVDictionary *options = NULL; AVCodecParameters *par = NULL; AVCodec *codec; AVCodecContext *cctx; av_register_all(); avdevice_register_all(); AVInputFormat *ifmt = av_find_input_format("avfoundation"); av_dict_set(&options, "framerate", "30", 0); av_dict_set(&options, "video_size", "1280x720", 0); ret = avformat_open_input(&s, "0", ifmt, &options); if (ret < 0) { cout << av_err2str(ret) << endl; goto error; } ret = avformat_find_stream_info(s, NULL); if (ret < 0) { cout << av_err2str(ret) << endl; goto error; } for (uint i = 0; i < s->nb_streams; i++) { if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; break; } } if (-1 == videoStreamIndex) { cout << "can't find video stream" << endl; goto error; } par = s->streams[videoStreamIndex]->codecpar; codec = avcodec_find_decoder(par->codec_id); cctx = avcodec_alloc_context3(codec); avcodec_parameters_to_context(cctx, par); ret = avcodec_open2(cctx, codec, NULL); if (ret < 0) { cout << av_err2str(ret) << endl; goto error; }error: if (s) { avformat_free_context(s); } if (cctx) { avcodec_free_context(&cctx); } if (options) { av_dict_free(&options); } return ret;}
问题是framerate和video_size是怎么来的呢?虽然可以通过list_devices的日志输出可以看到提示,但是在libavdevice(avdevice.h)中定义的一些API,对于avfoundation都是未实现的操作,不能通过avdevice_capabilities_create查询设备的能力参数。
阅读全文
0 0
- FFmpeg读取Mac摄像头的问题
- FFMpeg读取摄像头数据流
- 使用FFmpeg+SDL打开Mac摄像头
- FFmpeg读取摄像头用OpenCV显示
- 读取笔记本的摄像头的原始yuv数据,通过libav(ffmpeg编码)
- 最简单的基于FFmpeg的AVDevice例子(读取摄像头)
- 最简单的基于FFmpeg的AVDevice例子(读取摄像头)
- 最简单的基于FFmpeg的AVDevice例子(读取摄像头)
- 读取笔记本的摄像头的原始yuv数据,通过libav(ffmpeg编码)
- 最简单的基于FFmpeg的AVDevice例子(读取摄像头)
- 最简单的基于FFmpeg的AVDevice例子(读取摄像头)
- jwplayer +ffmpeg+red5 实现摄像头的直播
- 01 ffmpeg对摄像头的调用编程
- ffmpeg学习:ffmpeg下载,播放音频、视频,读取USB摄像头数据流并实时播放
- Mac 下的FFmpeg Install
- mac系统下读取移动硬盘的小问题
- win7系统下用opencv读取摄像头出现的proxytrans.ax问题
- 【OpenCV学习笔记】【函数学习】一(MFC+OpenCV2.4.7读取摄像头之cvCaptureFromCAM()的索引问题
- 欢迎使用CSDN-markdown编辑器
- c++ 使用throw抛出异常
- 机器视觉学习笔记(5)——基于OpenCV的单目摄像机标定
- eclipse中serverRuntime Environment无法添加tomcat
- win10系统磁盘分区
- FFmpeg读取Mac摄像头的问题
- Calico 的网络结构是什么?- 每天5分钟玩转 Docker 容器技术(68)
- python统计指定目录内文件的代码行数
- 51单片机的中断系统(三)
- plist文件追加数据
- planar
- hbase-HA
- Android开发 JDK和SDK简单配置
- 彻底卸载删除mysql及注册表