FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vpcc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Google Inc.
3  * Copyright (c) 2016 KongQun Yang (kqyang@google.com)
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/pixdesc.h"
23 #include "libavutil/pixfmt.h"
24 #include "vpcc.h"
25 
27 {
36 };
37 
39  enum AVColorSpace color_space)
40 {
41  switch (color_space) {
42  case AVCOL_SPC_RGB:
43  return VPX_COLOR_SPACE_RGB;
44  case AVCOL_SPC_BT709:
45  return VPX_COLOR_SPACE_BT709;
48  case AVCOL_SPC_BT470BG:
49  return VPX_COLOR_SPACE_BT601;
58  default:
59  av_log(s, AV_LOG_ERROR, "Unsupported color space (%d)\n", color_space);
60  return -1;
61  }
62 }
63 
65 {
70 };
71 
73  enum AVPixelFormat pixel_format,
74  enum AVChromaLocation chroma_location)
75 {
76  int chroma_w, chroma_h;
77  if (av_pix_fmt_get_chroma_sub_sample(pixel_format, &chroma_w, &chroma_h) == 0) {
78  if (chroma_w == 1 && chroma_h == 1) {
79  return (chroma_location == AVCHROMA_LOC_LEFT)
82  } else if (chroma_w == 1 && chroma_h == 0) {
83  return VPX_SUBSAMPLING_422;
84  } else if (chroma_w == 0 && chroma_h == 0) {
85  return VPX_SUBSAMPLING_444;
86  }
87  }
88  av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n", pixel_format);
89  return -1;
90 }
91 
92 static int get_bit_depth(AVFormatContext *s, enum AVPixelFormat pixel_format)
93 {
94  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pixel_format);
95  if (desc == NULL) {
96  av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n",
97  pixel_format);
98  return -1;
99  }
100  return desc->comp[0].depth;
101 }
102 
104  enum AVColorTransferCharacteristic transfer)
105 {
106  return transfer == AVCOL_TRC_SMPTEST2084;
107 }
108 
110 {
111  return color_range == AVCOL_RANGE_JPEG;
112 }
113 
115  AVCodecParameters *par)
116 {
117  int profile = par->profile;
118  int level = par->level == FF_LEVEL_UNKNOWN ? 0 : par->level;
119  int bit_depth = get_bit_depth(s, par->format);
120  int vpx_color_space = get_vpx_color_space(s, par->color_space);
121  int vpx_chroma_subsampling =
123  int vpx_transfer_function = get_vpx_transfer_function(par->color_trc);
124  int vpx_video_full_range_flag =
126 
127  if (bit_depth < 0 || vpx_color_space < 0 || vpx_chroma_subsampling < 0)
128  return AVERROR_INVALIDDATA;
129 
130  if (profile == FF_PROFILE_UNKNOWN) {
131  if (vpx_chroma_subsampling == VPX_SUBSAMPLING_420_VERTICAL ||
132  vpx_chroma_subsampling == VPX_SUBSAMPLING_420_COLLOCATED_WITH_LUMA) {
133  profile = (bit_depth == 8) ? FF_PROFILE_VP9_0 : FF_PROFILE_VP9_2;
134  } else {
135  profile = (bit_depth == 8) ? FF_PROFILE_VP9_1 : FF_PROFILE_VP9_3;
136  }
137  }
138 
139  avio_w8(pb, profile);
140  avio_w8(pb, level);
141  avio_w8(pb, (bit_depth << 4) | vpx_color_space);
142  avio_w8(pb, (vpx_chroma_subsampling << 4) | (vpx_transfer_function << 1) |
143  vpx_video_full_range_flag);
144 
145  // vp9 does not have codec initialization data.
146  avio_wb16(pb, 0);
147  return 0;
148 }
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:438
enum AVChromaLocation chroma_location
Definition: avcodec.h:4070
static int get_bit_depth(AVFormatContext *s, enum AVPixelFormat pixel_format)
Definition: vpcc.c:92
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:147
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:4068
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2266
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:481
static int get_vpx_transfer_function(enum AVColorTransferCharacteristic transfer)
Definition: vpcc.c:103
const char * desc
Definition: nvenc.c:101
VpxColorSpace
Definition: vpcc.c:26
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:442
VPX_CHROMA_SUBSAMPLING
Definition: vpcc.c:64
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:443
static int get_vpx_color_space(AVFormatContext *s, enum AVColorSpace color_space)
Definition: vpcc.c:38
color_range
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:437
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3972
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:410
functionally identical to above
Definition: pixfmt.h:444
enum AVColorSpace color_space
Definition: avcodec.h:4069
Format I/O context.
Definition: avformat.h:1338
#define FF_PROFILE_VP9_0
Definition: avcodec.h:3264
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:3280
static int get_vpx_chroma_subsampling(AVFormatContext *s, enum AVPixelFormat pixel_format, enum AVChromaLocation chroma_location)
Definition: vpcc.c:72
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:436
int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par)
Writes VP codec configuration to the provided AVIOContext.
Definition: vpcc.c:114
static int get_vpx_video_full_range_flag(enum AVColorRange color_range)
Definition: vpcc.c:109
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:457
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define FF_PROFILE_VP9_3
Definition: avcodec.h:3267
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2294
#define FF_PROFILE_VP9_2
Definition: avcodec.h:3266
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:3182
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:150
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:446
enum AVColorRange color_range
Video only.
Definition: avcodec.h:4066
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:460
#define FF_PROFILE_VP9_1
Definition: avcodec.h:3265
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:182
mfxU16 profile
Definition: qsvenc.c:42
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:452
uint8_t level
Definition: svq3.c:207
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:447
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:427
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:4040
pixel format definitions
internal header for VPx codec configuration utilities.
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:479
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60