Ticket #1452: 0001-Added-the-option-to-extract-images-with-timecode-as-.patch

File 0001-Added-the-option-to-extract-images-with-timecode-as-.patch, 5.2 KB (added by marcusjohansson, 9 years ago)

Fix for %t as timestamp

  • doc/muxers.texi

    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  
    849849the file list specified will contain the number 1, all the following
    850850numbers will be sequential.
    851851
     852The pattern can also contain "%t" which writes out the timestamp of the
     853frame in the format "HH.mm.ss.fff"
     854
    852855The pattern may contain a suffix which is used to automatically
    853856determine the format of the image files to write.
    854857
  • libavformat/avformat.h

    diff --git a/libavformat/avformat.h b/libavformat/avformat.h
    index b0de66a..e05b4f1 100644
    a b void av_dump_format(AVFormatContext *ic,  
    28172817 * @param path numbered sequence string
    28182818 * @param number frame number
    28192819 * @param flags AV_FRAME_FILENAME_FLAGS_*
     2820 * @param ts frame timestamp in seconds
    28202821 * @return 0 if OK, -1 on format error
    28212822 */
    28222823int 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);
    28242825
    28252826int av_get_frame_filename(char *buf, int buf_size,
    28262827                          const char *path, int number);
  • libavformat/img2enc.c

    diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
    index d793807..60ce38d 100644
    a b static int write_packet(AVFormatContext *s, AVPacket *pkt)  
    8383    AVIOContext *pb[4];
    8484    char filename[1024];
    8585    AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
     86    AVStream *stream = s->streams[ pkt->stream_index ];
     87    AVCodecContext *codec = stream->codec;
    8688    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format);
    8789    int i;
    8890    int nb_renames = 0;
     91    int64_t ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q);
    8992
    9093    if (!img->is_pipe) {
    9194        if (img->update) {
    … … static int write_packet(AVFormatContext *s, AVPacket *pkt)  
    100103                return AVERROR(EINVAL);
    101104            }
    102105        } 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 &&
    105108                   img->img_number > 1) {
    106109            av_log(s, AV_LOG_ERROR,
    107110                   "Could not get frame filename number %d from pattern '%s' (either set updatefirst or use a pattern like %%03d within the filename pattern)\n",
  • libavformat/utils.c

    diff --git a/libavformat/utils.c b/libavformat/utils.c
    index 7abca63..7dba942 100644
    a b  
    2121
    2222#include <stdarg.h>
    2323#include <stdint.h>
     24#include <ctype.h>
    2425
    2526#include "config.h"
    2627
    … … uint64_t ff_ntp_time(void)  
    45564557    return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
    45574558}
    45584559
    4559 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
     4560int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags, int64_t ts)
    45604561{
    45614562    const char *p;
    45624563    char *q, buf1[20], c;
    45634564    int nd, len, percentd_found;
     4565    int hours, mins, secs, ms;
    45644566
    45654567    q = buf;
    45664568    p = path;
    … … int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number  
    45934595                memcpy(q, buf1, len);
    45944596                q += len;
    45954597                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;
    45964619            default:
    45974620                goto fail;
    45984621            }
    45994622        } else {
    4600 addchar:
     4623        addchar:
    46014624            if ((q - buf) < buf_size - 1)
    46024625                *q++ = c;
    46034626        }
    … … fail:  
    46134636
    46144637int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
    46154638{
    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);
    46174640}
    46184641
    46194642void av_url_split(char *proto, int proto_size,