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

ffmpeg-avio实战:打开本地文件或者网络直播流dome

        使用ffmpeg打开打开本地文件或者网络直播流的一个小dome。流程产靠ffmpeg4.x系列的解码流程-CSDN博客

        

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>  
#include <libavformat/avio.h>
#include <libavutil/file.h>
#include <libavutil/dict.h>
#include <stdio.h>
#include <libavutil/error.h>int main()
{const char* url = "/home/yth/ffmpeg_text/videos/elon.mp4";int err = -1;//1.av_register_all();avformat_network_init(); //初始化网络相关的功能,用于处理网络的流媒体printf("hello ffmpeg\n");AVFormatContext* pFormatCtx = NULL; //用于存储媒体文件或流的信息AVInputFormat* piFmt = NULL; //指向输入格式的指针,用于指定打开文件时的格式    printf("helloc, avformat_alloc_context\n");if((pFormatCtx = avformat_alloc_context()) == NULL) //为pFormatCtx分配内存{printf("fail avformat_alloc_context()\n");goto avformat_alloc_context_err;}pFormatCtx->probesize = 5000000;pFormatCtx->max_analyze_duration  = 5000000;//2.printf("打开媒体流\n");//打开本地文件或网络流直播流//替换为实际的rtsp地址 或在文件路径//rtsp地址: rtsp://127.0.0.1:8554/rtsp1//本地文件: ./ymx.mp4err = avformat_open_input(&pFormatCtx, url,  NULL, NULL);if(err < 0){char errbuf[AV_ERROR_MAX_STRING_SIZE];av_strerror(err, errbuf, sizeof(errbuf));fprintf(stderr,"fail avformat_open_input:%s\n",errbuf );goto avformat_open_input_err;}else{printf("open stream success\n"); //成功打开}//3.err = avformat_find_stream_info(pFormatCtx, NULL); //获取流的信息,填充pFormatCtxif(err < 0 ){printf("fail avformat_find_stream_info\n");goto avformat_find_stream_info_err;}else{printf("open stream success\n"); //获取流信息成功printf("有n路流 = %d\n", pFormatCtx->nb_streams);}avformat_find_stream_info_err:avformat_close_input(&pFormatCtx); //关闭输入文件或流
avformat_open_input_err:avformat_network_deinit(); //取消网络流库的初始化
avformat_alloc_context_err:return err;}

        如果是本地文件没有使用 av_register_all(); 打开媒体文件失败,打印失败原因。比如,如果上面没有调用函数av_register_all,则会打印“XXX failed!:Invaliddata found when processing input”.   

        这是代码的实现,我们来执行一下,配合其他工具看看打开的视频流消息是不是对的。

        两路流是正确的。

 

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

相关文章:

  • css预处理器sass
  • VulnHub-Acid(1/100)
  • MATLAB语言的正则表达式
  • 通过 route 或 ip route 管理Linux主机路由
  • MYSQL--------SQL 注入简介MySQL SQL Mode 简介
  • 第6章——HTTP首部
  • 多行输入模式(dquote> 提示符)double quote(双引号)
  • 【什么是MVCC?】
  • HarmonyOS开发:粒子动画应用实战
  • 数据库课设——网上花店销售管理系统(上)
  • 用于AI的 数据存储其获取介绍
  • flutter 专题二十四 Flutter性能优化在携程酒店的实践
  • L28.【LeetCode笔记】移动零(三种解法)
  • jenkins入门10--自动化构建
  • el-table拖拽表格
  • 如何轻松反转C# List<T>中的元素顺序
  • Transformer中Self-Attention以及Multi-Head Attention模块详解(附pytorch实现)
  • 在Nvidia Jetson ADX Orin中使用TensorRT-LLM运行llama3-8b
  • 六十一:HTTP/2的问题及HTTP/3的意义
  • IOS开发如何从入门进阶到高级
  • 非一般的小数:小数的概念新解、小数分类、浮点数的存储
  • 关于游戏销量的思考
  • JuiceFS 详解:一款为云原生设计的高性能分布式文件系统
  • 百度Android面试题及参考答案 (下)
  • RK3588+FPGA全国产异步LED显示屏控制卡/屏幕拼接解决方案
  • Elasticsearch:Query rules 疑难解答
  • 四、VSCODE 使用GIT插件
  • 键盘鼠标共享工具Barrier(kail与windows操作系统)
  • QTcpSocket 中设置接收缓冲区大小
  • Arduino IDE刷微控制器并下载对应固件的原由