[FFmpeg-devel] [PATCH v5 4/4] avformat: add kvag muxer

Michael Niedermayer michael at niedermayer.cc
Fri May 29 02:15:09 EEST 2020


On Sat, May 16, 2020 at 11:53:51AM +0000, Zane van Iperen wrote:
> Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
> ---
>  Changelog                |  1 +
>  libavformat/Makefile     |  1 +
>  libavformat/allformats.c |  1 +
>  libavformat/kvag.c       | 84 +++++++++++++++++++++++++++++++++++++++-
>  libavformat/version.h    |  2 +-
>  5 files changed, 87 insertions(+), 2 deletions(-)
> 
> diff --git a/Changelog b/Changelog
> index 1f2cf7692d..6aacf6e819 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -68,6 +68,7 @@ version <next>:
>  - pcm_rechunk bitstream filter
>  - scdet filter
>  - Simon & Schuster Interactive ADPCM encoder
> +- Real War KVAG muxer
>  
>  
>  version 4.2:
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 5fa24cef16..c342c7f245 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -285,6 +285,7 @@ OBJS-$(CONFIG_JACOSUB_MUXER)             += jacosubenc.o rawenc.o
>  OBJS-$(CONFIG_JV_DEMUXER)                += jvdec.o
>  OBJS-$(CONFIG_KUX_DEMUXER)               += flvdec.o
>  OBJS-$(CONFIG_KVAG_DEMUXER)              += kvag.o
> +OBJS-$(CONFIG_KVAG_MUXER)                += kvag.o rawenc.o
>  OBJS-$(CONFIG_LATM_MUXER)                += latmenc.o rawenc.o
>  OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
>  OBJS-$(CONFIG_LOAS_DEMUXER)              += loasdec.o rawdec.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 3919c9e4c1..a7c5c9db89 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -220,6 +220,7 @@ extern AVOutputFormat ff_jacosub_muxer;
>  extern AVInputFormat  ff_jv_demuxer;
>  extern AVInputFormat  ff_kux_demuxer;
>  extern AVInputFormat  ff_kvag_demuxer;
> +extern AVOutputFormat ff_kvag_muxer;
>  extern AVOutputFormat ff_latm_muxer;
>  extern AVInputFormat  ff_lmlm4_demuxer;
>  extern AVInputFormat  ff_loas_demuxer;
> diff --git a/libavformat/kvag.c b/libavformat/kvag.c
> index 71b0eb4118..8be820a3c8 100644
> --- a/libavformat/kvag.c
> +++ b/libavformat/kvag.c
> @@ -1,5 +1,5 @@
>  /*
> - * Simon & Schuster Interactive VAG demuxer
> + * Simon & Schuster Interactive VAG (de)muxer
>   *
>   * Copyright (C) 2020 Zane van Iperen (zane at zanevaniperen.com)
>   *
> @@ -21,6 +21,7 @@
>   */
>  #include "avformat.h"
>  #include "internal.h"
> +#include "rawenc.h"
>  #include "libavutil/intreadwrite.h"
>  
>  #define KVAG_TAG            MKTAG('K', 'V', 'A', 'G')
> @@ -34,6 +35,7 @@ typedef struct KVAGHeader {
>      uint16_t    stereo;
>  } KVAGHeader;
>  
> +#if CONFIG_KVAG_DEMUXER
>  static int kvag_probe(const AVProbeData *p)
>  {
>      if (AV_RL32(p->buf) != KVAG_TAG)
> @@ -115,3 +117,83 @@ AVInputFormat ff_kvag_demuxer = {
>      .read_header    = kvag_read_header,
>      .read_packet    = kvag_read_packet
>  };
> +#endif
> +
> +#if CONFIG_KVAG_MUXER
> +static int kvag_write_init(AVFormatContext *s)
> +{
> +    AVCodecParameters *par;
> +
> +    if (s->nb_streams != 1) {
> +        av_log(s, AV_LOG_ERROR, "KVAG files have exactly one stream\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    par = s->streams[0]->codecpar;
> +
> +    if (par->codec_id != AV_CODEC_ID_ADPCM_IMA_SSI) {
> +        av_log(s, AV_LOG_ERROR, "%s codec not supported\n",
> +               avcodec_get_name(par->codec_id));
> +        return AVERROR(EINVAL);
> +    }
> +
> +    if (par->channels > 2) {
> +        av_log(s, AV_LOG_ERROR, "KVAG files only support up to 2 channels\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    return 0;
> +}
> +
> +static int kvag_write_header(AVFormatContext *s)
> +{
> +    uint8_t buf[KVAG_HEADER_SIZE];
> +    AVCodecParameters *par = s->streams[0]->codecpar;
> +
> +    AV_WL32(buf +  0, KVAG_TAG);
> +    AV_WL32(buf +  4, 0); /* Data size, we fix this up later. */
> +    AV_WL32(buf +  8, par->sample_rate);
> +    AV_WL16(buf + 12, par->channels == 2);
> +
> +    avio_write(s->pb, buf, sizeof(buf));
> +    return 0;
> +}
> +

> +static int kvag_write_trailer(AVFormatContext *s)
> +{
> +    int64_t file_size, data_size;
> +
> +    if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
> +        av_log(s, AV_LOG_WARNING,
> +               "Stream not seekable, unable to write data size. "
> +               "Output file will be broken\n");
> +        return 0;
> +    }

this could be checked earlier, checking it earlier would avoid transcoding the
whole file just to fail
or is such a broken file usefull in some usecase ?

thx

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

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200529/fdf35cc2/attachment.sig>


More information about the ffmpeg-devel mailing list