aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/hlsenc.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2013-08-15 12:33:20 +0300
committerMartin Storsjö <martin@martin.st>2013-08-15 22:41:18 +0300
commit09c93b1b957f2049ea5fd8fb0e6f4d82680172f2 (patch)
treecfe45f76aa090d75442bb364382ac926d66dc17b /libavformat/hlsenc.c
parentc9031c7c1446a1a63eff7c0bf50d1ee559adf3fb (diff)
downloadffmpeg-09c93b1b957f2049ea5fd8fb0e6f4d82680172f2.tar.gz
hlsenc: Append the last incomplete segment when closing the output
Also avoid comparing NOPTS values. Bug-id: 551 Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r--libavformat/hlsenc.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index caf878ffd4..a4b1baf180 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -49,6 +49,7 @@ typedef struct HLSContext {
int has_video;
int64_t start_pts;
int64_t end_pts;
+ int64_t duration; // last segment duration computed so far, in seconds
int nb_entries;
ListEntry *list;
ListEntry *end_list;
@@ -261,16 +262,20 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
pkt->flags & AV_PKT_FLAG_KEY;
}
+ if (pkt->pts == AV_NOPTS_VALUE)
+ can_split = 0;
+ else
+ hls->duration = av_rescale(pkt->pts - hls->end_pts,
+ st->time_base.num, st->time_base.den);
if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
end_pts, AV_TIME_BASE_Q) >= 0) {
- ret = append_entry(hls, av_rescale(pkt->pts - hls->end_pts,
- st->time_base.num,
- st->time_base.den));
+ ret = append_entry(hls, hls->duration);
if (ret)
return ret;
hls->end_pts = pkt->pts;
+ hls->duration = 0;
av_write_frame(oc, NULL); /* Flush any buffered data */
avio_close(oc->pb);
@@ -300,6 +305,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
avio_closep(&oc->pb);
avformat_free_context(oc);
av_free(hls->basename);
+ append_entry(hls, hls->duration);
hls_window(s, 1);
free_entries(hls);