[FFmpeg-devel] [PATCH v2 1/2] avformat/internal: Add ff_get_frame_filename
Zhao Zhili
quinkblack at foxmail.com
Mon Sep 23 18:14:19 EEST 2024
From: Zhao Zhili <zhilizhao at tencent.com>
It's similar to av_get_frame_filename2 but with int64_t number
support. Make av_get_frame_filename* a wrapper over
ff_get_frame_filename.
Co-authored-by: Filip Mašić <shoutplenty at gmail.com>
---
libavformat/internal.h | 16 ++++++++++++++++
libavformat/utils.c | 11 ++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8e8971bfeb..6c026f08a0 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -745,6 +745,22 @@ void ff_format_set_url(AVFormatContext *s, char *url);
*/
int ff_match_url_ext(const char *url, const char *extensions);
+/**
+ * Return in 'buf' the path with '%d' replaced by a number.
+ *
+ * Also handles the '%0nd' format where 'n' is the total number
+ * of digits and '%%'.
+ *
+ * @param buf destination buffer
+ * @param buf_size destination buffer size
+ * @param path path with substitution template
+ * @param number the number to substitute
+ * @param flags AV_FRAME_FILENAME_FLAGS_*
+ * @return 0 if OK, -1 on format error
+ */
+int ff_get_frame_filename(char *buf, int buf_size, const char *path,
+ int64_t number, int flags);
+
struct FFOutputFormat;
struct FFInputFormat;
void avpriv_register_devices(const struct FFOutputFormat * const o[],
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e9ded627ad..e892e8bde7 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -280,7 +280,7 @@ uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
return (sec * 1000000) + usec;
}
-int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
+int ff_get_frame_filename(char *buf, int buf_size, const char *path, int64_t number, int flags)
{
const char *p;
char *q, buf1[20], c;
@@ -313,7 +313,7 @@ int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number
percentd_found = 1;
if (number < 0)
nd += 1;
- snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
+ snprintf(buf1, sizeof(buf1), "%0*" PRId64, nd, number);
len = strlen(buf1);
if ((q - buf + len) > buf_size - 1)
goto fail;
@@ -338,9 +338,14 @@ fail:
return -1;
}
+int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
+{
+ return ff_get_frame_filename(buf, buf_size, path, number, flags);
+}
+
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
{
- return av_get_frame_filename2(buf, buf_size, path, number, 0);
+ return ff_get_frame_filename(buf, buf_size, path, number, 0);
}
void av_url_split(char *proto, int proto_size,
--
2.42.0
More information about the ffmpeg-devel
mailing list