[FFmpeg-devel] [PATCH] Add support for vp9 in iso-bmff

James Almer jamrial at gmail.com
Sat Jun 11 17:48:01 CEST 2016


On 6/10/2016 7:25 PM, Kongqun Yang wrote:
> Implemented according to the draft specification
> "VP Codec ISO Media File Format Binding":
> http://www.webmproject.org/vp9/#draft-vp-codec-iso-media-file-format-binding
> 
> Change-Id: Iaa7ddf5524b17e8d79cd1923b26f096deeee6e91
> ---
>  libavformat/Makefile |   2 +-
>  libavformat/isom.c   |   3 +
>  libavformat/movenc.c |  15 +++++
>  libavformat/vpx.c    | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/vpx.h    |  33 ++++++++++
>  5 files changed, 222 insertions(+), 1 deletion(-)
>  create mode 100644 libavformat/vpx.c
>  create mode 100644 libavformat/vpx.h
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 6684ead..33d6027 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -276,7 +276,7 @@ OBJS-$(CONFIG_MM_DEMUXER)                += mm.o
>  OBJS-$(CONFIG_MMF_DEMUXER)               += mmf.o
>  OBJS-$(CONFIG_MMF_MUXER)                 += mmf.o rawenc.o
>  OBJS-$(CONFIG_MOV_DEMUXER)               += mov.o mov_chan.o replaygain.o
> -OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o avc.o hevc.o \
> +OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o avc.o hevc.o vpx.o \
>                                              movenchint.o mov_chan.o rtp.o \
>                                              movenccenc.o rawutils.o
>  OBJS-$(CONFIG_MP2_MUXER)                 += mp3enc.o rawenc.o id3v2enc.o
> diff --git a/libavformat/isom.c b/libavformat/isom.c
> index b1757e2..9a65268 100644
> --- a/libavformat/isom.c
> +++ b/libavformat/isom.c
> @@ -59,6 +59,7 @@ const AVCodecTag ff_mp4_obj_type[] = {
>      { AV_CODEC_ID_AC3         , 0xA5 },
>      { AV_CODEC_ID_EAC3        , 0xA6 },
>      { AV_CODEC_ID_DTS         , 0xA9 }, /* mp4ra.org */
> +    { AV_CODEC_ID_VP9         , 0xC0 }, /* non standard, update when there is a standard value */

Muxing such files should absolutely require -strict experimental then.

[...]

> diff --git a/libavformat/vpx.c b/libavformat/vpx.c
> new file mode 100644
> index 0000000..5125187
> --- /dev/null
> +++ b/libavformat/vpx.c
> @@ -0,0 +1,170 @@
> +/*
> + * VPX helper functions for muxers
> + *
> + * Copyright (c) 2016 Google Inc.
> + * Copyright (c) 2016 KongQun Yang (kqyang at google.com)
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "vpx.h"
> +#include "libavutil/pixfmt.h"
> +
> +enum VpxColorSpace
> +{
> +    VPX_COLOR_SPACE_UNSPECIFIED = 0,
> +    VPX_COLOR_SPACE_BT601 = 1,
> +    VPX_COLOR_SPACE_BT709 = 2,
> +    VPX_COLOR_SPACE_SMPTE_170 = 3,
> +    VPX_COLOR_SPACE_SMPTE_240 = 4,
> +    VPX_COLOR_SPACE_BT2020_NCL = 5,
> +    VPX_COLOR_SPACE_BT2020_CL = 6,
> +    VPX_COLOR_SPACE_RGB = 7,
> +};
> +
> +static int get_vpx_color_space(enum AVColorSpace color_space)
> +{
> +    switch (color_space) {
> +        case AVCOL_SPC_RGB:
> +            return VPX_COLOR_SPACE_RGB;
> +        case AVCOL_SPC_BT709:
> +            return VPX_COLOR_SPACE_BT709;
> +        case AVCOL_SPC_SMPTE170M:
> +            return VPX_COLOR_SPACE_SMPTE_170;
> +        case AVCOL_SPC_SMPTE240M:
> +            return VPX_COLOR_SPACE_SMPTE_240;
> +        case AVCOL_SPC_BT2020_NCL:
> +            return VPX_COLOR_SPACE_BT2020_NCL;
> +        case AVCOL_SPC_BT2020_CL:
> +            return VPX_COLOR_SPACE_BT2020_CL;
> +        default:
> +            return VPX_COLOR_SPACE_UNSPECIFIED;
> +    }
> +}

Isn't the above duplicating code or structs from libavcodec? (either the
native vp9 decoder or the libvpx wrapper). If so, maybe it could be shared.

Same probably also goes for most of the stuff below.

> +
> +enum VPX_CHROMA_SUBSAMPLING
> +{
> +    VPX_SUBSAMPLING_420_VERTICAL = 0,
> +    VPX_SUBSAMPLING_420_COLLOCATED_WITH_LUMA = 1,
> +    VPX_SUBSAMPLING_422 = 2,
> +    VPX_SUBSAMPLING_444 = 3,
> +};
> +
> +static int get_vpx_chroma_subsampling(enum AVPixelFormat pixel_format,
> +                                      enum AVChromaLocation chroma_location)
> +{
> +    switch (pixel_format) {
> +        case AV_PIX_FMT_YUV420P:
> +        case AV_PIX_FMT_YUV420P10LE:
> +        case AV_PIX_FMT_YUV420P10BE:
> +        case AV_PIX_FMT_YUV420P12LE:
> +        case AV_PIX_FMT_YUV420P12BE:
> +            if (chroma_location == AVCHROMA_LOC_LEFT)
> +                return VPX_SUBSAMPLING_420_VERTICAL;
> +            // Otherwise assume collocated.
> +            return VPX_SUBSAMPLING_420_COLLOCATED_WITH_LUMA;
> +        case AV_PIX_FMT_YUV422P:
> +        case AV_PIX_FMT_YUV422P10LE:
> +        case AV_PIX_FMT_YUV422P10BE:
> +        case AV_PIX_FMT_YUV422P12LE:
> +        case AV_PIX_FMT_YUV422P12BE:
> +            return VPX_SUBSAMPLING_422;
> +        case AV_PIX_FMT_YUV444P:
> +        case AV_PIX_FMT_YUV444P10LE:
> +        case AV_PIX_FMT_YUV444P10BE:
> +        case AV_PIX_FMT_YUV444P12LE:
> +        case AV_PIX_FMT_YUV444P12BE:
> +            return VPX_SUBSAMPLING_444;
> +        default:
> +            av_log(NULL, AV_LOG_WARNING,
> +                   "Unspecified or unrecognized pix format. Assuming 4:2:0 "
> +                   "vertical.");
> +            return VPX_SUBSAMPLING_420_VERTICAL;
> +    }
> +}
> +
> +static int get_bit_depth(enum AVPixelFormat pixel_format)
> +{
> +  switch (pixel_format) {
> +      case AV_PIX_FMT_YUV420P:
> +      case AV_PIX_FMT_YUV422P:
> +      case AV_PIX_FMT_YUV444P:
> +          return 8;
> +      case AV_PIX_FMT_YUV420P10LE:
> +      case AV_PIX_FMT_YUV420P10BE:
> +      case AV_PIX_FMT_YUV422P10LE:
> +      case AV_PIX_FMT_YUV422P10BE:
> +      case AV_PIX_FMT_YUV444P10LE:
> +      case AV_PIX_FMT_YUV444P10BE:
> +          return 10;
> +      case AV_PIX_FMT_YUV420P12LE:
> +      case AV_PIX_FMT_YUV420P12BE:
> +      case AV_PIX_FMT_YUV422P12LE:
> +      case AV_PIX_FMT_YUV422P12BE:
> +      case AV_PIX_FMT_YUV444P12LE:
> +      case AV_PIX_FMT_YUV444P12BE:
> +          return 12;
> +      default:
> +          // Defaults to 8.
> +          av_log(NULL, AV_LOG_WARNING,
> +                 "Unspecified or unrecognized bit depth. Assuming 8.");
> +          return 8;
> +  }
> +}

I'm fairly sure this is duplicating libavutil functionality. A function
returning bit depth based on a AVPixelFormat argument sounds generic
enough that plenty modules would use.



More information about the ffmpeg-devel mailing list