ffmpeg解析实时h265/264视频流,出现Could not find ref with POCXX问题解决方法

解决方法

1.增加解码线程调用子线程数量

这是由于处理的机器性能低,导致播放流的速度大于解码速度,
怎么解决这种问题呢,就是提高解码速度,采取的就是增加解码的线程,
参考文章
FFmpeg 解码 avcodec_find_decoder AVCodecContext
FFmpeg(8)-打开音视频解码器,配置解码器上下文(avcodec_find_decoder()、avcodec_alloc_context3())
具体来说

int avcodec_open2(AVCodecContext *avctx, const AVCodec
*codec, AVDictionary **options) 打开 options动态设置 多线程解码设置
• /libavcodec/options_table.h
• int thread_count CPU数量设置
• time_base 时间基数

中可以设置CPU数量,那么应该怎么做呢
设置调用的CPU线程数量

// 注册解码器
avcodec_register_all();
AVCodec *vc = avcodec_find_decoder(ic->streams[videoStream]->codecpar->codec_id); // 软解
    // vc = avcodec_find_decoder_by_name("h264_mediacodec"); // 硬解
    if (!vc) {
        LOGE("avcodec_find_decoder[videoStream] failure");
        return env->NewStringUTF(hello.c_str());
    }
    // 配置解码器
    AVCodecContext *vct = avcodec_alloc_context3(vc);
    avcodec_parameters_to_context(vct, ic->streams[videoStream]->codecpar);
    vct->thread_count = 1;//设置CPU线程数量
    // 打开解码器
    int re = avcodec_open2(vct, vc, 0);
    if (re != 0) {
        LOGE("avcodec_open2 failure");
        return env->NewStringUTF(hello.c_str());
    }
2.将网络接收的缓冲设大

参考博客FFmpeg 获取RTSP传过来的视频数据并保存成文件

AVDictionary* options = NULL;
av_dict_set(&options, "buffer_size", "102400", 0); //设置缓存大小,1080p可将值调大
//打开网络流或文件流  
if (avformat_open_input(&pFormatCtx, filepath, NULL, &options) != 0)	
{
	printf("Couldn't open input stream.\n");
	return;
}

3.减少接受线程工作量

参考博客[FFmpeg 获取RTSP传过来的视频数据并保存成文件]
开一条线程给RTSP接收函数,该线程只负责接收,不做其他的工作。这样基本上就能保证数据被及时处理。

4.如果使用ros接收,增加接收的队列长度
ros::Subscriber image_sub = node.subscribe(h265_topic_, 10, &TrackerProcessTest::H265TopicCallback, this);

这里将接收长度改为10
设置Subscriber的queue_size(消息队列大小),保证数据不丢失

  • 6
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
引用\[1\]:\[hevc @ 000001716438fc00\] Two slices reporting being the first in the same frame. \[hevc @ 000001716439ec80\] Could not find ref with POC 2 。 引用\[2\]:解决办法:使用avio_alloc_context的回调函数read_packet来给ffmpeg喂数据。 经过测试,不会出现Could not find ref with POCXX的问题。 经测试,延时160ms 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)); 。 引用\[3\]:中可以设置CPU数量,那么应该怎么做呢 设置调用的CPU线程数量 // 注册解码器 avcodec_register_all(); AVCodec *vc = avcodec_find_decoder(ic->streams\[videoStream\]->codecpar->codec_id); // 软解 // vc = avcodec_find_decoder_by_name("h264_mediacodec"); // 硬解 if (!vc) { LOGE("avcodec_find_decoder\[videoStream\] failure"); return env->NewStringUTF(hello.c_str()); } // 配置解码器 AVCodecContext *vct = avcodec_alloc_context3(vc); avcodec_parameters_to_context(vct, ic->streams\[videoStream\]->codecpar); vct->thread_count = 1;//设置CPU线程数量 // 打开解码器 int re = avcodec_open2(vct, vc, 0); if (re != 0) { LOGE("avcodec_open2 failure"); return env->NewStringUTF(hello.c_str()); } 2.将网络接收的缓冲设大 。 问题:Could not find ref with POC 回答: "Could not find ref with POC"是ffmpeg中的一个错误消息,它表示在解码过程中找不到参考帧。这个问题可能是由于多个切片在同一帧中报告为第一个切片引起的\[1\]。解决这个问题方法是使用avio_alloc_context的回调函数read_packet来提供数据给ffmpeg,并且经过测试,这样就不会出现"Could not find ref with POC"的问题\[2\]。另外,还可以通过设置CPU线程数量来优化解码过程,可以将vct->thread_count设置为所需的线程数量\[3\]。此外,还可以尝试将网络接收的缓冲区大小增加来解决问题\[3\]。 #### 引用[.reference_title] - *1* *2* [Two slices reporting being the first in the same frame. 和 Could not find ref with POCXX问题](https://blog.csdn.net/asdasfdgdhh/article/details/121826433)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ffmpeg解析实时h265/264视频流出现Could not find ref with POCXX问题解决方法](https://blog.csdn.net/u013241583/article/details/104796741)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值