[FFmpeg-cvslog] lavf/segment: sanitize segment end time in case last packet do not have a defined duration
Stefano Sabatini
git at videolan.org
Tue Jul 22 13:54:43 CEST 2014
ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Thu Jul 17 20:37:55 2014 +0200| [44071b0d252f7bb0d42fa8da1d486b56c4ba3acd] | committer: Stefano Sabatini
lavf/segment: sanitize segment end time in case last packet do not have a defined duration
In particular, avoids to set segments with duration set to 0
(e.g. segment with a single reference frame for which duration is
undefined).
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44071b0d252f7bb0d42fa8da1d486b56c4ba3acd
---
libavformat/segment.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 4a516da..135def2 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -48,6 +48,7 @@ typedef struct SegmentListEntry {
int64_t offset_pts;
char *filename;
struct SegmentListEntry *next;
+ int64_t last_duration;
} SegmentListEntry;
typedef enum {
@@ -719,6 +720,10 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
(pkt->pts != AV_NOPTS_VALUE &&
av_compare_ts(pkt->pts, st->time_base,
end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0))) {
+ /* sanitize end time in case last packet didn't have a defined duration */
+ if (seg->cur_entry.last_duration == 0)
+ seg->cur_entry.end_time = (double)pkt->pts * av_q2d(st->time_base);
+
if ((ret = segment_end(s, seg->individual_header_trailer, 0)) < 0)
goto fail;
@@ -734,6 +739,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
} else if (pkt->pts != AV_NOPTS_VALUE && pkt->stream_index == seg->reference_stream_index) {
seg->cur_entry.end_time =
FFMAX(seg->cur_entry.end_time, (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
+ seg->cur_entry.last_duration = pkt->duration;
}
if (seg->segment_frame_count == 0) {
More information about the ffmpeg-cvslog
mailing list