[FFmpeg-devel] [PATCH] examples/muxing: set timestamps in output audio packet

Michael Niedermayer michaelni at gmx.at
Thu Jan 9 02:32:11 CET 2014


On Thu, Jan 09, 2014 at 01:08:57AM +0100, Stefano Sabatini wrote:
> On date Thursday 2014-01-09 00:41:45 +0100, Michael Niedermayer encoded:
> > On Wed, Jan 08, 2014 at 03:45:21PM +0100, Stefano Sabatini wrote:
> > > In particular, fix trac ticket #3231.
> > > ---
> > >  doc/examples/muxing.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > > 
> > > diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
> > > index 33b2989..cf3e336 100644
> > > --- a/doc/examples/muxing.c
> > > +++ b/doc/examples/muxing.c
> > > @@ -270,6 +270,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
> > >      }
> > >  
> > >      audio_frame->nb_samples = dst_nb_samples;
> > > +    audio_frame->pts += av_rescale_q(dst_nb_samples, (AVRational){1, c->sample_rate}, c->time_base);
> > >      avcodec_fill_audio_frame(audio_frame, c->channels, c->sample_fmt,
> > >                               dst_samples_data[0], dst_samples_size, 0);
> > >  
> > > @@ -280,6 +281,13 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
> > >      }
> > >  
> > >      pkt.stream_index = st->index;
> > 
> > > +    /* rescale output packet timestamp values */
> > > +    if (pkt.pts != AV_NOPTS_VALUE)
> > > +        pkt.pts = av_rescale_q(pkt.pts, c->time_base, st->time_base);
> > > +    if (pkt.dts != AV_NOPTS_VALUE)
> > > +        pkt.dts = av_rescale_q(pkt.dts, c->time_base, st->time_base);
> > 
> > see AV_ROUND_PASS_MINMAX
> > 
> > > +    if (pkt.duration)
> > > +        pkt.duration = av_rescale_q(pkt.duration, c->time_base, st->time_base);
> > 
> > the if seems unneeded
> 
> Up.
> -- 
> FFmpeg = Forgiving & Fabulous Mean Programmable Ecumenical God

>  muxing.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> f8cc5d38d1a9d47b7b7430cb11b638df31969f79  0006-examples-muxing-set-timestamps-in-output-audio-packe.patch
> From 868ea504f582d0c387d5d0664f43de78f2e8482c Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Wed, 8 Jan 2014 15:43:25 +0100
> Subject: [PATCH] examples/muxing: set timestamps in output audio packet
> 
> In particular, fix trac ticket #3231.
> ---
>  doc/examples/muxing.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
> index 8edef00..14913d0 100644
> --- a/doc/examples/muxing.c
> +++ b/doc/examples/muxing.c
> @@ -148,6 +148,7 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
>          fprintf(stderr, "Could not allocate audio frame\n");
>          exit(1);
>      }
> +    audio_frame->pts = 0;
>  
>      /* open it */
>      ret = avcodec_open2(c, codec, NULL);
> @@ -269,6 +270,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
>      }
>  
>      audio_frame->nb_samples = dst_nb_samples;
> +    audio_frame->pts += av_rescale_q(dst_nb_samples, (AVRational){1, c->sample_rate}, c->time_base);

this looks like it would accumulate rounding errors (especially bad as
this is a example other might base their code on)
otherwise it should be ok

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140109/2d520c26/attachment.asc>


More information about the ffmpeg-devel mailing list