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

相关文章:

  • 2022-02-26
  • 2021-06-02
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-10-18
  • 2021-07-13
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2021-12-12
  • 2022-02-25
  • 2021-04-18
  • 2021-07-28
  • 2021-07-04
相关资源
相似解决方案