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)

你可能感兴趣的:(FFmpeg H264码流保存为hls切片m3u8数据类型)