ffmpeg拉流rtmp音频实时数据有延时的解决方法
2017-10-13 15:44
85 查看
最近在做一个从rtmp服务器中拉流音频实时数据会延迟播放的问题,从rtmp播放端<拉流音频数据端>发现,是探测时间太长了,超过了5s,播放数据就延迟播放了5second,
卡在了这个函数:avformat_find_stream_info(),我通过ffplay的以下命令可以解决播放延时的问题:
参考网址:http://blog.csdn.net/cai6811376/article/details/52637158
使用ffplay播放视频源时,rtsp/rtmp等,会有一定的延时,这里我们可以通过设置ffplay播放参数将延时控制到最小。
ffplay.exe -i rtmp://xxxxxxx -fflags nobuffer
减少缓冲
也可以减少分析码流的时间
ffplay.exe -i rtmp://xxxxxxx -analyzeduration 1000000
码流分析时间设置,单位为微秒
RTSP低延时播放:
ffplay.exe -i rtsp://xxx -fflags nobuffer -analyzeduration 1000000 -rtsp_transport tcp
通过代码可以通过如下方式设置:
在使用ffmpeg播放网络流中,在执行到avformat_stream_info函数会阻塞5秒左右,这样造成播放等待时间过长,影响
用户体验,经试验,修改函数里面AVFormatContext参数,probesize和max_analyze_duration值大小
通过AVDictionary来改变AVFormatContext结构体里参数。
AVDictionary * avdic = NULL;
av_dict_set(&avdic,"probesize","2048",0);
av_dict_set(&avdic,"max_analyze_duration","1000",0);
avforamt_open_input(&pFormatCtx,url, NULL, &avdic);
avformat_find_stream_info(pFormatCtx, NULL);
我的实际代码如下:
AVDictionary* pOptions = NULL;
pFormatCtx->probesize = 1 *1024;
pFormatCtx->max_analyze_duration = 1 * AV_TIME_BASE;
// Retrieve stream information
if(avformat_find_stream_info(pFormatCtx,&pOptions)<0)
{
printf("Couldn't find stream information.\n");
return -1;
}以下代码也是可以的:
AVDictionary * avdic = NULL;
av_dict_set(&avdic,"probesize","2048",0);
av_dict_set(&avdic,"max_analyze_duration","10",0);
avformat_open_input(&pFormatCtx,url, NULL, &avdic);
avformat_find_stream_info(pFormatCtx, NULL);
这样就不会有太大的延时问题,我设置了服务器的缓冲大小等方式没有用,通过上述方法就可以了。
卡在了这个函数:avformat_find_stream_info(),我通过ffplay的以下命令可以解决播放延时的问题:
ffmpeg ffplay播放延时大问题:播放延时参数设置
参考网址:http://blog.csdn.net/cai6811376/article/details/52637158使用ffplay播放视频源时,rtsp/rtmp等,会有一定的延时,这里我们可以通过设置ffplay播放参数将延时控制到最小。
ffplay.exe -i rtmp://xxxxxxx -fflags nobuffer
减少缓冲
也可以减少分析码流的时间
ffplay.exe -i rtmp://xxxxxxx -analyzeduration 1000000
码流分析时间设置,单位为微秒
RTSP低延时播放:
ffplay.exe -i rtsp://xxx -fflags nobuffer -analyzeduration 1000000 -rtsp_transport tcp
通过代码可以通过如下方式设置:
ffmpeg中avformat_stream_info函数阻塞时间太长
在使用ffmpeg播放网络流中,在执行到avformat_stream_info函数会阻塞5秒左右,这样造成播放等待时间过长,影响用户体验,经试验,修改函数里面AVFormatContext参数,probesize和max_analyze_duration值大小
通过AVDictionary来改变AVFormatContext结构体里参数。
AVDictionary * avdic = NULL;
av_dict_set(&avdic,"probesize","2048",0);
av_dict_set(&avdic,"max_analyze_duration","1000",0);
avforamt_open_input(&pFormatCtx,url, NULL, &avdic);
avformat_find_stream_info(pFormatCtx, NULL);
我的实际代码如下:
AVDictionary* pOptions = NULL;
pFormatCtx->probesize = 1 *1024;
pFormatCtx->max_analyze_duration = 1 * AV_TIME_BASE;
// Retrieve stream information
if(avformat_find_stream_info(pFormatCtx,&pOptions)<0)
{
printf("Couldn't find stream information.\n");
return -1;
}以下代码也是可以的:
AVDictionary * avdic = NULL;
av_dict_set(&avdic,"probesize","2048",0);
av_dict_set(&avdic,"max_analyze_duration","10",0);
avformat_open_input(&pFormatCtx,url, NULL, &avdic);
avformat_find_stream_info(pFormatCtx, NULL);
这样就不会有太大的延时问题,我设置了服务器的缓冲大小等方式没有用,通过上述方法就可以了。
相关文章推荐
- JS 实时数据解决方法
- BW数据加载后不能实时刷新到水晶易表解决方法
- 关于MDK(KELI)下stlink仿真不能实时更新数据的解决方法
- Spring中DAO被循环调用的时候数据不实时更新的解决方法
- -------------别人解决的, rtmp中音频和视频数据不对称导致的卡顿的情况-----------------
- 关于VS2005 数据连接错误的解决方法
- SQL2000+存储过程+触发器+DLL调用的方法来实现数据实时转换
- Response.Write("Sucess!!")不能输出数据的解决方法
- 批量更新数据引起 DataGrid 的绘制错误及解决方法
- 在JBossPortal中使用MySQL5出现数据截断问题的解决方法
- xmlhttp远程异步调数据一例(含中文乱码解决方法)
- 英数数据太长把cells撑开的解决方法
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 较长数据无法在Asp页面中取出的三种解决方法
- 有关Powerdesgner数据模型设计中,属性名同名问题的解决方法
- SQL2000+存储过程+触发器+DLL调用的方法来实现数据实时转换
- SQL Server2000中数据从一个表导入加一个表出现的问题及解决方法
- 解决Listview控件中的数据实时更新产生闪烁!
- DateTimePicker 数据绑定遭遇 null 值的解决方法
- 无法保存中间表关系数据的解决方法