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

  • 相关阅读:
    052-141
    052-140
    052-139
    052-138
    需要做笔记的页面
    日期总是显示1900/01/01 0:00:00
    延迟加载的树控件
    (简单)关于summary的注释
    江南检测
    fineui动态添加用户控件
  • 原文地址:https://www.cnblogs.com/lidabo/p/15684617.html
Copyright © 2020-2023  润新知