diff mbox series

[FFmpeg-devel,1/1] Add option to set DASH stream start time, instead of relying on system clock

Message ID 20240816222849.603644-2-jerome@percipient.ai
State New
Headers show
Series Explanation for "Add option to set DASH stream start time" | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".

Commit Message

Jerome Berclaz Aug. 16, 2024, 10:28 p.m. UTC
---
 libavformat/dashenc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

--
2.43.0
diff mbox series

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index d4a6fe0304..e586e934cb 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -204,6 +204,7 @@  typedef struct DASHContext {
     AVRational min_playback_rate;
     AVRational max_playback_rate;
     int64_t update_period;
+    int64_t start_time_ms;
 } DASHContext;

 static const struct codec_string {
@@ -2108,7 +2109,12 @@  static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
     os->last_pts = pkt->pts;

     if (!c->availability_start_time[0]) {
-        int64_t start_time_us = av_gettime();
+        int64_t start_time_us;
+        if (c->start_time_ms) {
+            start_time_us = c->start_time_ms * 1000;
+        } else {
+            start_time_us = av_gettime();
+        }
         c->start_time_s = start_time_us / 1000000;
         format_date(c->availability_start_time,
                     sizeof(c->availability_start_time), start_time_us);
@@ -2393,6 +2399,7 @@  static const AVOption options[] = {
     { "seg_duration", "segment duration (in seconds, fractional value can be set)", OFFSET(seg_duration), AV_OPT_TYPE_DURATION, { .i64 = 5000000 }, 0, INT_MAX, E },
     { "single_file", "Store all segments in one file, accessed using byte ranges", OFFSET(single_file), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
     { "single_file_name", "DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges", OFFSET(single_file_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { "start_time_ms", "Stream start time in epoch milliseconds", OFFSET(start_time_ms), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, UINT64_MAX, E, .unit = "ms"},
     { "streaming", "Enable/Disable streaming mode of output. Each frame will be moof fragment", OFFSET(streaming), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
     { "target_latency", "Set desired target latency for Low-latency dash", OFFSET(target_latency), AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT_MAX, E },
     { "timeout", "set timeout for socket I/O operations", OFFSET(timeout), AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },