FFmpeg
vp9_metadata.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/log.h"
20 #include "libavutil/opt.h"
21 
22 #include "bsf.h"
23 #include "bsf_internal.h"
24 #include "cbs.h"
25 #include "cbs_bsf.h"
26 #include "cbs_vp9.h"
27 
28 typedef struct VP9MetadataContext {
30 
33 
36 
37 
40 {
42  int i;
43 
44  for (i = 0; i < frag->nb_units; i++) {
45  VP9RawFrame *frame = frag->units[i].content;
46  VP9RawFrameHeader *header = &frame->header;
47  int profile = (header->profile_high_bit << 1) + header->profile_low_bit;
48 
49  if (header->frame_type == VP9_KEY_FRAME ||
50  header->intra_only && profile > 0) {
51  if (ctx->color_space >= 0) {
52  if (!(profile & 1) && ctx->color_space == VP9_CS_RGB) {
53  if (!(ctx->color_warnings & 2)) {
54  av_log(bsf, AV_LOG_WARNING, "Warning: RGB "
55  "incompatible with profiles 0 and 2.\n");
56  ctx->color_warnings |= 2;
57  }
58  } else
59  header->color_space = ctx->color_space;
60  }
61 
62  if (ctx->color_range >= 0)
63  header->color_range = ctx->color_range;
64  if (header->color_space == VP9_CS_RGB) {
65  if (!(ctx->color_warnings & 1) && !header->color_range) {
66  av_log(bsf, AV_LOG_WARNING, "Warning: Color space RGB "
67  "implicitly sets color range to PC range.\n");
68  ctx->color_warnings |= 1;
69  }
70  header->color_range = 1;
71  }
72  } else if (!(ctx->color_warnings & 4) && header->intra_only && !profile &&
73  ctx->color_space >= 0 && ctx->color_space != VP9_CS_BT_601) {
74  av_log(bsf, AV_LOG_WARNING, "Warning: Intra-only frames in "
75  "profile 0 are automatically BT.601.\n");
76  ctx->color_warnings |= 4;
77  }
78  }
79 
80  return 0;
81 }
82 
83 static const CBSBSFType vp9_metadata_type = {
85  .fragment_name = "superframe",
86  .unit_name = "frame",
87  .update_fragment = &vp9_metadata_update_fragment,
88 };
89 
91 {
93 }
94 
95 #define OFFSET(x) offsetof(VP9MetadataContext, x)
96 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
97 static const AVOption vp9_metadata_options[] = {
98  { "color_space", "Set colour space (section 7.2.2)",
99  OFFSET(color_space), AV_OPT_TYPE_INT,
100  { .i64 = -1 }, -1, VP9_CS_RGB, FLAGS, .unit = "cs" },
101  { "unknown", "Unknown/unspecified", 0, AV_OPT_TYPE_CONST,
102  { .i64 = VP9_CS_UNKNOWN }, .flags = FLAGS, .unit = "cs" },
103  { "bt601", "ITU-R BT.601-7", 0, AV_OPT_TYPE_CONST,
104  { .i64 = VP9_CS_BT_601 }, .flags = FLAGS, .unit = "cs" },
105  { "bt709", "ITU-R BT.709-6", 0, AV_OPT_TYPE_CONST,
106  { .i64 = VP9_CS_BT_709 }, .flags = FLAGS, .unit = "cs" },
107  { "smpte170", "SMPTE-170", 0, AV_OPT_TYPE_CONST,
108  { .i64 = VP9_CS_SMPTE_170 }, .flags = FLAGS, .unit = "cs" },
109  { "smpte240", "SMPTE-240", 0, AV_OPT_TYPE_CONST,
110  { .i64 = VP9_CS_SMPTE_240 }, .flags = FLAGS, .unit = "cs" },
111  { "bt2020", "ITU-R BT.2020-2", 0, AV_OPT_TYPE_CONST,
112  { .i64 = VP9_CS_BT_2020 }, .flags = FLAGS, .unit = "cs" },
113  { "rgb", "sRGB / IEC 61966-2-1", 0, AV_OPT_TYPE_CONST,
114  { .i64 = VP9_CS_RGB }, .flags = FLAGS, .unit = "cs" },
115 
116  { "color_range", "Set colour range (section 7.2.2)",
118  { .i64 = -1 }, -1, 1, FLAGS, .unit = "cr" },
119  { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST,
120  { .i64 = 0 }, .flags = FLAGS, .unit = "cr" },
121  { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST,
122  { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
123 
124  { NULL }
125 };
126 
127 static const AVClass vp9_metadata_class = {
128  .class_name = "vp9_metadata_bsf",
129  .item_name = av_default_item_name,
130  .option = vp9_metadata_options,
131  .version = LIBAVUTIL_VERSION_INT,
132 };
133 
134 static const enum AVCodecID vp9_metadata_codec_ids[] = {
136 };
137 
139  .p.name = "vp9_metadata",
140  .p.codec_ids = vp9_metadata_codec_ids,
141  .p.priv_class = &vp9_metadata_class,
142  .priv_data_size = sizeof(VP9MetadataContext),
144  .close = &ff_cbs_bsf_generic_close,
146 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
vp9_metadata_options
static const AVOption vp9_metadata_options[]
Definition: vp9_metadata.c:97
ff_cbs_bsf_generic_init
int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition: cbs_bsf.c:110
bsf_internal.h
opt.h
CBSBSFType::codec_id
enum AVCodecID codec_id
Definition: cbs_bsf.h:32
vp9_metadata_codec_ids
static enum AVCodecID vp9_metadata_codec_ids[]
Definition: vp9_metadata.c:134
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
AVOption
AVOption.
Definition: opt.h:346
CBSBSFContext
Definition: cbs_bsf.h:53
cbs.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
VP9MetadataContext::common
CBSBSFContext common
Definition: vp9_metadata.c:29
VP9MetadataContext::color_range
int color_range
Definition: vp9_metadata.c:32
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
bsf.h
cbs_bsf.h
VP9_CS_BT_2020
@ VP9_CS_BT_2020
Definition: cbs_vp9.h:62
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
VP9MetadataContext
Definition: vp9_metadata.c:28
pkt
AVPacket * pkt
Definition: movenc.c:59
vp9_metadata_init
static int vp9_metadata_init(AVBSFContext *bsf)
Definition: vp9_metadata.c:90
VP9_CS_BT_601
@ VP9_CS_BT_601
Definition: cbs_vp9.h:58
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
cbs_vp9.h
ctx
AVFormatContext * ctx
Definition: movenc.c:48
VP9RawFrameHeader
Definition: cbs_vp9.h:83
color_range
color_range
Definition: vf_selectivecolor.c:43
frame
static AVFrame * frame
Definition: demux_decode.c:54
if
if(ret)
Definition: filter_design.txt:179
VP9_CS_SMPTE_240
@ VP9_CS_SMPTE_240
Definition: cbs_vp9.h:61
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
FFBitStreamFilter
Definition: bsf_internal.h:27
ff_vp9_metadata_bsf
const FFBitStreamFilter ff_vp9_metadata_bsf
Definition: vp9_metadata.c:138
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
VP9MetadataContext::color_space
int color_space
Definition: vp9_metadata.c:31
VP9_CS_SMPTE_170
@ VP9_CS_SMPTE_170
Definition: cbs_vp9.h:60
VP9RawFrame
Definition: cbs_vp9.h:164
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
CBSBSFType
Definition: cbs_bsf.h:31
ff_cbs_bsf_generic_close
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition: cbs_bsf.c:155
header
static const uint8_t header[24]
Definition: sdr2.c:68
vp9_metadata_class
static const AVClass vp9_metadata_class
Definition: vp9_metadata.c:127
FLAGS
#define FLAGS
Definition: vp9_metadata.c:96
log.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
VP9MetadataContext::color_warnings
int color_warnings
Definition: vp9_metadata.c:34
VP9_CS_UNKNOWN
@ VP9_CS_UNKNOWN
Definition: cbs_vp9.h:57
profile
int profile
Definition: mxfenc.c:2226
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:83
ff_cbs_bsf_generic_filter
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
Definition: cbs_bsf.c:61
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
VP9_KEY_FRAME
@ VP9_KEY_FRAME
Definition: cbs_vp9.h:44
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
vp9_metadata_type
static const CBSBSFType vp9_metadata_type
Definition: vp9_metadata.c:83
vp9_metadata_update_fragment
static int vp9_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *frag)
Definition: vp9_metadata.c:38
OFFSET
#define OFFSET(x)
Definition: vp9_metadata.c:95
AVPacket
This structure stores compressed data.
Definition: packet.h:499
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
VP9_CS_BT_709
@ VP9_CS_BT_709
Definition: cbs_vp9.h:59
VP9_CS_RGB
@ VP9_CS_RGB
Definition: cbs_vp9.h:64
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153