[FFmpeg-devel] [PATCH] avformat/hlsenc: add reference stream index for split segment
Steven Liu
lq at chinaffmpeg.org
Tue Feb 27 07:39:33 EET 2018
fix ticket: #7044
Get the first video stream to reference for split segment
when there have more than one video stream
Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
libavformat/hlsenc.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ff064732a1..8567227885 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -129,6 +129,7 @@ typedef struct VariantStream {
int nb_entries;
int discontinuity_set;
int discontinuity;
+ int reference_stream_index;
HLSSegment *segments;
HLSSegment *last_segment;
@@ -2155,8 +2156,10 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
* st->time_base.num / st->time_base.den;
vs->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;
} else {
- if (pkt->duration) {
- vs->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
+ if (pkt->duration) {
+ if (pkt->stream_index == vs->reference_stream_index) {
+ 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;
@@ -2497,6 +2500,11 @@ static int hls_init(AVFormatContext *s)
for (j = 0; j < vs->nb_streams; j++) {
vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
+ /* Get one video stream to reference for split segments
+ * so use the first video stream index. */
+ if (vs->has_video == 1) {
+ vs->reference_stream_index = j;
+ }
vs->has_subtitle += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE;
}
--
2.15.1
More information about the ffmpeg-devel
mailing list