avformat_open_input超时问题
来源:互联网 发布:在香港用淘宝 编辑:程序博客网 时间:2024/06/13 06:51
fmpeg用avformat_open_input()解析网络流时,默认是阻塞的。
当遇到解析错误的网络流时,会导致该函数长时间不返回。
为此可以设置ffmpeg的-stimeout 的参数,要注意 -stimeout的单位是us 微妙。
用法就是设置在解析的 url 之前 (这里设置超时为5秒)即:
“ffmpeg -stimeout 5000000 -i rtsp://admin:admin@192.168.7.102:554/h264...........”
或者:
“ffmpeg -stimeout 5000000 -rtsp_transport tcp -i rtsp://admin:12345@172.16.7.166:554/h264.....”
备注:-stimeout 设置在你要解析的url之后是没有作用的。
=============================================
从网络上搜索到的有关资料:
一:
“去看ffmpeg的tcp.c的源代码(会阻塞的网络地址基本都是tcp协议),搜索上面两个关键字,就明白是如何退出了。我之前的文章只说了open的时候阻塞,其实网络环境复杂,有可能在read或write时候断网或阻塞异常。但根基却是在tcp.c这个文件里。把interrupt_callback和timeout设置好了,就可以解决这些问题。”
二:
“ffmpeg的avformat_open_input()默认是阻塞的,用户可以通过设置“ic->flags |= AVFMT_FLAG_NONBLOCK;”设置成非阻塞(通常是不推荐的);或者是设置timeout设置超时时间;或者是设置interrupt_callback定义返回机制。
附一段代码参考下吧。
formatCtx = avformat_alloc_context();
if (!formatCtx)
returnLvErrorOpenFile;
AVIOInterruptCB cb = {interrupt_callback,this};
formatCtx->interrupt_callback = cb;
//这个没什么用
formatCtx->flags |=AVFMT_FLAG_NONBLOCK;
//主要是这个!!设置Opts
AVDictionary* opts =NULL;
av_dict_set(&opts,"timeout","6000",0);
if (avformat_open_input(&formatCtx,
path.c_str(),
NULL,
&opts) < 0) {
if (formatCtx)
avformat_free_context(formatCtx);
returnLvErrorOpenFile;
}
- avformat_open_input超时问题
- ffmpeg设置avformat_open_input( )超时 -stimeout
- avformat_open_input
- avformat_open_input()
- FFmpeg avformat_open_input函数打开acc,h264失败的错误问题
- 超时问题
- FFMPEG-avformat_open_input
- FFMPEG-avformat_open_input
- FFMPEG-avformat_open_input
- IIS6的超时问题
- asp.net超时问题
- MYSQL 连接超时问题
- 解决PHP超时问题
- asp.net超时问题
- SquirrelMail超时的问题
- C#进程超时问题
- WebService SendTimeout 超时问题
- 服务器超时管理问题
- maven项目找不到类not class found
- Android 编程下的 TraceView 简介及其案例实战
- 【uoj 35】后缀排序
- 总结网络IO模型与select模型的Python实例讲解
- 补码的概念
- avformat_open_input超时问题
- 学习:实现任意角度的sin、cos求值-No.2
- 关于Android的主题设置的文章
- 泛型 (中) - 解析通配符:
- OJ1914(改进,通过OJ检测)
- Socket数据通信
- Spring
- JAVA调用R语言之Rserve(二)
- openwrt启动流程