[FFmpeg-devel] [PATCH] ffmpeg.c: copy chapters by default.

Michael Niedermayer michaelni
Sun Mar 21 16:38:22 CET 2010


On Sat, Mar 20, 2010 at 08:36:18AM +0100, Anton Khirnov wrote:
> On Fri, Mar 19, 2010 at 09:38:18AM +0100, Michael Niedermayer wrote:
> > On Thu, Mar 18, 2010 at 10:18:11PM +0100, Michael Niedermayer wrote:
> > > On Thu, Mar 18, 2010 at 08:15:48PM +0100, Anton Khirnov wrote:
> > > > On Thu, Mar 18, 2010 at 04:34:21PM +0100, Michael Niedermayer wrote:
> > > > > On Thu, Mar 18, 2010 at 01:13:41PM +0100, Anton Khirnov wrote:
> > > > > maybe these could be simplified with FFMIN/FFMAX
> > > > indeed, done.
> > > > 
> > > > Anton Khirnov
> > > 
> > > >  ffmpeg.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  1 file changed, 51 insertions(+)
> > > > baca1878fb209f8c401f6c6b047e78d75c3c33d4  0001-ffmpeg.c-copy-chapters-by-default.patch
> > > > From c538b582f2478e0c21a577901f30e011a55f13a0 Mon Sep 17 00:00:00 2001
> > > > From: Anton Khirnov <wyskas at gmail.com>
> > > > Date: Wed, 24 Feb 2010 23:00:31 +0100
> > > > Subject: [PATCH] ffmpeg.c: copy chapters by default.
> > > > 
> > > > Chapters are copied from the first input file that has them to all
> > > > output files.
> > > > ---
> > > >  ffmpeg.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  1 files changed, 51 insertions(+), 0 deletions(-)
> > > 
> > > okif tested
> > 
> > also maybe you want to move this function into lavf
> something like this?
> btw isn't av_rescale_q supposed to handle overflows?
> av_rescale_q(INT64_MAX, {1,1E6}, {1,1E9}) returns -1000.

how should it handle overflows?
its kinda hard to return a value if its not representable


> 
> >(new c file)
> why a new file? utils.c seems like a perfect place for it.

well i dont care


> 
> Anton Khirnov

>  doc/APIchanges         |    3 +++
>  ffmpeg.c               |   44 ++------------------------------------------
>  libavformat/avformat.h |   14 +++++++++++++-
>  libavformat/utils.c    |   39 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 57 insertions(+), 43 deletions(-)
> 32cf8140556624173a414adaa19e0da044f31eaa  0001-Add-av_copy_chapters-function.patch
> From fe67a229b66372ad4d22beb40a364a2c8618feea Mon Sep 17 00:00:00 2001
> From: Anton Khirnov <wyskas at gmail.com>
> Date: Fri, 19 Mar 2010 20:45:35 +0100
> Subject: [PATCH] Add av_copy_chapters() function.
> 
> ---
>  doc/APIchanges         |    3 +++
>  ffmpeg.c               |   44 ++------------------------------------------
>  libavformat/avformat.h |   14 +++++++++++++-
>  libavformat/utils.c    |   39 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 57 insertions(+), 43 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index a7936c5..ad43bfa 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -12,6 +12,9 @@ libavutil:   2009-03-08
>  
>  API changes, most recent first:
>  
> +2010-03-19 - r22599 - lavf 52.56.0 - av_copy_chapters()
> +  Add av_copy_chapters().
> +
>  2010-03-15 - r22540 - lavf 52.56.0 - AVFormatContext.start_time_realtime
>    Add AVFormatContext.start_time_realtime field.
>  
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 19d3c44..952d46a 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -1641,47 +1641,6 @@ static void print_sdp(AVFormatContext **avc, int n)
>      fflush(stdout);
>  }
>  
> -static int copy_chapters(int infile, int outfile)
> -{
> -    AVFormatContext *is = input_files[infile];
> -    AVFormatContext *os = output_files[outfile];
> -    int i;
> -
> -    for (i = 0; i < is->nb_chapters; i++) {
> -        AVChapter *in_ch = is->chapters[i], *out_ch;
> -        AVMetadataTag *t = NULL;
> -        int64_t ts_off   = av_rescale_q(start_time - input_files_ts_offset[infile],
> -                                      AV_TIME_BASE_Q, in_ch->time_base);
> -        int64_t rt       = (recording_time == INT64_MAX) ? INT64_MAX :
> -                           av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base);
> -
> -
> -        if (in_ch->end < ts_off)
> -            continue;
> -        if (rt != INT64_MAX && in_ch->start > rt + ts_off)
> -            break;
> -
> -        out_ch = av_mallocz(sizeof(AVChapter));
> -        if (!out_ch)
> -            return AVERROR(ENOMEM);
> -
> -        out_ch->id        = in_ch->id;
> -        out_ch->time_base = in_ch->time_base;
> -        out_ch->start     = FFMAX(0,  in_ch->start - ts_off);
> -        out_ch->end       = FFMIN(rt, in_ch->end   - ts_off);
> -
> -        while ((t = av_metadata_get(in_ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
> -            av_metadata_set2(&out_ch->metadata, t->key, t->value, 0);
> -
> -        os->nb_chapters++;
> -        os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
> -        if (!os->chapters)
> -            return AVERROR(ENOMEM);
> -        os->chapters[os->nb_chapters - 1] = out_ch;
> -    }
> -    return 0;
> -}
> -
>  /*
>   * The following code is the main loop of the file converter
>   */
> @@ -2196,7 +2155,8 @@ static int av_encode(AVFormatContext **output_files,
>              continue;
>  
>          for (j = 0; j < nb_output_files; j++)
> -            if ((ret = copy_chapters(i, j)) < 0)
> +            if ((ret = av_copy_chapters(input_files[i], output_files[j], 0, recording_time,
> +                                        input_files_ts_offset[i] - start_time)) < 0)
>                  goto dump_format;
>      }
>  
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 0c0ce46..7fef6b9 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -22,7 +22,7 @@
>  #define AVFORMAT_AVFORMAT_H
>  
>  #define LIBAVFORMAT_VERSION_MAJOR 52
> -#define LIBAVFORMAT_VERSION_MINOR 56
> +#define LIBAVFORMAT_VERSION_MINOR 57
>  #define LIBAVFORMAT_VERSION_MICRO  0
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

> @@ -1324,6 +1324,18 @@ int av_filename_number_test(const char *filename);
>   */
>  int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
>  
> +/**
> + * Copy chapters between two streams. All timestamps must be in AV_TIME_BASE.

so no accurate timestamps, seems less than ideal

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100321/00c0ee11/attachment.pgp>



More information about the ffmpeg-devel mailing list