[FFmpeg-devel] [PATCH] Support 64-bit integers for av_get_frame_filename2()

Devin Heitmueller dheitmueller at ltnglobal.com
Fri Aug 24 21:56:03 EEST 2018


Create a new av_get_frame_filename3() API which is just like the
previous version but accepts a 64-bit integer for the "number"
argument.  This is useful in cases where you want to put the
original PTS into the filename (which can be larger than 32-bits).

Tested with:

./ffmpeg -copyts -vsync 0 -i foo.ts -frame_pts 1 -enc_time_base -1 foo_%d.png

Signed-off-by: Devin Heitmueller <dheitmueller at ltnglobal.com>
---
 libavformat/avformat.h | 2 ++
 libavformat/img2enc.c  | 2 +-
 libavformat/utils.c    | 9 +++++++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index fdaffa5bf4..c358a9a71e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2896,6 +2896,8 @@ void av_dump_format(AVFormatContext *ic,
  * @param flags AV_FRAME_FILENAME_FLAGS_*
  * @return 0 if OK, -1 on format error
  */
+int av_get_frame_filename3(char *buf, int buf_size,
+                          const char *path, int64_t number, int flags);
 int av_get_frame_filename2(char *buf, int buf_size,
                           const char *path, int number, int flags);
 
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index a09cc8ec50..414eb827e2 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -101,7 +101,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
                 return AVERROR(EINVAL);
             }
         } else if (img->frame_pts) {
-            if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
+            if (av_get_frame_filename3(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
                 av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames.");
                 return AVERROR(EINVAL);
             }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index b0b5e164a6..d9d4d38a44 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4666,7 +4666,7 @@ uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
     return ntp_ts;
 }
 
-int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
+int av_get_frame_filename3(char *buf, int buf_size, const char *path, int64_t number, int flags)
 {
     const char *p;
     char *q, buf1[20], c;
@@ -4696,7 +4696,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;
@@ -4721,6 +4721,11 @@ fail:
     return -1;
 }
 
+int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
+{
+    return av_get_frame_filename3(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);
-- 
2.13.2



More information about the ffmpeg-devel mailing list