[FFmpeg-devel] [PATCH] ffmpeg.c: copy chapters by default.
Michael Niedermayer
michaelni
Thu Mar 18 16:34:21 CET 2010
On Thu, Mar 18, 2010 at 01:13:41PM +0100, Anton Khirnov wrote:
> On Thu, Mar 18, 2010 at 12:36:59PM +0100, Michael Niedermayer wrote:
> > On Thu, Mar 18, 2010 at 09:40:38AM +0100, Anton Khirnov wrote:
> > > Chapters are copied from the first input file that has them to all
> > > output files.
> > > ---
> > > ffmpeg.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > 1 files changed, 57 insertions(+), 0 deletions(-)
> >
> > putting this into a seperate function likely makes the code overall
> > more readable
> done
>
> Anton Khirnov
> ffmpeg.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
> 2711fb769c70d8e5ec9fab106f64cff339aec99b 0001-ffmpeg.c-copy-chapters-by-default.patch
> From b103b29605c4de7e3244daec0fc74c30508c1b75 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/ffmpeg.c b/ffmpeg.c
> index d0af510..3ee66fd 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -1646,6 +1646,56 @@ 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, *out_ch;
> + AVMetadataTag *t = NULL;
> +
> + in_ch = is->chapters[i];
> + if (av_compare_ts(in_ch->end, in_ch->time_base, start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q) < 0)
> + continue;
> + if (recording_time != INT64_MAX &&
> + av_compare_ts(in_ch->start, in_ch->time_base, recording_time + start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q) > 0)
> + 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;
> + if (av_compare_ts(in_ch->start, in_ch->time_base, start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q) < 0)
> + out_ch->start = 0;
> + else
> + out_ch->start = in_ch->start - av_rescale_q(start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q, out_ch->time_base);
> + if (recording_time != INT64_MAX &&
> + av_compare_ts(in_ch->end, in_ch->time_base, recording_time + start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q) > 0)
> + out_ch->end = av_rescale_q(recording_time, AV_TIME_BASE_Q, out_ch->time_base);
> + else
> + out_ch->end = in_ch->end - av_rescale_q(start_time - input_files_ts_offset[infile],
> + AV_TIME_BASE_Q, out_ch->time_base);
maybe these could be simplified with FFMIN/FFMAX
except that feel free to commit if tested
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- 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/20100318/d4b2ed69/attachment.pgp>
More information about the ffmpeg-devel
mailing list