解決ffmpeg打開流各種超時問題


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM