[FFmpeg-devel] [PATCH] lavf/segment: extend format for the segment list file

Stefano Sabatini stefasab at gmail.com
Fri Jun 29 17:18:47 CEST 2012


Write the start and ending time for each segment. This is required to
make it available this information to external tools without the need
to perform file analysis in the resulting segments.
---
 libavformat/segment.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 17ef20a..f1a9cdf 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -43,6 +43,7 @@ typedef struct {
     int64_t recording_time;
     int has_video;
     AVIOContext *pb;
+    double start_time, end_time;
 } SegmentContext;
 
 static int segment_start(AVFormatContext *s)
@@ -109,7 +110,7 @@ static int segment_end(AVFormatContext *s)
                                   &s->interrupt_callback, NULL)) < 0)
                 goto end;
         }
-        avio_printf(seg->pb, "%s\n", oc->filename);
+        avio_printf(seg->pb, "%s,%f,%f\n", oc->filename, seg->start_time, seg->end_time);
         avio_flush(seg->pb);
     }
 
@@ -220,6 +221,10 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
 
         if (ret)
             goto fail;
+        seg->start_time = (double)pkt->pts * av_q2d(st->time_base);
+    } else if (pkt->pts != AV_NOPTS_VALUE) {
+        seg->end_time = FFMAX(seg->end_time,
+                              (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
     }
 
     ret = oc->oformat->write_packet(oc, pkt);
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list