@@ -1384,6 +1384,9 @@ If the pattern contains "%d" or "%0@var{N}d", the first filename of
the file list specified will contain the number 1, all the following
numbers will be sequential.
+The pattern can also contain "%t" which writes out the timestamp of the
+frame in the format "HH.mm.ss.fff"
+
The pattern may contain a suffix which is used to automatically
determine the format of the image files to write.
@@ -2602,10 +2602,11 @@ void av_dump_format(AVFormatContext *ic,
* @param path numbered sequence string
* @param number frame number
* @param flags AV_FRAME_FILENAME_FLAGS_*
+ * @param ts frame timestamp in seconds
* @return 0 if OK, -1 on format error
*/
int av_get_frame_filename2(char *buf, int buf_size,
- const char *path, int number, int flags);
+ const char *path, int number, int flags, int64_t ts);
int av_get_frame_filename(char *buf, int buf_size,
const char *path, int number);
@@ -131,9 +131,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext *pb[4] = {0};
char filename[1024];
AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
+ AVStream *stream = s->streams[ pkt->stream_index ];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format);
int ret, i;
int nb_renames = 0;
+ int64_t ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q);
AVDictionary *options = NULL;
if (img->update) {
@@ -148,13 +150,13 @@ 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_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE, 0) < 0) {
av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames.");
return AVERROR(EINVAL);
}
} else if (av_get_frame_filename2(filename, sizeof(filename), img->path,
- img->img_number,
- AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
+ img->img_number, 0,
+ ts) < 0 &&
img->img_number > 1) {
av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern '%s'. "
@@ -4589,15 +4589,17 @@ 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 av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags, int64_t ts)
{
const char *p;
char *q, buf1[20], c;
- int nd, len, percentd_found;
+ int nd, len, percentd_found, percentt_found;
+ int hours, mins, secs, ms;
q = buf;
p = path;
percentd_found = 0;
+ percentt_found = 0;
for (;;) {
c = *p++;
if (c == '\0')
@@ -4629,6 +4631,27 @@ int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number
memcpy(q, buf1, len);
q += len;
break;
+ case 't':
+ if (percentd_found)
+ goto fail;
+ if (ts < 0)
+ goto fail;
+ percentt_found = 1;
+ ms = (ts/1000)%1000;
+ ts /= AV_TIME_BASE;
+ secs = ts % 60;
+ ts /= 60;
+ mins = ts % 60;
+ ts /= 60;
+ hours = ts;
+ snprintf(buf1, sizeof(buf1),
+ "%02d.%02d.%02d.%03d", hours, mins, secs, ms);
+ len = strlen(buf1);
+ if ((q - buf + len) > buf_size - 1)
+ goto fail;
+ memcpy(q, buf1, len);
+ q += len;
+ break;
default:
goto fail;
}
@@ -4638,7 +4661,7 @@ addchar:
*q++ = c;
}
}
- if (!percentd_found)
+ if (!(percentd_found || percentt_found))
goto fail;
*q = '\0';
return 0;
@@ -4649,7 +4672,7 @@ fail:
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 av_get_frame_filename2(buf, buf_size, path, number, 0, 0);
}
void av_url_split(char *proto, int proto_size,