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;

你可能感兴趣的:(ffmpeg拉流设置暂停)