DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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秒超时
}

posted on 2021-12-13 18:18  DoubleLi  阅读(1072)  评论(0编辑  收藏  举报