FFMPEG读取各种协议超时设置

1.设置rtsp超时

AVDictionary* opts = NULL;

av_dict_set(&opts, "rtsp_transport",  "tcp" 或"udp", 0); //设置tcp or udp,默认一般优先tcp再尝试udp
av_dict_set(&opts, "stimeout", "1000000", 0);//设置超时1秒

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

2.设置udp,http超时

AVDictionary* opts = NULL;

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

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

3.设置av_read_frame 超时

AVFormatContext* ctx = avformat_alloc_context();
ctx->interrupt_callback.callback = AVInterruptCallBackFun;//超时回调
ctx->interrupt_callback.opaque = this;

DWORD dwStart = GetTickCount();

avformat_open_input(&ctx, "rtmp://192.168.0.25/live/stream", 0, nullptr);

 

//超时回调函数

static int AVInterruptCallBackFun(void* ctx)
{

       int nTimeOut = GetTickCount() - dwStart;
  if(nTimeOut > 10000)//超过10秒则退出

              return 1;//退出流读取回调
  return 0;
}

你可能感兴趣的:(ffmpeg,读取流媒体地址)