lavf/hlsenc: append last incomplete segment when closing the output
Also introduce missing check on PTS value in case of NOPTS value.
This commit is contained in:
parent
aeef76b383
commit
4630dfd1eb
@ -49,6 +49,7 @@ typedef struct HLSContext {
|
|||||||
int has_video;
|
int has_video;
|
||||||
int64_t start_pts;
|
int64_t start_pts;
|
||||||
int64_t end_pts;
|
int64_t end_pts;
|
||||||
|
int64_t duration; ///< last segment duration computed so far, in seconds
|
||||||
int nb_entries;
|
int nb_entries;
|
||||||
ListEntry *list;
|
ListEntry *list;
|
||||||
ListEntry *end_list;
|
ListEntry *end_list;
|
||||||
@ -252,7 +253,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
AVFormatContext *oc = hls->avf;
|
AVFormatContext *oc = hls->avf;
|
||||||
AVStream *st = s->streams[pkt->stream_index];
|
AVStream *st = s->streams[pkt->stream_index];
|
||||||
int64_t end_pts = hls->recording_time * hls->number;
|
int64_t end_pts = hls->recording_time * hls->number;
|
||||||
int ret;
|
int ret, is_ref_pkt = 0;
|
||||||
|
|
||||||
if (hls->start_pts == AV_NOPTS_VALUE) {
|
if (hls->start_pts == AV_NOPTS_VALUE) {
|
||||||
hls->start_pts = pkt->pts;
|
hls->start_pts = pkt->pts;
|
||||||
@ -260,17 +261,23 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
|
if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
|
||||||
|
pkt->pts != AV_NOPTS_VALUE) {
|
||||||
|
is_ref_pkt = 1;
|
||||||
|
hls->duration = av_rescale(pkt->pts - hls->end_pts,
|
||||||
|
st->time_base.num, st->time_base.den);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_ref_pkt &&
|
||||||
av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
|
av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
|
||||||
end_pts, AV_TIME_BASE_Q) >= 0 &&
|
end_pts, AV_TIME_BASE_Q) >= 0 &&
|
||||||
pkt->flags & AV_PKT_FLAG_KEY) {
|
pkt->flags & AV_PKT_FLAG_KEY) {
|
||||||
|
|
||||||
ret = append_entry(hls, av_rescale(pkt->pts - hls->end_pts,
|
ret = append_entry(hls, hls->duration);
|
||||||
st->time_base.num,
|
|
||||||
st->time_base.den));
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
hls->end_pts = pkt->pts;
|
hls->end_pts = pkt->pts;
|
||||||
|
hls->duration = 0;
|
||||||
|
|
||||||
av_write_frame(oc, NULL); /* Flush any buffered data */
|
av_write_frame(oc, NULL); /* Flush any buffered data */
|
||||||
avio_close(oc->pb);
|
avio_close(oc->pb);
|
||||||
@ -300,6 +307,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
|
|||||||
avio_closep(&oc->pb);
|
avio_closep(&oc->pb);
|
||||||
avformat_free_context(oc);
|
avformat_free_context(oc);
|
||||||
av_free(hls->basename);
|
av_free(hls->basename);
|
||||||
|
append_entry(hls, hls->duration);
|
||||||
hls_window(s, 1);
|
hls_window(s, 1);
|
||||||
|
|
||||||
free_entries(hls);
|
free_entries(hls);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user