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

File 0001-Added-the-option-to-extract-images-with-timecode-as-v2.patch, 5.1 KB (added by Alex, 5 years ago)
  • doc/muxers.texi

    diff --git a/doc/muxers.texi b/doc/muxers.texi
    index e77055e7ef..91997bd4fa 100644
    a b If the pattern contains "%d" or "%0@var{N}d", the first filename of  
    13841384the file list specified will contain the number 1, all the following
    13851385numbers will be sequential.
    13861386
     1387The pattern can also contain "%t" which writes out the timestamp of the
     1388frame in the format "HH.mm.ss.fff"
     1389
    13871390The pattern may contain a suffix which is used to automatically
    13881391determine the format of the image files to write.
    13891392
  • libavformat/avformat.h

    diff --git a/libavformat/avformat.h b/libavformat/avformat.h
    index cd7b0d941c..513de9e477 100644
    a b void av_dump_format(AVFormatContext *ic,  
    26022602 * @param path numbered sequence string
    26032603 * @param number frame number
    26042604 * @param flags AV_FRAME_FILENAME_FLAGS_*
     2605 * @param ts frame timestamp in seconds
    26052606 * @return 0 if OK, -1 on format error
    26062607 */
    26072608int av_get_frame_filename2(char *buf, int buf_size,
    2608                           const char *path, int number, int flags);
     2609                          const char *path, int number, int flags, int64_t ts);
    26092610
    26102611int av_get_frame_filename(char *buf, int buf_size,
    26112612                          const char *path, int number);
  • libavformat/img2enc.c

    diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
    index 7b5133d300..55dca272ea 100644
    a b static int write_packet(AVFormatContext *s, AVPacket *pkt)  
    131131    AVIOContext *pb[4] = {0};
    132132    char filename[1024];
    133133    AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
     134    AVStream *stream = s->streams[ pkt->stream_index ];
    134135    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format);
    135136    int ret, i;
    136137    int nb_renames = 0;
     138    int64_t ts = av_rescale_q(pkt->pts, stream->time_base, AV_TIME_BASE_Q);
    137139    AVDictionary *options = NULL;
    138140
    139141    if (img->update) {
    static int write_packet(AVFormatContext *s, AVPacket *pkt)  
    148150            return AVERROR(EINVAL);
    149151        }
    150152    } else if (img->frame_pts) {
    151         if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
     153        if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE, 0) < 0) {
    152154            av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames.");
    153155            return AVERROR(EINVAL);
    154156        }
    155157    } else if (av_get_frame_filename2(filename, sizeof(filename), img->path,
    156                                       img->img_number,
    157                                       AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
     158                                      img->img_number, 0,
     159                                      ts) < 0 &&
    158160               img->img_number > 1) {
    159161        av_log(s, AV_LOG_ERROR,
    160162               "Could not get frame filename number %d from pattern '%s'. "
  • libavformat/utils.c

    diff --git a/libavformat/utils.c b/libavformat/utils.c
    index 0df14682a4..d2e7cb7d34 100644
    a b uint64_t ff_parse_ntp_time(uint64_t ntp_ts)  
    45894589    return (sec * 1000000) + usec;
    45904590}
    45914591
    4592 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
     4592int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags, int64_t ts)
    45934593{
    45944594    const char *p;
    45954595    char *q, buf1[20], c;
    4596     int nd, len, percentd_found;
     4596    int nd, len, percentd_found, percentt_found;
     4597    int hours, mins, secs, ms;
    45974598
    45984599    q = buf;
    45994600    p = path;
    46004601    percentd_found = 0;
     4602    percentt_found = 0;
    46014603    for (;;) {
    46024604        c = *p++;
    46034605        if (c == '\0')
    int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number  
    46294631                memcpy(q, buf1, len);
    46304632                q += len;
    46314633                break;
     4634            case 't':
     4635                if (percentd_found)
     4636                  goto fail;
     4637                if (ts < 0)
     4638                  goto fail;
     4639                percentt_found = 1;
     4640                ms = (ts/1000)%1000;
     4641                ts /= AV_TIME_BASE;
     4642                secs = ts % 60;
     4643                ts /= 60;
     4644                mins = ts % 60;
     4645                ts /= 60;
     4646                hours = ts;
     4647                snprintf(buf1, sizeof(buf1),
     4648                       "%02d.%02d.%02d.%03d", hours, mins, secs, ms);
     4649                len = strlen(buf1);
     4650                if ((q - buf + len) > buf_size - 1)
     4651                  goto fail;
     4652                memcpy(q, buf1, len);
     4653                q += len;
     4654                break;
    46324655            default:
    46334656                goto fail;
    46344657            }
    addchar:  
    46384661                *q++ = c;
    46394662        }
    46404663    }
    4641     if (!percentd_found)
     4664    if (!(percentd_found || percentt_found))
    46424665        goto fail;
    46434666    *q = '\0';
    46444667    return 0;
    fail:  
    46494672
    46504673int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
    46514674{
    4652     return av_get_frame_filename2(buf, buf_size, path, number, 0);
     4675    return av_get_frame_filename2(buf, buf_size, path, number, 0, 0);
    46534676}
    46544677
    46554678void av_url_split(char *proto, int proto_size,