From: Aman Gupta <a...@tmm1.net>

---
 doc/muxers.texi      |  4 ++++
 libavformat/hlsenc.c | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index fd7ee50..e88dbf8 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -389,6 +389,10 @@ to @var{wrap}.
 Start the playlist sequence number from @var{number}. Default value is
 0.
 
+@item initial_offset @var{offset}
+Specify timestamp offset to apply to the output packet timestamps. The
+argument must be a time duration specification, and defaults to 0.
+
 @item hls_allow_cache @var{allowcache}
 Explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments.
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1846d9d..be58db8 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -90,6 +90,7 @@ typedef struct HLSContext {
     uint32_t pl_type;      // enum PlaylistType
     char *segment_filename;
 
+    int64_t initial_offset; ///< initial timestamps offset, expressed in 
microseconds
     int use_localtime;      ///< flag to expand filename with localtime
     int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename
     int allowcache;
@@ -795,7 +796,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     HLSContext *hls = s->priv_data;
     AVFormatContext *oc = NULL;
     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, offset;
     int is_ref_pkt = 1;
     int ret, can_split = 1;
     int stream_index = 0;
@@ -871,7 +872,14 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
             return ret;
     }
 
-    ret = ff_write_chained(oc, stream_index, pkt, s, 0);
+    /* compute new timestamps */
+    offset = av_rescale_q(hls->initial_offset, AV_TIME_BASE_Q, st->time_base);
+    if (pkt->pts != AV_NOPTS_VALUE)
+        pkt->pts += offset;
+    if (pkt->dts != AV_NOPTS_VALUE)
+        pkt->dts += offset;
+
+    ret = ff_write_chained(oc, stream_index, pkt, s, hls->initial_offset ? 1 : 
0);
 
     return ret;
 }
@@ -939,6 +947,7 @@ static const AVOption options[] = {
     {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = 
PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
     {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, 
INT_MIN, INT_MAX, E, "pl_type" },
     {"method", "set the HTTP method", OFFSET(method), AV_OPT_TYPE_STRING, 
{.str = NULL},  0, 0,    E},
+    {"initial_offset", "set initial timestamp offset", OFFSET(initial_offset), 
AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E },
 
     { NULL },
 };
-- 
2.8.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to