FFmpeg  4.0
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 {
32 };
33 
35  enum AVPixelFormat pixel_format,
36  enum AVChromaLocation chroma_location)
37 {
38  int chroma_w, chroma_h;
39  if (av_pix_fmt_get_chroma_sub_sample(pixel_format, &chroma_w, &chroma_h) == 0) {
40  if (chroma_w == 1 && chroma_h == 1) {
41  return (chroma_location == AVCHROMA_LOC_LEFT)
44  } else if (chroma_w == 1 && chroma_h == 0) {
45  return VPX_SUBSAMPLING_422;
46  } else if (chroma_w == 0 && chroma_h == 0) {
47  return VPX_SUBSAMPLING_444;
48  }
49  }
50  av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n", pixel_format);
51  return -1;
52 }
53 
54 static int get_bit_depth(AVFormatContext *s, enum AVPixelFormat pixel_format)
55 {
56  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pixel_format);
57  if (desc == NULL) {
58  av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n",
59  pixel_format);
60  return -1;
61  }
62  return desc->comp[0].depth;
63 }
64 
66 {
67  return color_range == AVCOL_RANGE_JPEG;
68 }
69 
71  AVCodecParameters *par)
72 {
73  int profile = par->profile;
74  int level = par->level == FF_LEVEL_UNKNOWN ? 0 : par->level;
75  int bit_depth = get_bit_depth(s, par->format);
76  int vpx_chroma_subsampling =
78  int vpx_video_full_range_flag =
80 
81  if (bit_depth < 0 || vpx_chroma_subsampling < 0)
82  return AVERROR_INVALIDDATA;
83 
84  if (profile == FF_PROFILE_UNKNOWN) {
85  if (vpx_chroma_subsampling == VPX_SUBSAMPLING_420_VERTICAL ||
86  vpx_chroma_subsampling == VPX_SUBSAMPLING_420_COLLOCATED_WITH_LUMA) {
87  profile = (bit_depth == 8) ? FF_PROFILE_VP9_0 : FF_PROFILE_VP9_2;
88  } else {
89  profile = (bit_depth == 8) ? FF_PROFILE_VP9_1 : FF_PROFILE_VP9_3;
90  }
91  }
92 
93  avio_w8(pb, profile);
94  avio_w8(pb, level);
95  avio_w8(pb, (bit_depth << 4) | (vpx_chroma_subsampling << 1) | vpx_video_full_range_flag);
96  avio_w8(pb, par->color_primaries);
97  avio_w8(pb, par->color_trc);
98  avio_w8(pb, par->color_space);
99 
100  // vp9 does not have codec initialization data.
101  avio_wb16(pb, 0);
102  return 0;
103 }
enum AVChromaLocation chroma_location
Definition: avcodec.h:3974
static int get_bit_depth(AVFormatContext *s, enum AVPixelFormat pixel_format)
Definition: vpcc.c:54
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:161
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:3972
#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:2363
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:520
const char * desc
Definition: nvenc.c:65
VPX_CHROMA_SUBSAMPLING
Definition: vpcc.c:26
color_range
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3876
enum AVColorSpace color_space
Definition: avcodec.h:3973
Format I/O context.
Definition: avformat.h:1342
#define FF_PROFILE_VP9_0
Definition: avcodec.h:2926
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:2954
static int get_vpx_chroma_subsampling(AVFormatContext *s, enum AVPixelFormat pixel_format, enum AVChromaLocation chroma_location)
Definition: vpcc.c:34
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par)
Writes VP codec configuration to the provided AVIOContext.
Definition: vpcc.c:70
static int get_vpx_video_full_range_flag(enum AVColorRange color_range)
Definition: vpcc.c:65
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:496
#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:2929
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:2391
enum AVColorPrimaries color_primaries
Definition: avcodec.h:3971
#define FF_PROFILE_VP9_2
Definition: avcodec.h:2928
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2844
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:152
enum AVColorRange color_range
Video only.
Definition: avcodec.h:3970
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:499
#define FF_PROFILE_VP9_1
Definition: avcodec.h:2927
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:196
mfxU16 profile
Definition: qsvenc.c:44
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:475
uint8_t level
Definition: svq3.c:207
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:3944
pixel format definitions
internal header for VPx codec configuration utilities.
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:518
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60