summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavformat/hlsenc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 4471858222..f7eb2411b0 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2572,13 +2572,14 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
vs->packets_written++;
if (oc->pb) {
+ int64_t keyframe_pre_pos = avio_tell(oc->pb);
ret = ff_write_chained(oc, stream_index, pkt, s, 0);
- vs->video_keyframe_size += pkt->size;
- if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->flags & AV_PKT_FLAG_KEY)) {
- vs->video_keyframe_size = avio_tell(oc->pb);
- } else {
- vs->video_keyframe_pos = avio_tell(vs->out);
+ if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
+ (pkt->flags & AV_PKT_FLAG_KEY) && !keyframe_pre_pos) {
+ av_write_frame(oc, NULL); /* Flush any buffered data */
+ vs->video_keyframe_size = avio_tell(oc->pb) - keyframe_pre_pos;
}
+ vs->video_keyframe_pos = vs->start_pos;
if (hls->ignore_io_errors)
ret = 0;
}