FFmpeg H264码流保存为hls切片m3u8数据类型

简单流程介绍

                    avformat_alloc_output_context2(pAVFormatContext, NULL, "hls", strFileName.c_str())//指定复用器muxer

                    av_dict_set_int(&opts, "hls_list_size", 0, 0);//设置播放列表保存的最多条目,设置为0会保存有所片信息,默认值为5

                    avformat_write_header(pAVFormatContext, opts ? &opts : NULL)

                    av_interleaved_write_frame(pAVFormatContext, AVPacket);

                    av_write_trailer(pAVFormatContext)

                    avformat_free_context(pAVFormatContext)

 

 

提示警告问题1)pkt->duration = 0, maybe the hls segment duration will not precise

将AVPacket中的pts赋值给duration解决问题

原因

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

FFmpeg源码

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;
}

2)缺少#EXT-X-ENDLIST结束符,检查是否调用写文件结束调用

av_write_trailer(pAVFormatContext)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值