[FFmpeg-devel] [PATCH 2/2] img2: revised timestamp in output pattern patch
Yuval Adam
yuv.adm at gmail.com
Wed Jan 4 13:48:23 CET 2012
From: Yuval Adam <yuv.adm at gmail.com>
Deprecated av_get_frame_filename API
Added av_get_frame_filename2 which supports frame timestamps
Various stability fixes and error handling
Signed-off-by: Yuval Adam <yuv.adm at gmail.com>
---
libavformat/avformat.h | 12 ++++++++++--
libavformat/img2.c | 10 +++++-----
libavformat/utils.c | 24 ++++++++++++++++++++----
libavformat/version.h | 3 +++
4 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index a9ab0cc..bb3376b 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2066,6 +2066,14 @@ int64_t av_gettime(void);
attribute_deprecated int find_info_tag(char *arg, int arg_size, const char
*tag1, const char *info);
#endif
+#if FF_API_GET_FRAME_FILENAME
+/**
+ * Deprecated. Use av_get_frame_filename2 which supports %t.
+ */
+attribute_deprecated int av_get_frame_filename(char *buf, int buf_size,
+ const char *path, int
number);
+#endif
+
/**
* Return in 'buf' the path with '%d' replaced by the frame number,
* and '%t' replaced by the frame timestamp.
@@ -2080,8 +2088,8 @@ attribute_deprecated int find_info_tag(char *arg, int
arg_size, const char *tag1
* @param ts frame timestamp in seconds
* @return 0 if OK, -1 on format error
*/
-int av_get_frame_filename(char *buf, int buf_size,
- const char *path, int number, int ts);
+int av_get_frame_filename2(char *buf, int buf_size,
+ const char *path, int number, int ts);
/**
* Check whether filename actually is a numbered sequence generator.
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 8012e5b..820bed2 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -142,7 +142,7 @@ static int find_image_range(int *pfirst_index, int
*plast_index,
/* find the first image */
for(first_index = 0; first_index < 5; first_index++) {
- if (av_get_frame_filename(buf, sizeof(buf), path, first_index, 0)
< 0){
+ if (av_get_frame_filename(buf, sizeof(buf), path, first_index) <
0){
*pfirst_index =
*plast_index = 1;
if (avio_check(buf, AVIO_FLAG_READ) > 0)
@@ -165,7 +165,7 @@ static int find_image_range(int *pfirst_index, int
*plast_index,
else
range1 = 2 * range;
if (av_get_frame_filename(buf, sizeof(buf), path,
- last_index + range1, 0) < 0)
+ last_index + range1) < 0)
goto fail;
if (avio_check(buf, AVIO_FLAG_READ) <= 0)
break;
@@ -310,7 +310,7 @@ static int read_packet(AVFormatContext *s1, AVPacket
*pkt)
if (s->img_number > s->img_last)
return AVERROR_EOF;
if (av_get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number, 0)<0 &&
s->img_number > 1)
+ s->path, s->img_number)<0 &&
s->img_number > 1)
return AVERROR(EIO);
for(i=0; i<3; i++){
if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
@@ -393,10 +393,10 @@ static int write_packet(AVFormatContext *s, AVPacket
*pkt)
AVCodecContext *codec = stream->codec;
int i;
- int ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q) /
AV_TIME_BASE;
+ int ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q);
if (!img->is_pipe) {
- if (av_get_frame_filename(filename, sizeof(filename),
+ if (av_get_frame_filename2(filename, sizeof(filename),
img->path, img->img_number, ts) < 0 &&
img->img_number>1 && !img->updatefirst) {
av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern
'%s'\n",
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 311b6ed..df4852b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -326,7 +326,7 @@ int av_append_packet(AVIOContext *s, AVPacket *pkt, int
size)
int av_filename_number_test(const char *filename)
{
char buf[1024];
- return filename && (av_get_frame_filename(buf, sizeof(buf), filename,
1, 0)>=0);
+ return filename && (av_get_frame_filename(buf, sizeof(buf), filename,
1)>=0);
}
AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int
*score_ret)
@@ -3780,13 +3780,13 @@ int find_info_tag(char *arg, int arg_size, const
char *tag1, const char *info)
}
#endif
-int av_get_frame_filename(char *buf, int buf_size,
+int av_get_frame_filename2(char *buf, int buf_size,
const char *path, int number, int ts)
{
const char *p;
char *q, buf1[20], c;
int nd, len, percent_found;
- int hours, mins, secs;
+ int hours, mins, secs, ms;
q = buf;
p = path;
@@ -3821,14 +3821,18 @@ int av_get_frame_filename(char *buf, int buf_size,
case 't':
if (percent_found)
goto fail;
+ if (ts < 1)
+ goto fail;
percent_found = 1;
+ ms = ts % (AV_TIME_BASE / 1000);
+ ts /= AV_TIME_BASE;
secs = ts % 60;
ts /= 60;
mins = ts % 60;
ts /= 60;
hours = ts;
snprintf(buf1, sizeof(buf1),
- "%02d:%02d:%02d", hours, mins, secs);
+ "%02d.%02d.%02d.%03d", hours, mins, secs, ms);
len = strlen(buf1);
if ((q - buf + len) > buf_size - 1)
goto fail;
@@ -3853,6 +3857,18 @@ int av_get_frame_filename(char *buf, int buf_size,
return -1;
}
+#if FF_API_GET_FRAME_FILENAME
+int av_get_frame_filename(char *buf, int buf_size,
+ const char *path, int number)
+{
+ /*
+ * old versions don't support timestamps in filename (%t)
+ * so just pass 0 as the frame timestamp
+ */
+ return av_get_frame_filename2(buf, buf_size, path, number, 0);
+}
+#endif
+
static void hex_dump_internal(void *avcl, FILE *f, int level, uint8_t
*buf, int size)
{
int len, i, j, c;
diff --git a/libavformat/version.h b/libavformat/version.h
index 4c73dbf..0cacac9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -128,5 +128,8 @@
#ifndef FF_API_CLOSE_INPUT_FILE
#define FF_API_CLOSE_INPUT_FILE (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
+#ifndef FF_API_GET_FRAME_FILENAME
+#define FF_API_GET_FRAME_FILENAME (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
#endif /* AVFORMAT_VERSION_H */
--
1.7.2.2
More information about the ffmpeg-devel
mailing list