From: Dave Johansen <davejohansen@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Dave Johansen <davejohansen@gmail.com>
Subject: [FFmpeg-devel] [PATCH] Use existing function to parse time
Date: Mon, 6 Nov 2023 17:31:35 -0700
Message-ID: <20231107003135.15169-1-davejohansen@gmail.com> (raw)
In-Reply-To: <544b328c-e2a2-981-9f9c-e692d1d33c18@passwd.hu>
---
libavformat/hlsenc.c | 32 +++++++-------------------------
1 file changed, 7 insertions(+), 25 deletions(-)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e1714d4eed..1baefe852f 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -35,6 +35,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "libavutil/log.h"
+#include "libavutil/parseutils.h"
#include "libavutil/random_seed.h"
#include "libavutil/time.h"
#include "libavutil/time_internal.h"
@@ -1251,27 +1252,6 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
return 0;
}
-static double parse_iso8601(const char *ptr) {
- struct tm program_date_time;
- int y,M,d,h,m;
- double s;
- int num_scanned = sscanf(ptr, "%d-%d-%dT%d:%d:%lf", &y, &M, &d, &h, &m, &s);
-
- if (num_scanned < 6) {
- return -1;
- }
-
- program_date_time.tm_year = y - 1900;
- program_date_time.tm_mon = M - 1;
- program_date_time.tm_mday = d;
- program_date_time.tm_hour = h;
- program_date_time.tm_min = m;
- program_date_time.tm_sec = 0;
- program_date_time.tm_isdst = -1;
-
- return mktime(&program_date_time) + s;
-}
-
static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs)
{
HLSContext *hls = s->priv_data;
@@ -1281,6 +1261,7 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs
char line[MAX_URL_SIZE];
const char *ptr;
const char *end;
+ int64_t parsed_time;
double discont_program_date_time = 0;
if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ,
@@ -1337,11 +1318,11 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs
}
}
} else if (av_strstart(line, "#EXT-X-PROGRAM-DATE-TIME:", &ptr)) {
- discont_program_date_time = parse_iso8601(ptr);
- if (discont_program_date_time < 0) {
+ if (av_parse_time(&parsed_time, ptr, 0)) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
+ discont_program_date_time = parsed_time / 1000000.0;
} else if (av_strstart(line, "#", NULL)) {
continue;
} else if (line[0]) {
@@ -2933,6 +2914,7 @@ static int hls_init(AVFormatContext *s)
int i = 0;
int j = 0;
HLSContext *hls = s->priv_data;
+ int64_t parsed_time;
const char *pattern;
VariantStream *vs = NULL;
const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt";
@@ -2942,11 +2924,11 @@ static int hls_init(AVFormatContext *s)
double initial_program_date_time;
if (hls->init_program_date_time) {
- initial_program_date_time = parse_iso8601(hls->init_program_date_time);
- if (initial_program_date_time < 0) {
+ if (av_parse_time(&parsed_time, hls->init_program_date_time, 0)) {
av_log(s, AV_LOG_ERROR, "Invalid init_program_date_time\n");
return AVERROR(EINVAL);
}
+ initial_program_date_time = parsed_time / 1000000.0;
} else {
initial_program_date_time = av_gettime() / 1000000.0;
}
--
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-11-07 0:31 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 ` [FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: Add strftime_prog for using PROGRAM-DATE-TIME in the segment filename Dave Johansen
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 ` Dave Johansen [this message]
2023-11-08 23:45 ` 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=20231107003135.15169-1-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