[FFmpeg-devel] [PATCH 2/2] mxfdec: set audio packets pts

Tomas Härdin tomas.hardin at codemill.se
Thu Nov 8 17:00:31 CET 2012


> From 466d6e5f641469e620a8e46b45a8e5e6e256edd1 Mon Sep 17 00:00:00 2001
> From: Matthieu Bouron <matthieu.bouron at gmail.com>
> Date: Thu, 13 Sep 2012 21:15:48 +0200
> Subject: [PATCH] mxfdec: set audio packets pts
> 
> Also fix playback of ntsc files.
> ---
>  libavformat/mxfdec.c        | 82 +++++++++++++++++++++++++++++++++++++++++++--
>  tests/ref/fate/mxf-demux    |  6 ++--
>  tests/ref/lavf/mxf          |  2 +-
>  tests/ref/seek/lavf_mxf     | 18 +++++-----
>  tests/ref/seek/lavf_mxf_d10 | 30 ++++++++---------
>  5 files changed, 107 insertions(+), 31 deletions(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index b7c0826..b3f6165 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -46,6 +46,7 @@
>  //#define DEBUG
>  
>  #include "libavutil/aes.h"
> +#include "libavutil/avassert.h"
>  #include "libavutil/mathematics.h"
>  #include "libavcodec/bytestream.h"
>  #include "libavutil/timecode.h"
> @@ -132,6 +133,8 @@ typedef struct {
>      uint8_t track_number[4];
>      AVRational edit_rate;
>      int intra_only;
> +    AVRational time_base;

Please avoid having multiple points of truth. Also see further down.

> +static int mxf_compute_sample_count(MXFContext *mxf, int stream_index, uint64_t *sample_count)
> +{
> +    int i, total = 0, size = 0;
> +    AVStream *st = mxf->fc->streams[stream_index];
> +    MXFTrack *track = st->priv_data;
> +    AVRational time_base = track->time_base;
> +    AVRational sample_rate = st->time_base;
> +    const MXFSamplesPerFrame *spf = NULL;
> +
> +    if (av_q2d(sample_rate) == 48000)
> +        spf = ff_mxf_get_samples_per_frame(mxf->fc, time_base);
> +    if (!spf) {
> +        int remainder = (sample_rate.num * time_base.den) % (time_base.num * sample_rate.den);
> +        *sample_count = mxf->current_edit_unit * (av_q2d(sample_rate) / av_q2d(time_base));

Inaccurate. Try something like:

    *sample_count = av_mul_q((AVRational){mxf->current_edit_unit,1},
                             av_mul_q(sample_rate, track->edit_rate));

since track->time_base is 1/edit_rate here.

> +static int mxf_set_audio_pts(MXFContext *mxf, AVCodecContext *codec, AVPacket *pkt)
> +{
> +    MXFTrack *track = mxf->fc->streams[pkt->stream_index]->priv_data;
> +    pkt->pts = track->sample_count;
> +    track->sample_count += pkt->size / (codec->channels * av_get_bits_per_sample(codec->codec_id) / 8);

pkt->duration gets set by lavf later, right?

Getting there :)

/Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121108/03e9fe82/attachment.asc>


More information about the ffmpeg-devel mailing list