ffmpeg-rstp流相关问题

1.视频流各种超时设置

 ffmpeg的avformat_open_input()和av_read_frame默认是阻塞的

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);//单位us 也就是这里设置的是3s

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

2.设置udp,http格式流超时

AVDictionary* opts = NULL;

av_dict_set(&opts, "timeout", "3000000", 0);//单位 如果是http:ms  如果是udp:s

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

 

读流超时设计av_read_frame


1.回调用的方式

  • //打开成功后 设置回调,监控read超时情况 通过这种方式可以动态修改(一定是要打开 后再进行回调函数的设置,否则会一直接报avformat_open_input()函数执行不成功

    context->ifmt_ctx->interrupt_callback.opaque = context;回调函数的参数

    context->ifmt_ctx->interrupt_callback.callback = interruptCallback;//设置回调函数

  • //每次读流之前记录一下起始时间

context->read_start_time = time(NULL);

int ret = av_read_frame(context->ifmt_ctx, &pkt);

  • //回调监控

static int interruptCallback(void *context){

AVFormatContext *ctx = (AVFormatContext *)context;//AVFormatContext ,这是回调opaque设置的

    if (ctx == NULL) {

        return 0;

    }

    ACCUInt64_t end =  time(NULL);

    if (end - ctx->read_start_time >= 3) {

        return 1;

    }

    return 0;

}

2.参数设置

//不可动态设置,只能在开流之前设置好

AVDictionary* opts = NULL;

av_dict_set(&opts, "rw_timeout", "3000", 0);//单位:ms  

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

 

2.视频流的格式

关键字:rtsp url 用户名 密码 user password

rtsp://[<username>[:<password>]@]<server-address-or-name>[:<port>][/<path>]"

如:rtsp://admin:1992wuweibiao@192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值