当前位置: 首页 > news >正文

ffmpeg草稿

avformat 用于解析容器和协议(protocol)。 avcodec 用于编码和解码基本流(您已经拥有的)。

Qt/C++音视频开发44-本地摄像头推流(支持分辨率/帧率等设置/实时性极高)_feiyangqingyun的博客-CSDN博客

void FFmpegThread::initInputFormat()
{//本地摄像头/桌面录屏if (videoType == VideoType_Camera) {
#if defined(Q_OS_WIN)//ifmt = av_find_input_format("vfwcap");ifmt = av_find_input_format("dshow");
#elif defined(Q_OS_LINUX)//可以打开cheese程序查看本地摄像头(如果是在虚拟机中需要设置usb选项3.1)//ifmt = av_find_input_format("v4l2");ifmt = av_find_input_format("video4linux2");
#elif defined(Q_OS_MAC)ifmt = av_find_input_format("avfoundation");
#endif} else if (videoType == VideoType_Desktop) {
#if defined(Q_OS_WIN)ifmt = av_find_input_format("gdigrab");
#elif defined(Q_OS_LINUX)ifmt = av_find_input_format("x11grab");
#elif defined(Q_OS_MAC)ifmt = av_find_input_format("avfoundation");
#endif}
}bool FFmpegThread::initInput()
{//实例化格式处理上下文formatCtx = avformat_alloc_context();//设置超时回调(有些不存在的地址或者网络不好的情况下要卡很久)formatCtx->interrupt_callback.callback = FFmpegHelper::avinterruptCallBackFun;formatCtx->interrupt_callback.opaque = this;//打开输入(通过标志位控制回调那边做超时判断)//其他地方调用 formatCtx->url formatCtx->filename 可以拿到设置的地址(两个变量值一样)tryOpen = true;QByteArray urlData = VideoHelper::getRightUrl(videoType, videoUrl).toUtf8();int result = avformat_open_input(&formatCtx, urlData.data(), ifmt, &options);tryOpen = false;if (result < 0) {debug("打开出错", "错误: " + FFmpegHelper::getError(result));return false;}//根据自己项目需要开启下面部分代码加快视频流打开速度//开启后由于值太小可能会出现部分视频流获取不到分辨率if (decodeType == DecodeType_Fastest && videoType == VideoType_Rtsp) {//接口内部读取的最大数据量(从源文件中读取的最大字节数)//默认值5000000导致这里卡很久最耗时(可以调小来加快打开速度)formatCtx->probesize = 50000;//从文件中读取的最大时长(单位为 AV_TIME_BASE units)formatCtx->max_analyze_duration = 5 * AV_TIME_BASE;//内部读取的数据包不放入缓冲区//formatCtx->flags |= AVFMT_FLAG_NOBUFFER;//设置解码错误验证过滤花屏//formatCtx->error_recognition |= AV_EF_EXPLODE;}//获取流信息result = avformat_find_stream_info(formatCtx, NULL);if (result < 0) {debug("找流失败", "错误: " + FFmpegHelper::getError(result));return false;}//解码格式formatName = formatCtx->iformat->name;//某些格式比如视频流不做音视频同步(响应速度快)if (formatName == "rtsp" || videoUrl.endsWith(".sdp")) {useSync = false;}//设置了最快速度则不启用音视频同步if (decodeType == DecodeType_Fastest) {useSync = false;}//有些格式不支持硬解码if (formatName.contains("rm") || formatName.contains("avi") || formatName.contains("webm")) {hardware = "none";}//本地摄像头设备解码出来的直接就是yuv显示不需要硬解码if (videoType == VideoType_Camera || videoType == VideoType_Desktop) {useSync = false;hardware = "none";}//过低版本不支持硬解码
#if (FFMPEG_VERSION_MAJOR < 3)hardware = "none";
#endif//获取文件时长(这里获取到的是秒)double length = (double)formatCtx->duration / AV_TIME_BASE;duration = length * 1000;this->checkVideoType();//有时候网络地址也可能是纯音频if (videoType == VideoType_FileHttp) {onlyAudio = VideoHelper::getOnlyAudio(videoUrl, formatName);}if (getIsFile()) {//文件必须要音视频同步useSync = true;//发送文件时长信号emit receiveDuration(duration > 0 ? duration : 0);}QString msg = QString("格式: %1 时长: %2 秒 加速: %3").arg(formatName).arg(duration / 1000).arg(hardware);debug("媒体信息", msg);return true;
}

在线电子书

main入口函数分析—ffplay.c源码分析 · FFmpeg原理

http://www.lryc.cn/news/165774.html

相关文章:

  • 熵 | 无线通信知识
  • 黑马JVM总结(七)
  • Vue3核心语法一
  • 5.11.Webrtc接口的设计原理
  • 2022年09月 C/C++(八级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • Vue3 监听属性-watch
  • JWT安全
  • LabVIEW利用人工神经网络辅助进行结冰检测
  • Linux安装MySQL8.0
  • 【【萌新编写RISCV之前言CPU的部分介绍.3】】
  • dl_model_param
  • Android相机调用-CameraX【外接摄像头】【USB摄像头】
  • 第一个Java程序
  • OpenCV之霍夫变换检测直线
  • lv3 嵌入式开发-11 Linux下GDB调试工具
  • Zabbix监控平台概念
  • 【javaSE】 枚举与枚举的使用
  • NetSuite知识会汇编-管理员篇顾问篇2023
  • 根号分治与多项式的巧妙结合:GYM-104386G
  • 通过FTP高速下载几百G数据
  • cudnn-windows-x86_64-8.6.0.163_cuda11-archive 下载
  • 多线程案例(1) - 单例模式
  • Arduino驱动TCS34725传感器(颜色传感器篇)
  • 知识库网站如何搭建?需要注意这五个要点!
  • 【UE虚幻引擎】UE源码版编译、Andorid配置、打包
  • 树和二叉树的相关概念及结构
  • MySQL安装validate_password_policy插件
  • 数据在内存中的存储——练习3
  • web-案例
  • 第一章 JAVA入门