码迷,mamicode.com
首页 > 其他好文 > 详细

解决ffmpeg打开流各种超时问题

时间:2017-10-19 11:06:39      阅读:814      评论:0      收藏:0      [点我收藏+]

标签:inpu   callback   dict   void   text   函数   oid   pts   avd   

1.设置rtsp超时

AVDictionary* opts = NULL;

av_dict_set(&opts, "rtsp_transport", m_bTcp ? "tcp" : "udp", 0); //设置tcp or udp,默认一般优先tcp再尝试udp
av_dict_set(&opts, "stimeout", "3000000", 0);//设置超时3秒

int ret = avformat_open_input(&ctx, url, NULL, &opts);

2.设置udp,http超时

AVDictionary* opts = NULL;

av_dict_set(&opts, "timeout", "3000000", 0);//设置超时3秒

int ret = avformat_open_input(&ctx, url, NULL, &opts);

3.设置av_read_frame 超时

auto ctx = avformat_alloc_context();
ctx->interrupt_callback.callback = CheckInterrupt;//超时回调
ctx->interrupt_callback.opaque = this;

//

m_tStart = time(NULL);

av_read_frame(ctx, &pkt);

//超时回调函数

static int CheckInterrupt(void* ctx)
{
  auto p = (xxx*)ctx;
  return time(NULL) -  p->m_tStart >= 3 ? 1 : 0;//3秒超时
}

解决ffmpeg打开流各种超时问题

标签:inpu   callback   dict   void   text   函数   oid   pts   avd   

原文地址:http://www.cnblogs.com/shareable/p/7691285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!