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