当前位置: 移动技术网 > IT编程>开发语言>.net > 【FFmpeg】警告:[hls] pkt-」duration = 0, maybe the hls segment duration will not precise

【FFmpeg】警告:[hls] pkt-」duration = 0, maybe the hls segment duration will not precise

2020年07月13日  | 移动技术网IT编程  | 我要评论
1、问题描述

在使用ffmpeg编程生成m3u8文件时,报警告

[hls @ 0x7f26b4181840] pkt->duration = 0, maybe the hls segment duration will not precise
2、原因分析

根据警告提示信息, AVPacket.duration的值设为了0,可能会导致hls在分段时时间不精确。
根据警告信息搜索源码,在FFmpeg-n4.2.2/libavformat/hlsenc.c文件的hls_write_packet函数中有

if (pkt->duration) {
	vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
} else {
	av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");
	vs->duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;
}

hls中会用到duration,当AVPacket::duration的值为0时,使用前后两个AVPacket中的pts来计算,可能不准确,因此这里给出警告信息。

3、解决方法

当帧率固定时,可以计算出前后两帧的间隔时间,将这个时间换算成以流AVStream中的time_base为单位的值,赋值给AVPacket::duration即可。
换算方法:
1> 如果是通过编码生成的AVPacket,使用如下方法

packet.duration = av_rescale_q(1, codecContext->time_base, outStream->time_base);

2> 如果是解封装、再封装生成的AVPacket,使用如下方法

packet.duration = av_rescale_q(packet.duration, inStream->time_base, outStream->time_base);

本文地址:https://blog.csdn.net/u010168781/article/details/107305193

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网