[FFmpeg-devel] [PATCH v4 7/8] avformat: implement retiming directly in mxfenc and gxfenc

Tomas Härdin tjoppen at acc.umu.se
Mon May 4 11:13:06 EEST 2020


tis 2020-04-28 klockan 19:37 +0200 skrev Marton Balint:
> Generic retime functionality is replaced by a few lines of code directly in the
> muxers which used it, which seems a lot easier to understand and this way the
> retiming is not dependant of the input durations.
> 
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavformat/Makefile |  4 ++--
>  libavformat/gxfenc.c | 21 ++++++++++++++-------
>  libavformat/mxfenc.c | 14 +++++++++-----
>  3 files changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 56ca55fbd5..0a2edffc86 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -205,7 +205,7 @@ OBJS-$(CONFIG_GIF_DEMUXER)               += gifdec.o
>  OBJS-$(CONFIG_GSM_DEMUXER)               += gsmdec.o
>  OBJS-$(CONFIG_GSM_MUXER)                 += rawenc.o
>  OBJS-$(CONFIG_GXF_DEMUXER)               += gxf.o
> -OBJS-$(CONFIG_GXF_MUXER)                 += gxfenc.o retimeinterleave.o
> +OBJS-$(CONFIG_GXF_MUXER)                 += gxfenc.o
>  OBJS-$(CONFIG_G722_DEMUXER)              += g722.o rawdec.o
>  OBJS-$(CONFIG_G722_MUXER)                += rawenc.o
>  OBJS-$(CONFIG_G723_1_DEMUXER)            += g723_1.o
> @@ -347,7 +347,7 @@ OBJS-$(CONFIG_MUSX_DEMUXER)              += musx.o
>  OBJS-$(CONFIG_MV_DEMUXER)                += mvdec.o
>  OBJS-$(CONFIG_MVI_DEMUXER)               += mvi.o
>  OBJS-$(CONFIG_MXF_DEMUXER)               += mxfdec.o mxf.o
> -OBJS-$(CONFIG_MXF_MUXER)                 += mxfenc.o mxf.o retimeinterleave.o avc.o
> +OBJS-$(CONFIG_MXF_MUXER)                 += mxfenc.o mxf.o avc.o
>  OBJS-$(CONFIG_MXG_DEMUXER)               += mxg.o
>  OBJS-$(CONFIG_NC_DEMUXER)                += ncdec.o
>  OBJS-$(CONFIG_NISTSPHERE_DEMUXER)        += nistspheredec.o pcm.o
> diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
> index 60468c36ce..6d4df894f6 100644
> --- a/libavformat/gxfenc.c
> +++ b/libavformat/gxfenc.c
> @@ -27,7 +27,6 @@
>  #include "avformat.h"
>  #include "internal.h"
>  #include "gxf.h"
> -#include "retimeinterleave.h"
>  
>  #define GXF_SAMPLES_PER_FRAME 32768
>  #define GXF_AUDIO_PACKET_SIZE 65536
> @@ -45,7 +44,7 @@ typedef struct GXFTimecode{
>  } GXFTimecode;
>  
>  typedef struct GXFStreamContext {
> -    RetimeInterleaveContext aic;
> +    int64_t pkt_cnt;
>      uint32_t track_type;
>      uint32_t sample_size;
>      uint32_t sample_rate;
> @@ -815,7 +814,6 @@ static int gxf_write_header(AVFormatContext *s)
>                  return -1;
>              }
>          }
> -        ff_retime_interleave_init(&sc->aic, st->time_base);
>          /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
>          sc->media_info = media_info<<8 | ('0'+tracks[media_info]++);
>          sc->order = s->nb_streams - st->index;
> @@ -1012,10 +1010,19 @@ static int gxf_compare_field_nb(AVFormatContext *s, const AVPacket *next,
>  
>  static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
>  {
> -    if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
> -        pkt->duration = 2; // enforce 2 fields
> -    return ff_retime_interleave(s, out, pkt, flush,
> -                                ff_interleave_packet_per_dts, gxf_compare_field_nb);
> +    int ret;
> +    if (pkt) {
> +        AVStream *st = s->streams[pkt->stream_index];
> +        GXFStreamContext *sc = st->priv_data;
> +        if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
> +            pkt->pts = pkt->dts = sc->pkt_cnt * 2; // enforce 2 fields
> +        else
> +            pkt->pts = pkt->dts = sc->pkt_cnt * GXF_SAMPLES_PER_FRAME;
> +        sc->pkt_cnt++;
> +        if ((ret = ff_interleave_add_packet(s, pkt, gxf_compare_field_nb)) < 0)
> +            return ret;
> +    }
> +    return ff_interleave_packet_per_dts(s, out, NULL, flush);
>  }

Doesn't apply on master

/Tomas



More information about the ffmpeg-devel mailing list