ffmpeg拉流设置暂停_ffmpeg拉流长时间堵塞解决方式

av_read_frame()

该函数是链接成功后,由于网络堵塞或者其它问题导致packet丢失,无法读取,导致堵塞,

函数在ffmpeg.c文件中,解决方式也是添加超时

f->ctx->interrupt_callback.callback = CheckInterrupt;

f->ctx->interrupt_callback.opaque = (void*)f->ctx;

time_t start_time;

start_time = time(NULL);

int l = time(&start_time);

f->ctx->st = l;

return av_read_frame(f->ctx, pkt);

下面是回调函数:

static int CheckInterrupt(void *ctx)

{

AVFormatContext p = (AVFormatContext)ctx;

time_t et;

et = time(NULL);

int l = time(&et);

av_log(NULL, AV_LOG_WARNING,"start time%d\n",p->st);

av_log(NULL, AV_LOG_WARNING,"end time%d\n",l);

return l - p->st >= 10 ? 1 : 0;//3秒超时

}

需要注意的是,我在f->ctx结构体中添加了st变量,由时间戳作为评判超时的依据,需要把变量类型统一,所以需要添加变量如下:

在avformat.h文件的AVFormatContext结构体中添加:

int st;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值