FFMPEG类库打开流媒体的方法(需要传参数的时候)
使用ffmpeg类库进行开发的时候,打开流媒体(或本地文件)的函数是avformat_open_input()。
其中打开网络流的话,前面要加上函数avformat_network_init()。
一般情况下,只要传入流媒体的url就可以了。但是在打开某些流媒体的时候,可能需要附加一些参数。
例如在播放中央人民广播电台的声音信号的时候,其url为“rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==”
如果直接进行打开是不会成功的,我们可以使用ffplay做一下实验:
ffplay rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==
会出现错误:
Invalid data found when processing input
这时候我们需要指定其传输方式为TCP,需要将命令改为如下形式:
ffplay -rtsp_transport tcp rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==
附加了参数以后,发现就可以正常播放了。
此外还可以附加一些参数,比如
ffplay -rtsp_transport tcp -max_delay 5000000 rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==
在使用FFMPEG类库进行编程的时候,如何将这些附加的参数传递给avformat_open_input()呢?经过研究后发现,可以通过AVDictionary把参数传给avformat_open_input()。
看一下avformat_open_input()的定义:
/*** Open an input stream and read the header. The codecs are not opened.* The stream must be closed with av_close_input_file().** @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).* May be a pointer to NULL, in which case an AVFormatContext is allocated by this* function and written into ps.* Note that a user-supplied AVFormatContext will be freed on failure.* @param filename Name of the stream to open.* @param fmt If non-NULL, this parameter forces a specific input format.* Otherwise the format is autodetected.* @param options A dictionary filled with AVFormatContext and demuxer-private options.* On return this parameter will be destroyed and replaced with a dict containing* options that were not found. May be NULL.** @return 0 on success, a negative AVERROR on failure.** @note If you want to use custom IO, preallocate the format context and set its pb field.*/
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
可以看出avformat_open_input()的第4个参数是一个AVDictionary类型的参数。这个参数就是传入的附加参数。
设置AVDictionary的时候会用到av_dict_set()。
下面看看把命令
ffplay -rtsp_transport tcp -max_delay 5000000 rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==
转化为代码实现的方式:
AVFormatContext *pFormatCtx;
pFormatCtx = avformat_alloc_context();
...代码略
AVDictionary *avdic=NULL;
char option_key[]="rtsp_transport";
char option_value[]="tcp";
av_dict_set(&avdic,option_key,option_value,0);
char option_key2[]="max_delay";
char option_value2[]="5000000";
av_dict_set(&avdic,option_key2,option_value2,0);
char url[]="rtsp://mms.cnr.cn/cnr003?MzE5MTg0IzEjIzI5NjgwOQ==";avformat_open_input(&pFormatCtx,url,NULL,&avdic);
FFMPEG类库打开流媒体的方法(需要传参数的时候)相关推荐
- repeater上EVAL绑定后台方法并且传参数
如果实在不行 就在后台定义一个方法 public string getTags(string str) { string[] strs = str.Split(','); .... ...
- windowopen传值到jsp_window.open()使用方法以及传参数的问题总结
") OpenWindow.document.write(" Hello! ") OpenWindow.document.write("New window o ...
- Android开发之APP唤醒小程序,打开小程序,调起小程序以及传参数的实现方法(附加源码)
老套路咱们先看效果图: 可以先看下官方文档介绍:微信官方文档APP打开小程序链接 我这边打开了,上面奔溃是因为模拟器不兼容的原因: 主要讲解下打开小程序核心代码: // 填应用AppIdString ...
- ffmpeg处理RTMP流媒体的命令 发送流媒体的命令(UDP,RTP,RTMP)
将文件当做直播送至live ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName re限制输出速率,按照 ...
- 使用FFmpeg下载M3U流媒体
使用FFmpeg下载M3U流媒体 安装: 编译好的windows可用版本的下载地址(官网中可以连接到这个网站,和官方网站保持同步): http://ffmpeg.zeranoe.com/builds/ ...
- FFmpeg 代码实现流媒体推流(RTSP)
实时录屏并把视频推流到RTSP服务器,具体流程是抓取屏幕内容(bitmap),并把bitmap转化为YUV,接着把YUV编码成H264,再把H264码流推到RTSP服务器:把采集到的PCM编码为AAC ...
- mysql php gpl_MySQL_MySQL数据库远程访问权限如何打开(两种方法),下载GPL版本安装MySQL Community - phpStudy...
MySQL数据库远程访问权限如何打开(两种方法) 下载GPL版本安装 MySQL Community Edition(GPL) Community (GPL) Downloads » 在我们使用mys ...
- 两种方法上传本地文件到github
自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的原因是我习惯本地编辑,完成以后再一起上传github.看过了几个教程,总结出最 ...
- JS打开摄像头并截图上传
直入正题,JS打开摄像头并截图上传至后端的一个完整步骤 1. 打开摄像头主要用到getUserMedia方法,然后将获取到的媒体流置入video标签 2. 截取图片主要用到canvas绘图,使用dra ...
最新文章
- 3.request response
- cameraraw面板大小调整_Camera Raw基础操作面板介绍
- MFC添加背景图片方法
- pyQt显示系统文件目录
- Kazrog AmpCraft 1992 for Mac - 放大器建模插件
- 系统架构升级建议书(1)
- Win10 PSCAD4.5安装心路历程Mark
- VS2010-MFC(常用控件:标签控件Tab Control 上)
- Java反射机制的大厂面试题
- 一次完整的 RPC 流程
- 微信红包在微信公账号平台如何进行配置
- 基于MATLA的图像复原系统
- 微信使用技巧 - 收集整理
- C语言实现哈夫曼树求解及其编码输出
- Win7虚拟机安装vs2019,亲测有效
- excel数据透视表总结
- 傅盛:最可怕的不是把事情做差,而是越做越好后被淘汰
- Unity技术手册 - 生命周期LifetimebyEmitterSpeed-周期内颜色ColorOverLifetime-速度颜色ColorBySpeed
- 2.液晶显示屏结构简介
- expand linux,整理一下linux系统expand 命令