ffmpeg连接超时与解码超时

ffmpeg超时时间应该有两个,连接超时时间和解码超时时间,但是现在只有一个参数,本文告诉你一种解决方案


    // Set the RTSP Options
    AVDictionary *opts = 0;
    if (usesTcp) {
       // av_dict_set(&opts, "rtsp_transport", "tcp", 0);
    }
     av_dict_set(&opts, "timeout", "6000", 0); // in ms
   av_dict_set(&opts, "timeout", "0", 0); // 表示一直等待。
  av_dict_set(&opts, "timeout", "-1", 0); // 不能正常收数据
    // 打開影片檔案
    if (avformat_open_input(&pFormatCtx, [moviePath UTF8String], NULL, &opts) != 0) {
        av_log(NULL, AV_LOG_ERROR, "Couldn't open file\n");
        goto initError;
    }

后果:
解决了问题:如果开始连接不上,程序一直卡在 avformat_open_input,导致第二次连接,即使有数据也不能播放。
产生了新问题:一旦网络失败,就会断开,自动重连的功能就没有了,以前是如果没有数据,就一直等着,数据来了就自动重连。

解码超时问题:
h->rw_timeout = s->timeout;

int ffurl_read(URLContext *h, unsigned char *buf, int size)
{
    if (!(h->flags & AVIO_FLAG_READ))
        return AVERROR(EIO);
    return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
}


调用地方:



av_log(NULL, AV_LOG_ERROR, "lbg ffurl_read 12\n");
  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
                          (void*)ffurl_read, (void*)ffurl_write, (void*)ffurl_seek);


声明:avio.h文件:

AVIOContext *avio_alloc_context(
                  unsigned char *buffer,
                  int buffer_size,
                  int write_flag,
                  void *opaque,
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));


接收数据调用:

static void fill_buffer(AVIOContext *s)
{


解决OK:


#include "ffmpeg/libavformat/url.h"


AVIOContext * pb= player->input_format_ctx->pb;
if(pb){
    URLContext *hd=(URLContext *)pb->opaque;
    if(hd){
     hd->rw_timeout=0;
      //  AesContext *c = hd->priv_data;
      //  if(c){
     //   URLContext *h=c->hd;
     //   h->rw_timeout=0;
     // LOGE(3,"11111111111111111111111111%d",h->rw_timeout);
     // }
  }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值