Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
Thanks for reviewing and making this happen. Regards, Joep On Wed, Mar 6, 2019 at 6:38 AM Jeyapal, Karthick wrote: > > On 3/5/19 8:07 PM, joepadmiraal wrote: > > --- > > libavformat/dashenc.c | 20 ++-- > > 1 file changed, 18 insertions(+), 2 deletions(-) > > > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > > index c5e882f4ae..6bcdc9ba36 100644 > > --- a/libavformat/dashenc.c > > +++ b/libavformat/dashenc.c > > @@ -61,6 +61,7 @@ typedef struct Segment { > > int64_t start_pos; > > int range_length, index_length; > > int64_t time; > > +double prog_date_time; > > int64_t duration; > > int n; > > } Segment; > > @@ -122,6 +123,7 @@ typedef struct DASHContext { > > int64_t last_duration; > > int64_t total_duration; > > char availability_start_time[100]; > > +time_t start_time_s; > > char dirname[1024]; > > const char *single_file_name; /* file names as specified in > options */ > > const char *init_seg_name; > > @@ -433,6 +435,7 @@ static void write_hls_media_playlist(OutputStream > *os, AVFormatContext *s, > > const char *proto = avio_find_protocol_name(c->dirname); > > int use_rename = proto && !strcmp(proto, "file"); > > int i, start_index, start_number; > > +double prog_date_time = 0; > > > > get_start_index_number(os, c, _index, _number); > > > > @@ -467,11 +470,20 @@ static void write_hls_media_playlist(OutputStream > *os, AVFormatContext *s, > > > > for (i = start_index; i < os->nb_segments; i++) { > > Segment *seg = os->segments[i]; > > + > > +if (prog_date_time == 0) { > > +if (os->nb_segments == 1) > > +prog_date_time = c->start_time_s; > > +else > > +prog_date_time = seg->prog_date_time; > > +} > > +seg->prog_date_time = prog_date_time; > > + > > ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > > (double) seg->duration / timescale, 0, > > seg->range_length, seg->start_pos, NULL, > > c->single_file ? os->initfile : > seg->file, > > -NULL); > > +_date_time); > > if (ret < 0) { > > av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry > get error\n"); > > } > > @@ -1592,9 +1604,13 @@ static int dash_write_packet(AVFormatContext *s, > AVPacket *pkt) > > os->first_pts = pkt->pts; > > os->last_pts = pkt->pts; > > > > -if (!c->availability_start_time[0]) > > +if (!c->availability_start_time[0]) { > > +int64_t start_time_us = av_gettime(); > > +int64_t start_time_ms = start_time_us / 1000; > > +c->start_time_s = start_time_ms / 1000; > > format_date_now(c->availability_start_time, > > sizeof(c->availability_start_time)); > > +} > > > > if (!os->availability_time_offset && pkt->duration) { > > int64_t frame_duration = av_rescale_q(pkt->duration, > st->time_base, > Thanks for your contribution. This patch has been pushed (after a minor > cleanup). > > Regards, > Karthick > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
On 3/5/19 8:07 PM, joepadmiraal wrote: > --- > libavformat/dashenc.c | 20 ++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > index c5e882f4ae..6bcdc9ba36 100644 > --- a/libavformat/dashenc.c > +++ b/libavformat/dashenc.c > @@ -61,6 +61,7 @@ typedef struct Segment { > int64_t start_pos; > int range_length, index_length; > int64_t time; > +double prog_date_time; > int64_t duration; > int n; > } Segment; > @@ -122,6 +123,7 @@ typedef struct DASHContext { > int64_t last_duration; > int64_t total_duration; > char availability_start_time[100]; > +time_t start_time_s; > char dirname[1024]; > const char *single_file_name; /* file names as specified in options */ > const char *init_seg_name; > @@ -433,6 +435,7 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > const char *proto = avio_find_protocol_name(c->dirname); > int use_rename = proto && !strcmp(proto, "file"); > int i, start_index, start_number; > +double prog_date_time = 0; > > get_start_index_number(os, c, _index, _number); > > @@ -467,11 +470,20 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > > for (i = start_index; i < os->nb_segments; i++) { > Segment *seg = os->segments[i]; > + > +if (prog_date_time == 0) { > +if (os->nb_segments == 1) > +prog_date_time = c->start_time_s; > +else > +prog_date_time = seg->prog_date_time; > +} > +seg->prog_date_time = prog_date_time; > + > ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > (double) seg->duration / timescale, 0, > seg->range_length, seg->start_pos, NULL, > c->single_file ? os->initfile : seg->file, > -NULL); > +_date_time); > if (ret < 0) { > av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get > error\n"); > } > @@ -1592,9 +1604,13 @@ static int dash_write_packet(AVFormatContext *s, > AVPacket *pkt) > os->first_pts = pkt->pts; > os->last_pts = pkt->pts; > > -if (!c->availability_start_time[0]) > +if (!c->availability_start_time[0]) { > +int64_t start_time_us = av_gettime(); > +int64_t start_time_ms = start_time_us / 1000; > +c->start_time_s = start_time_ms / 1000; > format_date_now(c->availability_start_time, > sizeof(c->availability_start_time)); > +} > > if (!os->availability_time_offset && pkt->duration) { > int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, Thanks for your contribution. This patch has been pushed (after a minor cleanup). Regards, Karthick ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
--- libavformat/dashenc.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index c5e882f4ae..6bcdc9ba36 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -61,6 +61,7 @@ typedef struct Segment { int64_t start_pos; int range_length, index_length; int64_t time; +double prog_date_time; int64_t duration; int n; } Segment; @@ -122,6 +123,7 @@ typedef struct DASHContext { int64_t last_duration; int64_t total_duration; char availability_start_time[100]; +time_t start_time_s; char dirname[1024]; const char *single_file_name; /* file names as specified in options */ const char *init_seg_name; @@ -433,6 +435,7 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, const char *proto = avio_find_protocol_name(c->dirname); int use_rename = proto && !strcmp(proto, "file"); int i, start_index, start_number; +double prog_date_time = 0; get_start_index_number(os, c, _index, _number); @@ -467,11 +470,20 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, for (i = start_index; i < os->nb_segments; i++) { Segment *seg = os->segments[i]; + +if (prog_date_time == 0) { +if (os->nb_segments == 1) +prog_date_time = c->start_time_s; +else +prog_date_time = seg->prog_date_time; +} +seg->prog_date_time = prog_date_time; + ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, (double) seg->duration / timescale, 0, seg->range_length, seg->start_pos, NULL, c->single_file ? os->initfile : seg->file, -NULL); +_date_time); if (ret < 0) { av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); } @@ -1592,9 +1604,13 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->first_pts = pkt->pts; os->last_pts = pkt->pts; -if (!c->availability_start_time[0]) +if (!c->availability_start_time[0]) { +int64_t start_time_us = av_gettime(); +int64_t start_time_ms = start_time_us / 1000; +c->start_time_s = start_time_ms / 1000; format_date_now(c->availability_start_time, sizeof(c->availability_start_time)); +} if (!os->availability_time_offset && pkt->duration) { int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, -- 2.17.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
On 3/1/19 2:56 PM, joepadmiraal wrote: > --- > libavformat/dashenc.c | 23 --- > 1 file changed, 20 insertions(+), 3 deletions(-) Thanks for sending this revised patch. Now the patch looks fine overall. There are two minor suggestions though. > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > index c5e882f4ae..4ee4a0cf72 100644 > --- a/libavformat/dashenc.c > +++ b/libavformat/dashenc.c > @@ -61,6 +61,7 @@ typedef struct Segment { > int64_t start_pos; > int range_length, index_length; > int64_t time; > +double prog_date_time; > int64_t duration; > int n; > } Segment; > @@ -122,6 +123,7 @@ typedef struct DASHContext { > int64_t last_duration; > int64_t total_duration; > char availability_start_time[100]; > +int64_t start_time_ms; > char dirname[1024]; > const char *single_file_name; /* file names as specified in options */ > const char *init_seg_name; > @@ -433,6 +435,8 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > const char *proto = avio_find_protocol_name(c->dirname); > int use_rename = proto && !strcmp(proto, "file"); > int i, start_index, start_number; > +time_t start_time_s = c->start_time_ms / 1000; Is there any reason for not storing start_time_s directly in the DASHContext instead of start_time_ms? Because two variables and two divisions seem redundant, when the same can be achieved with one. > +double prog_date_time = 0; > > get_start_index_number(os, c, _index, _number); > > @@ -467,11 +471,21 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > > for (i = start_index; i < os->nb_segments; i++) { > Segment *seg = os->segments[i]; > +double duration = (double) seg->duration / timescale; > + > +if (prog_date_time == 0) { > +if (os->nb_segments == 1) > +prog_date_time = start_time_s; > +else > +prog_date_time = seg->prog_date_time; > +} > +seg->prog_date_time = prog_date_time; > + > ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > -(double) seg->duration / timescale, 0, > +duration, 0, This change looks unnecessary to the motive of this patch. Could this change be removed from this patch? > seg->range_length, seg->start_pos, NULL, > c->single_file ? os->initfile : seg->file, > -NULL); > +_date_time); > if (ret < 0) { > av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get > error\n"); > } > @@ -1592,9 +1606,12 @@ static int dash_write_packet(AVFormatContext *s, > AVPacket *pkt) > os->first_pts = pkt->pts; > os->last_pts = pkt->pts; > > -if (!c->availability_start_time[0]) > +if (!c->availability_start_time[0]) { > +int64_t start_time_us = av_gettime(); > +c->start_time_ms = start_time_us / 1000; > format_date_now(c->availability_start_time, > sizeof(c->availability_start_time)); > +} > > if (!os->availability_time_offset && pkt->duration) { > int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
--- libavformat/dashenc.c | 23 --- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index c5e882f4ae..4ee4a0cf72 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -61,6 +61,7 @@ typedef struct Segment { int64_t start_pos; int range_length, index_length; int64_t time; +double prog_date_time; int64_t duration; int n; } Segment; @@ -122,6 +123,7 @@ typedef struct DASHContext { int64_t last_duration; int64_t total_duration; char availability_start_time[100]; +int64_t start_time_ms; char dirname[1024]; const char *single_file_name; /* file names as specified in options */ const char *init_seg_name; @@ -433,6 +435,8 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, const char *proto = avio_find_protocol_name(c->dirname); int use_rename = proto && !strcmp(proto, "file"); int i, start_index, start_number; +time_t start_time_s = c->start_time_ms / 1000; +double prog_date_time = 0; get_start_index_number(os, c, _index, _number); @@ -467,11 +471,21 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, for (i = start_index; i < os->nb_segments; i++) { Segment *seg = os->segments[i]; +double duration = (double) seg->duration / timescale; + +if (prog_date_time == 0) { +if (os->nb_segments == 1) +prog_date_time = start_time_s; +else +prog_date_time = seg->prog_date_time; +} +seg->prog_date_time = prog_date_time; + ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, -(double) seg->duration / timescale, 0, +duration, 0, seg->range_length, seg->start_pos, NULL, c->single_file ? os->initfile : seg->file, -NULL); +_date_time); if (ret < 0) { av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); } @@ -1592,9 +1606,12 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->first_pts = pkt->pts; os->last_pts = pkt->pts; -if (!c->availability_start_time[0]) +if (!c->availability_start_time[0]) { +int64_t start_time_us = av_gettime(); +c->start_time_ms = start_time_us / 1000; format_date_now(c->availability_start_time, sizeof(c->availability_start_time)); +} if (!os->availability_time_offset && pkt->duration) { int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, -- 2.17.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
Hi Karthick, Thanks for looking into this. I'll have a look at the suggested improvement. Regards, Joep On Tue, Feb 26, 2019 at 6:25 AM Jeyapal, Karthick wrote: > > On 2/22/19 12:25 PM, joepadmiraal wrote: > > From: joepadmiraal > > > > --- > > libavformat/dashenc.c | 29 - > > 1 file changed, 20 insertions(+), 9 deletions(-) > > > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > > index 37a7547b12..d0d0d6f030 100644 > > --- a/libavformat/dashenc.c > > +++ b/libavformat/dashenc.c > > @@ -122,6 +122,7 @@ typedef struct DASHContext { > > int64_t last_duration; > > int64_t total_duration; > > char availability_start_time[100]; > > +int64_t start_time_ms; > > char dirname[1024]; > > const char *single_file_name; /* file names as specified in > options */ > > const char *init_seg_name; > > @@ -432,6 +433,8 @@ static void write_hls_media_playlist(OutputStream > *os, AVFormatContext *s, > > const char *proto = avio_find_protocol_name(c->dirname); > > int use_rename = proto && !strcmp(proto, "file"); > > int i, start_index, start_number; > > +time_t start_time_s = c->start_time_ms / 1000; > > +double prog_date_time = start_time_s; > > > > get_start_index_number(os, c, _index, _number); > > > > @@ -464,16 +467,21 @@ static void write_hls_media_playlist(OutputStream > *os, AVFormatContext *s, > > ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file, > > os->init_range_length, os->init_start_pos); > > > > -for (i = start_index; i < os->nb_segments; i++) { > > +for (i = 0; i < os->nb_segments; i++) { > > Segment *seg = os->segments[i]; > > -ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > > -(double) seg->duration / timescale, 0, > > -seg->range_length, seg->start_pos, NULL, > > -c->single_file ? os->initfile : > seg->file, > > -NULL); > > -if (ret < 0) { > > -av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry > get error\n"); > > +double duration = (double) seg->duration / timescale; > > +if (i >= start_index) { > > +double prog_date_time_copy = prog_date_time; > > +ret = ff_hls_write_file_entry(c->m3u8_out, 0, > c->single_file, > > +duration, 0, > > +seg->range_length, seg->start_pos, > NULL, > > +c->single_file ? os->initfile : > seg->file, > > +_date_time_copy); > > +if (ret < 0) { > > +av_log(os->ctx, AV_LOG_WARNING, > "ff_hls_write_file_entry get error\n"); > > +} > > } > > +prog_date_time += duration; > Hi Joep, > > It is great to see that you are submitting your changes back to the > community for improving dashenc features. > Really appreciate your effort on this. Thank you very much. > > In terms for the actual changes, I have review comment. The algorithmic > complexity for calculating prog_date_time will increase with the time > software has been running continuously. For example, if the software has > been running for seven days continuously (with window_size parameter > enabled for a live input), it will take smaller cpu time to compute > prog_date_time on the first day, and much longer time on the seventh day. > Such kind of algorithms affect the stability of the software in > long-duration runs for live input. Could you please modify the algorithm so > that the prog_date_time calculation's complexity doesn't increase linearly > with time. > > Regards, > Karthick > > } > > > > if (prefetch_url) > > @@ -1583,9 +1591,12 @@ static int dash_write_packet(AVFormatContext *s, > AVPacket *pkt) > > os->first_pts = pkt->pts; > > os->last_pts = pkt->pts; > > > > -if (!c->availability_start_time[0]) > > +if (!c->availability_start_time[0]) { > > +int64_t start_time_us = av_gettime(); > > +c->start_time_ms = start_time_us / 1000; > > format_date_now(c->availability_start_time, > > sizeof(c->availability_start_time)); > > +} > > > > if (!os->availability_time_offset && pkt->duration) { > > int64_t frame_duration = av_rescale_q(pkt->duration, > st->time_base, > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
On 2/22/19 12:25 PM, joepadmiraal wrote: > From: joepadmiraal > > --- > libavformat/dashenc.c | 29 - > 1 file changed, 20 insertions(+), 9 deletions(-) > > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c > index 37a7547b12..d0d0d6f030 100644 > --- a/libavformat/dashenc.c > +++ b/libavformat/dashenc.c > @@ -122,6 +122,7 @@ typedef struct DASHContext { > int64_t last_duration; > int64_t total_duration; > char availability_start_time[100]; > +int64_t start_time_ms; > char dirname[1024]; > const char *single_file_name; /* file names as specified in options */ > const char *init_seg_name; > @@ -432,6 +433,8 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > const char *proto = avio_find_protocol_name(c->dirname); > int use_rename = proto && !strcmp(proto, "file"); > int i, start_index, start_number; > +time_t start_time_s = c->start_time_ms / 1000; > +double prog_date_time = start_time_s; > > get_start_index_number(os, c, _index, _number); > > @@ -464,16 +467,21 @@ static void write_hls_media_playlist(OutputStream *os, > AVFormatContext *s, > ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file, > os->init_range_length, os->init_start_pos); > > -for (i = start_index; i < os->nb_segments; i++) { > +for (i = 0; i < os->nb_segments; i++) { > Segment *seg = os->segments[i]; > -ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > -(double) seg->duration / timescale, 0, > -seg->range_length, seg->start_pos, NULL, > -c->single_file ? os->initfile : seg->file, > -NULL); > -if (ret < 0) { > -av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get > error\n"); > +double duration = (double) seg->duration / timescale; > +if (i >= start_index) { > +double prog_date_time_copy = prog_date_time; > +ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, > +duration, 0, > +seg->range_length, seg->start_pos, NULL, > +c->single_file ? os->initfile : > seg->file, > +_date_time_copy); > +if (ret < 0) { > +av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get > error\n"); > +} > } > +prog_date_time += duration; Hi Joep, It is great to see that you are submitting your changes back to the community for improving dashenc features. Really appreciate your effort on this. Thank you very much. In terms for the actual changes, I have review comment. The algorithmic complexity for calculating prog_date_time will increase with the time software has been running continuously. For example, if the software has been running for seven days continuously (with window_size parameter enabled for a live input), it will take smaller cpu time to compute prog_date_time on the first day, and much longer time on the seventh day. Such kind of algorithms affect the stability of the software in long-duration runs for live input. Could you please modify the algorithm so that the prog_date_time calculation's complexity doesn't increase linearly with time. Regards, Karthick > } > > if (prefetch_url) > @@ -1583,9 +1591,12 @@ static int dash_write_packet(AVFormatContext *s, > AVPacket *pkt) > os->first_pts = pkt->pts; > os->last_pts = pkt->pts; > > -if (!c->availability_start_time[0]) > +if (!c->availability_start_time[0]) { > +int64_t start_time_us = av_gettime(); > +c->start_time_ms = start_time_us / 1000; > format_date_now(c->availability_start_time, > sizeof(c->availability_start_time)); > +} > > if (!os->availability_time_offset && pkt->duration) { > int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
From: joepadmiraal --- libavformat/dashenc.c | 29 - 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 37a7547b12..d0d0d6f030 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -122,6 +122,7 @@ typedef struct DASHContext { int64_t last_duration; int64_t total_duration; char availability_start_time[100]; +int64_t start_time_ms; char dirname[1024]; const char *single_file_name; /* file names as specified in options */ const char *init_seg_name; @@ -432,6 +433,8 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, const char *proto = avio_find_protocol_name(c->dirname); int use_rename = proto && !strcmp(proto, "file"); int i, start_index, start_number; +time_t start_time_s = c->start_time_ms / 1000; +double prog_date_time = start_time_s; get_start_index_number(os, c, _index, _number); @@ -464,16 +467,21 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file, os->init_range_length, os->init_start_pos); -for (i = start_index; i < os->nb_segments; i++) { +for (i = 0; i < os->nb_segments; i++) { Segment *seg = os->segments[i]; -ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, -(double) seg->duration / timescale, 0, -seg->range_length, seg->start_pos, NULL, -c->single_file ? os->initfile : seg->file, -NULL); -if (ret < 0) { -av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); +double duration = (double) seg->duration / timescale; +if (i >= start_index) { +double prog_date_time_copy = prog_date_time; +ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, +duration, 0, +seg->range_length, seg->start_pos, NULL, +c->single_file ? os->initfile : seg->file, +_date_time_copy); +if (ret < 0) { +av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); +} } +prog_date_time += duration; } if (prefetch_url) @@ -1583,9 +1591,12 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->first_pts = pkt->pts; os->last_pts = pkt->pts; -if (!c->availability_start_time[0]) +if (!c->availability_start_time[0]) { +int64_t start_time_us = av_gettime(); +c->start_time_ms = start_time_us / 1000; format_date_now(c->availability_start_time, sizeof(c->availability_start_time)); +} if (!os->availability_time_offset && pkt->duration) { int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, -- 2.17.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists
From: joepadmiraal --- libavformat/dashenc.c | 29 - 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 37a7547b12..d0d0d6f030 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -122,6 +122,7 @@ typedef struct DASHContext { int64_t last_duration; int64_t total_duration; char availability_start_time[100]; +int64_t start_time_ms; char dirname[1024]; const char *single_file_name; /* file names as specified in options */ const char *init_seg_name; @@ -432,6 +433,8 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, const char *proto = avio_find_protocol_name(c->dirname); int use_rename = proto && !strcmp(proto, "file"); int i, start_index, start_number; +time_t start_time_s = c->start_time_ms / 1000; +double prog_date_time = start_time_s; get_start_index_number(os, c, _index, _number); @@ -464,16 +467,21 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file, os->init_range_length, os->init_start_pos); -for (i = start_index; i < os->nb_segments; i++) { +for (i = 0; i < os->nb_segments; i++) { Segment *seg = os->segments[i]; -ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, -(double) seg->duration / timescale, 0, -seg->range_length, seg->start_pos, NULL, -c->single_file ? os->initfile : seg->file, -NULL); -if (ret < 0) { -av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); +double duration = (double) seg->duration / timescale; +if (i >= start_index) { +double prog_date_time_copy = prog_date_time; +ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file, +duration, 0, +seg->range_length, seg->start_pos, NULL, +c->single_file ? os->initfile : seg->file, +_date_time_copy); +if (ret < 0) { +av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); +} } +prog_date_time += duration; } if (prefetch_url) @@ -1583,9 +1591,12 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) os->first_pts = pkt->pts; os->last_pts = pkt->pts; -if (!c->availability_start_time[0]) +if (!c->availability_start_time[0]) { +int64_t start_time_us = av_gettime(); +c->start_time_ms = start_time_us / 1000; format_date_now(c->availability_start_time, sizeof(c->availability_start_time)); +} if (!os->availability_time_offset && pkt->duration) { int64_t frame_duration = av_rescale_q(pkt->duration, st->time_base, -- 2.17.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel