博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ffmpeg-设置推流,拉流使用的协议类型(TCP/UDP)
阅读量:4072 次
发布时间:2019-05-25

本文共 1165 字,大约阅读时间需要 3 分钟。

如有错误,请指正,谢谢。

拉流(设置TCP/UDP)

//设置参数AVDictionary *format_opts = NULL;av_dict_set(&format_opts, "stimeout", std::to_string( 2* 1000000).c_str(), 0); //设置链接超时时间(us)av_dict_set(&format_opts, "rtsp_transport",  "tcp", 0); //设置推流的方式,默认udp。//初始化输入上下文AVFormatContext * m_InputContext = avformat_alloc_context();//打开输入流。avformat_open_input(&m_InputContext, "rtsp://127.0.0.1:554/", NULL, &format_opts);// ......

推流(设置TCP/UDP)

//初始化输出流上下文。AVFormatContext * output_format_context_ = NULL;avformat_alloc_output_context2(&output_format_context_, NULL, "rtsp", "rtsp://127.0.0.1:554/");/*    添加流信息    //TODO*///设置参数,设置为TCP推流, 默认UDPAVDictionary *format_opts = NULL;av_dict_set(&format_opts, "stimeout", std::to_string(2 * 1000000).c_str(), 0);av_dict_set(&format_opts, "rtsp_transport", "tcp", 0);//写入输出头(建立rtsp连接)avformat_write_header(output_format_context_, &format_opts);while(1){    AVPakcet media_pkt;    /*        初始化PKT,        读取数据,        填充数据,    */    //发送数据, 多个流时需要使用 av_interleaved_write_frame, 另附ret部分错误码,见其他文章。    int ret = av_interleaved_write_frame(output_format_context_, &media_pkt);    //释放数据    av_packet_unref(&media_pkt);    av_free_packet(&media_pkt);}

欢迎转载:

你可能感兴趣的文章
利用HTTP Cache来优化网站
查看>>
利用负载均衡优化和加速HTTP应用
查看>>
消息队列设计精要
查看>>
分布式缓存负载均衡负载均衡的缓存处理:虚拟节点对一致性hash的改进
查看>>
分布式存储系统设计(1)—— 系统架构
查看>>
MySQL数据库的高可用方案总结
查看>>
常用排序算法总结(一) 比较算法总结
查看>>
SSH原理与运用
查看>>
SIGN UP BEC2
查看>>
S3C2440中对LED驱动电路的理解
查看>>
《天亮了》韩红
查看>>
Windows CE下USB摄像头驱动开发(以OV511为例,附带全部源代码以及讲解) [转]
查看>>
出现( linker command failed with exit code 1)错误总结
查看>>
iOS开发中一些常见的并行处理
查看>>
iOS获取手机的Mac地址
查看>>
ios7.1发布企业证书测试包的问题
查看>>
如何自定义iOS中的控件
查看>>
iOS 开发百问
查看>>
Mac环境下svn的使用
查看>>
github简单使用教程
查看>>