From ff295f760246e99a1f27d562557840f9262ec706 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <marcus@compuccino.com>
Date: Wed, 27 Sep 2017 12:30:11 +0200
Subject: [PATCH] Added the option to extract images with timecode as token
---
doc/muxers.texi | 3 +++
libavformat/avformat.h | 3 ++-
libavformat/img2enc.c | 7 +++++--
libavformat/utils.c | 29 ++++++++++++++++++++++++++---
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index 38d9391..9e3cabc 100644
|
a
|
b
|
If the pattern contains "%d" or "%0@var{N}d", the first filename of
|
| 849 | 849 | the file list specified will contain the number 1, all the following |
| 850 | 850 | numbers will be sequential. |
| 851 | 851 | |
| | 852 | The pattern can also contain "%t" which writes out the timestamp of the |
| | 853 | frame in the format "HH.mm.ss.fff" |
| | 854 | |
| 852 | 855 | The pattern may contain a suffix which is used to automatically |
| 853 | 856 | determine the format of the image files to write. |
| 854 | 857 | |
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index b0de66a..e05b4f1 100644
|
a
|
b
|
void av_dump_format(AVFormatContext *ic,
|
| 2817 | 2817 | * @param path numbered sequence string |
| 2818 | 2818 | * @param number frame number |
| 2819 | 2819 | * @param flags AV_FRAME_FILENAME_FLAGS_* |
| | 2820 | * @param ts frame timestamp in seconds |
| 2820 | 2821 | * @return 0 if OK, -1 on format error |
| 2821 | 2822 | */ |
| 2822 | 2823 | int av_get_frame_filename2(char *buf, int buf_size, |
| 2823 | | const char *path, int number, int flags); |
| | 2824 | const char *path, int number, int flags, int64_t ts); |
| 2824 | 2825 | |
| 2825 | 2826 | int av_get_frame_filename(char *buf, int buf_size, |
| 2826 | 2827 | const char *path, int number); |
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index d793807..60ce38d 100644
|
a
|
b
|
static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
| 83 | 83 | AVIOContext *pb[4]; |
| 84 | 84 | char filename[1024]; |
| 85 | 85 | AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; |
| | 86 | AVStream *stream = s->streams[ pkt->stream_index ]; |
| | 87 | AVCodecContext *codec = stream->codec; |
| 86 | 88 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format); |
| 87 | 89 | int i; |
| 88 | 90 | int nb_renames = 0; |
| | 91 | int64_t ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q); |
| 89 | 92 | |
| 90 | 93 | if (!img->is_pipe) { |
| 91 | 94 | if (img->update) { |
| … |
… |
static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
| 100 | 103 | return AVERROR(EINVAL); |
| 101 | 104 | } |
| 102 | 105 | } else if (av_get_frame_filename2(filename, sizeof(filename), img->path, |
| 103 | | img->img_number, |
| 104 | | AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 && |
| | 106 | img->img_number, 0, |
| | 107 | ts) < 0 && |
| 105 | 108 | img->img_number > 1) { |
| 106 | 109 | av_log(s, AV_LOG_ERROR, |
| 107 | 110 | "Could not get frame filename number %d from pattern '%s' (either set updatefirst or use a pattern like %%03d within the filename pattern)\n", |
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7abca63..7dba942 100644
|
a
|
b
|
|
| 21 | 21 | |
| 22 | 22 | #include <stdarg.h> |
| 23 | 23 | #include <stdint.h> |
| | 24 | #include <ctype.h> |
| 24 | 25 | |
| 25 | 26 | #include "config.h" |
| 26 | 27 | |
| … |
… |
uint64_t ff_ntp_time(void)
|
| 4556 | 4557 | return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; |
| 4557 | 4558 | } |
| 4558 | 4559 | |
| 4559 | | int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags) |
| | 4560 | int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags, int64_t ts) |
| 4560 | 4561 | { |
| 4561 | 4562 | const char *p; |
| 4562 | 4563 | char *q, buf1[20], c; |
| 4563 | 4564 | int nd, len, percentd_found; |
| | 4565 | int hours, mins, secs, ms; |
| 4564 | 4566 | |
| 4565 | 4567 | q = buf; |
| 4566 | 4568 | p = path; |
| … |
… |
int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number
|
| 4593 | 4595 | memcpy(q, buf1, len); |
| 4594 | 4596 | q += len; |
| 4595 | 4597 | break; |
| | 4598 | case 't': |
| | 4599 | if (percentd_found) |
| | 4600 | goto fail; |
| | 4601 | if (ts < 1) |
| | 4602 | goto fail; |
| | 4603 | percentd_found = 1; |
| | 4604 | ms = (ts/1000)%1000; |
| | 4605 | ts /= AV_TIME_BASE; |
| | 4606 | secs = ts % 60; |
| | 4607 | ts /= 60; |
| | 4608 | mins = ts % 60; |
| | 4609 | ts /= 60; |
| | 4610 | hours = ts; |
| | 4611 | snprintf(buf1, sizeof(buf1), |
| | 4612 | "%02d.%02d.%02d.%03d", hours, mins, secs, ms); |
| | 4613 | len = strlen(buf1); |
| | 4614 | if ((q - buf + len) > buf_size - 1) |
| | 4615 | goto fail; |
| | 4616 | memcpy(q, buf1, len); |
| | 4617 | q += len; |
| | 4618 | break; |
| 4596 | 4619 | default: |
| 4597 | 4620 | goto fail; |
| 4598 | 4621 | } |
| 4599 | 4622 | } else { |
| 4600 | | addchar: |
| | 4623 | addchar: |
| 4601 | 4624 | if ((q - buf) < buf_size - 1) |
| 4602 | 4625 | *q++ = c; |
| 4603 | 4626 | } |
| … |
… |
fail:
|
| 4613 | 4636 | |
| 4614 | 4637 | int av_get_frame_filename(char *buf, int buf_size, const char *path, int number) |
| 4615 | 4638 | { |
| 4616 | | return av_get_frame_filename2(buf, buf_size, path, number, 0); |
| | 4639 | return av_get_frame_filename2(buf, buf_size, path, number, 0, 0); |
| 4617 | 4640 | } |
| 4618 | 4641 | |
| 4619 | 4642 | void av_url_split(char *proto, int proto_size, |