From: Dave Johansen <davejohansen@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Dave Johansen <davejohansen@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: Add strftime_prog for using PROGRAM-DATE-TIME in the segment filename Date: Thu, 26 Oct 2023 21:59:39 -0600 Message-ID: <20231027035941.23491-2-davejohansen@gmail.com> (raw) In-Reply-To: <20231027035941.23491-1-davejohansen@gmail.com> --- libavformat/hlsenc.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 5dfff6b2b6..24a0304f78 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -159,6 +159,7 @@ typedef struct VariantStream { char *m3u8_name; double initial_prog_date_time; + double curr_prog_date_time; char current_segment_final_filename_fmt[MAX_URL_SIZE]; // when renaming segments char *fmp4_init_filename; @@ -208,6 +209,7 @@ typedef struct HLSContext { int use_localtime; ///< flag to expand filename with localtime int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename + int use_localtime_prog; ///< flag to expand filename with prog date time int allowcache; int64_t recording_time; int64_t max_seg_size; // every segment file max size @@ -259,10 +261,9 @@ typedef struct HLSContext { int has_video_m3u8; /* has video stream m3u8 list */ } HLSContext; -static int strftime_expand(const char *fmt, char **dest) +static int strftime_expand_time_t(const char *fmt, const time_t *value, char **dest) { int r = 1; - time_t now0; struct tm *tm, tmpbuf; char *buf; @@ -270,8 +271,7 @@ static int strftime_expand(const char *fmt, char **dest) if (!buf) return AVERROR(ENOMEM); - time(&now0); - tm = localtime_r(&now0, &tmpbuf); + tm = localtime_r(value, &tmpbuf); r = strftime(buf, MAX_URL_SIZE, fmt, tm); if (!r) { av_free(buf); @@ -282,6 +282,19 @@ static int strftime_expand(const char *fmt, char **dest) return r; } +static int strftime_expand(const char *fmt, char **dest) +{ + time_t now0; + time(&now0); + return strftime_expand_time_t(fmt, &now0, dest); +} + +static int strftime_expand_prog(const char *fmt, const double prog_date_time, char **dest) +{ + time_t value = (time_t)prog_date_time; + return strftime_expand_time_t(fmt, &value, dest); +} + static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, const char *filename, AVDictionary **options) { @@ -1721,7 +1734,11 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) int r; char *expanded = NULL; - r = strftime_expand(vs->basename, &expanded); + if (c->use_localtime_prog) { + r = strftime_expand_prog(vs->basename, vs->curr_prog_date_time, &expanded); + } else { + r = strftime_expand(vs->basename, &expanded); + } if (r < 0) { av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); return r; @@ -2615,6 +2632,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) { double cur_duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den; ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size); + vs->curr_prog_date_time += cur_duration; vs->end_pts = pkt->pts; vs->duration = 0; if (ret < 0) { @@ -2971,6 +2989,7 @@ static int hls_init(AVFormatContext *s) vs->end_pts = AV_NOPTS_VALUE; vs->current_segment_final_filename_fmt[0] = '\0'; vs->initial_prog_date_time = initial_program_date_time; + vs->curr_prog_date_time = initial_program_date_time; for (j = 0; j < vs->nb_streams; j++) { vs->has_video += vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; @@ -3038,7 +3057,11 @@ static int hls_init(AVFormatContext *s) int r; char *expanded = NULL; - r = strftime_expand(vs->fmp4_init_filename, &expanded); + if (hls->use_localtime_prog) { + r = strftime_expand_prog(vs->fmp4_init_filename, vs->curr_prog_date_time, &expanded); + } else { + r = strftime_expand(vs->fmp4_init_filename, &expanded); + } if (r < 0) { av_log(s, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); return r; @@ -3158,6 +3181,7 @@ static const AVOption options[] = { {"iframes_only", "add EXT-X-I-FRAMES-ONLY, whenever applicable", 0, AV_OPT_TYPE_CONST, { .i64 = HLS_I_FRAMES_ONLY }, 0, UINT_MAX, E, "flags"}, {"strftime", "set filename expansion with strftime at segment creation", OFFSET(use_localtime), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, {"strftime_mkdir", "create last directory component in strftime-generated filename", OFFSET(use_localtime_mkdir), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, + {"strftime_prog", "set filename expanish with program date time", OFFSET(use_localtime_prog), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, {"hls_playlist_type", "set the HLS playlist type", OFFSET(pl_type), AV_OPT_TYPE_INT, {.i64 = PLAYLIST_TYPE_NONE }, 0, PLAYLIST_TYPE_NB-1, E, "pl_type" }, {"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" }, -- 2.39.2 (Apple Git-143) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-10-27 4:00 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-27 3:59 [FFmpeg-devel] [PATCH 1/4] avformat/hlsenc: Add init_program_date_time so start time can be specified Dave Johansen 2023-10-27 3:59 ` Dave Johansen [this message] 2023-10-27 3:59 ` [FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: Fix name of flag in error message Dave Johansen 2023-10-27 7:58 ` Steven Liu 2023-10-27 3:59 ` [FFmpeg-devel] [PATCH 4/4] avformat/hlsenc: Add second_level_segment_microsecond for using %%f to specify microseconds of time in segment filename Dave Johansen 2023-10-27 10:58 ` [FFmpeg-devel] [PATCH 1/4] avformat/hlsenc: Add init_program_date_time so start time can be specified epirat07 2023-10-27 21:28 ` [FFmpeg-devel] [PATCH] avformat/hlsenc: Handle when fractional seconds not set and error out when init_program_date_time can't be parsed Dave Johansen 2023-10-27 21:32 ` [FFmpeg-devel] [PATCH 1/4] avformat/hlsenc: Add init_program_date_time so start time can be specified David Johansen 2023-11-05 8:20 ` Marton Balint 2023-11-07 0:31 ` [FFmpeg-devel] [PATCH] Use existing function to parse time Dave Johansen 2023-11-08 23:45 ` [FFmpeg-devel] [PATCH 1/4] avformat/hlsenc: Add init_program_date_time so start time can be specified David Johansen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231027035941.23491-2-davejohansen@gmail.com \ --to=davejohansen@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git