FFmpeg
vf_tonemap_vaapi.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 #include <string.h>
19 
20 #include "libavutil/opt.h"
21 #include "libavutil/pixdesc.h"
23 
24 #include "avfilter.h"
25 #include "filters.h"
26 #include "vaapi_vpp.h"
27 #include "video.h"
28 
29 typedef struct HDRVAAPIContext {
30  VAAPIVPPContext vpp_ctx; // must be the first field
31 
33 
37 
41 
44 
45  VAHdrMetaDataHDR10 in_metadata;
46  VAHdrMetaDataHDR10 out_metadata;
47 
51 
52 static int tonemap_vaapi_save_metadata(AVFilterContext *avctx, AVFrame *input_frame)
53 {
54  HDRVAAPIContext *ctx = avctx->priv;
56  AVContentLightMetadata *light_meta;
57 
58  if (input_frame->color_trc != AVCOL_TRC_SMPTE2084) {
59  av_log(avctx, AV_LOG_WARNING, "Only support HDR10 as input for vaapi tone-mapping\n");
60  }
61 
62  ctx->src_display = av_frame_get_side_data(input_frame,
64  if (ctx->src_display) {
65  hdr_meta = (AVMasteringDisplayMetadata *)ctx->src_display->data;
66  if (!hdr_meta) {
67  av_log(avctx, AV_LOG_ERROR, "No mastering display data\n");
68  return AVERROR(EINVAL);
69  }
70 
71  if (hdr_meta->has_luminance) {
72  const int luma_den = 10000;
73  ctx->in_metadata.max_display_mastering_luminance =
74  lrint(luma_den * av_q2d(hdr_meta->max_luminance));
75  ctx->in_metadata.min_display_mastering_luminance =
76  FFMIN(lrint(luma_den * av_q2d(hdr_meta->min_luminance)),
77  ctx->in_metadata.max_display_mastering_luminance);
78 
79  av_log(avctx, AV_LOG_DEBUG,
80  "Mastering Display Metadata(in luminance):\n");
81  av_log(avctx, AV_LOG_DEBUG,
82  "min_luminance=%u, max_luminance=%u\n",
83  ctx->in_metadata.min_display_mastering_luminance,
84  ctx->in_metadata.max_display_mastering_luminance);
85  }
86 
87  if (hdr_meta->has_primaries) {
88  int i;
89  const int mapping[3] = {1, 2, 0}; //green, blue, red
90  const int chroma_den = 50000;
91 
92  for (i = 0; i < 3; i++) {
93  const int j = mapping[i];
94  ctx->in_metadata.display_primaries_x[i] =
95  FFMIN(lrint(chroma_den *
96  av_q2d(hdr_meta->display_primaries[j][0])),
97  chroma_den);
98  ctx->in_metadata.display_primaries_y[i] =
99  FFMIN(lrint(chroma_den *
100  av_q2d(hdr_meta->display_primaries[j][1])),
101  chroma_den);
102  }
103 
104  ctx->in_metadata.white_point_x =
105  FFMIN(lrint(chroma_den * av_q2d(hdr_meta->white_point[0])),
106  chroma_den);
107  ctx->in_metadata.white_point_y =
108  FFMIN(lrint(chroma_den * av_q2d(hdr_meta->white_point[1])),
109  chroma_den);
110 
111  av_log(avctx, AV_LOG_DEBUG,
112  "Mastering Display Metadata(in primaries):\n");
113  av_log(avctx, AV_LOG_DEBUG,
114  "G(%u,%u) B(%u,%u) R(%u,%u) WP(%u,%u)\n",
115  ctx->in_metadata.display_primaries_x[0],
116  ctx->in_metadata.display_primaries_y[0],
117  ctx->in_metadata.display_primaries_x[1],
118  ctx->in_metadata.display_primaries_y[1],
119  ctx->in_metadata.display_primaries_x[2],
120  ctx->in_metadata.display_primaries_y[2],
121  ctx->in_metadata.white_point_x,
122  ctx->in_metadata.white_point_y);
123  }
124  } else {
125  av_log(avctx, AV_LOG_ERROR, "No mastering display data from input\n");
126  return AVERROR(EINVAL);
127  }
128 
129  ctx->src_light = av_frame_get_side_data(input_frame,
131  if (ctx->src_light) {
132  light_meta = (AVContentLightMetadata *)ctx->src_light->data;
133  if (!light_meta) {
134  av_log(avctx, AV_LOG_ERROR, "No light metadata\n");
135  return AVERROR(EINVAL);
136  }
137 
138  ctx->in_metadata.max_content_light_level = light_meta->MaxCLL;
139  ctx->in_metadata.max_pic_average_light_level = light_meta->MaxFALL;
140 
141  av_log(avctx, AV_LOG_DEBUG,
142  "Mastering Content Light Level (in):\n");
143  av_log(avctx, AV_LOG_DEBUG,
144  "MaxCLL(%u) MaxFALL(%u)\n",
145  ctx->in_metadata.max_content_light_level,
146  ctx->in_metadata.max_pic_average_light_level);
147  } else {
148  av_log(avctx, AV_LOG_DEBUG, "No content light level from input\n");
149  }
150  return 0;
151 }
152 
154 {
155  HDRVAAPIContext *ctx = avctx->priv;
156  AVFrameSideData *metadata;
157  AVMasteringDisplayMetadata *hdr_meta;
158  AVFrameSideData *metadata_lt;
159  AVContentLightMetadata *hdr_meta_lt;
160  int i;
161  const int mapping[3] = {1, 2, 0}; //green, blue, red
162  const int chroma_den = 50000;
163  const int luma_den = 10000;
164 
168  if (!metadata)
169  return AVERROR(ENOMEM);
170 
171  hdr_meta = (AVMasteringDisplayMetadata *)metadata->data;
172 
173  for (i = 0; i < 3; i++) {
174  const int j = mapping[i];
175  hdr_meta->display_primaries[j][0].num = ctx->out_metadata.display_primaries_x[i];
176  hdr_meta->display_primaries[j][0].den = chroma_den;
177 
178  hdr_meta->display_primaries[j][1].num = ctx->out_metadata.display_primaries_y[i];
179  hdr_meta->display_primaries[j][1].den = chroma_den;
180  }
181 
182  hdr_meta->white_point[0].num = ctx->out_metadata.white_point_x;
183  hdr_meta->white_point[0].den = chroma_den;
184 
185  hdr_meta->white_point[1].num = ctx->out_metadata.white_point_y;
186  hdr_meta->white_point[1].den = chroma_den;
187  hdr_meta->has_primaries = 1;
188 
189  hdr_meta->max_luminance.num = ctx->out_metadata.max_display_mastering_luminance;
190  hdr_meta->max_luminance.den = luma_den;
191 
192  hdr_meta->min_luminance.num = ctx->out_metadata.min_display_mastering_luminance;
193  hdr_meta->min_luminance.den = luma_den;
194  hdr_meta->has_luminance = 1;
195 
196  av_log(avctx, AV_LOG_DEBUG,
197  "Mastering display colour volume(out):\n");
198  av_log(avctx, AV_LOG_DEBUG,
199  "G(%u,%u) B(%u,%u) R(%u,%u) WP(%u,%u)\n",
200  ctx->out_metadata.display_primaries_x[0],
201  ctx->out_metadata.display_primaries_y[0],
202  ctx->out_metadata.display_primaries_x[1],
203  ctx->out_metadata.display_primaries_y[1],
204  ctx->out_metadata.display_primaries_x[2],
205  ctx->out_metadata.display_primaries_y[2],
206  ctx->out_metadata.white_point_x,
207  ctx->out_metadata.white_point_y);
208  av_log(avctx, AV_LOG_DEBUG,
209  "max_display_mastering_luminance=%u, min_display_mastering_luminance=%u\n",
210  ctx->out_metadata.max_display_mastering_luminance,
211  ctx->out_metadata.min_display_mastering_luminance);
212 
213  metadata_lt = av_frame_new_side_data(output_frame,
215  sizeof(AVContentLightMetadata));
216  if (!metadata_lt)
217  return AVERROR(ENOMEM);
218 
219  hdr_meta_lt = (AVContentLightMetadata *)metadata_lt->data;
220 
221  hdr_meta_lt->MaxCLL = FFMIN(ctx->out_metadata.max_content_light_level, 65535);
222  hdr_meta_lt->MaxFALL = FFMIN(ctx->out_metadata.max_pic_average_light_level, 65535);
223 
224  av_log(avctx, AV_LOG_DEBUG,
225  "Content light level information(out):\n");
226  av_log(avctx, AV_LOG_DEBUG,
227  "MaxCLL(%u) MaxFALL(%u)\n",
228  ctx->out_metadata.max_content_light_level,
229  ctx->out_metadata.max_pic_average_light_level);
230 
231  return 0;
232 }
233 
235 {
236  VAAPIVPPContext *vpp_ctx = avctx->priv;
237  HDRVAAPIContext *ctx = avctx->priv;
238  VAStatus vas;
239  VAProcFilterParameterBufferHDRToneMapping *hdrtm_param;
240 
241  vas = vaMapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0],
242  (void**)&hdrtm_param);
243  if (vas != VA_STATUS_SUCCESS) {
244  av_log(avctx, AV_LOG_ERROR, "Failed to map "
245  "buffer (%d): %d (%s).\n",
246  vpp_ctx->filter_buffers[0], vas, vaErrorStr(vas));
247  return AVERROR(EIO);
248  }
249 
250  memcpy(hdrtm_param->data.metadata, &ctx->in_metadata, sizeof(VAHdrMetaDataHDR10));
251 
252  vas = vaUnmapBuffer(vpp_ctx->hwctx->display, vpp_ctx->filter_buffers[0]);
253  if (vas != VA_STATUS_SUCCESS) {
254  av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
255  "%d (%s).\n", vas, vaErrorStr(vas));
256  return AVERROR(EIO);
257  }
258 
259  return 0;
260 }
261 
263 {
264  VAAPIVPPContext *vpp_ctx = avctx->priv;
265  HDRVAAPIContext *ctx = avctx->priv;
266  VAStatus vas;
267  VAProcFilterParameterBufferHDRToneMapping hdrtm_param;
268  VAProcFilterCapHighDynamicRange hdr_cap[VAProcHighDynamicRangeMetadataTypeCount];
269  int num_query_caps;
270  int i;
271 
272  memset(&hdrtm_param, 0, sizeof(hdrtm_param));
273  memset(&ctx->in_metadata, 0, sizeof(ctx->in_metadata));
274 
275  num_query_caps = VAProcHighDynamicRangeMetadataTypeCount;
276  vas = vaQueryVideoProcFilterCaps(vpp_ctx->hwctx->display,
277  vpp_ctx->va_context,
278  VAProcFilterHighDynamicRangeToneMapping,
279  &hdr_cap, &num_query_caps);
280  if (vas != VA_STATUS_SUCCESS) {
281  av_log(avctx, AV_LOG_ERROR, "Failed to query HDR caps "
282  "context: %d (%s).\n", vas, vaErrorStr(vas));
283  return AVERROR(EIO);
284  }
285 
286  for (i = 0; i < num_query_caps; i++) {
287  if (hdr_cap[i].metadata_type != VAProcHighDynamicRangeMetadataNone)
288  break;
289  }
290 
291  if (i >= num_query_caps) {
292  av_log(avctx, AV_LOG_ERROR, "VAAPI driver doesn't support HDR\n");
293  return AVERROR(EINVAL);
294  }
295 
296  if (ctx->mastering_display) {
297  for (i = 0; i < num_query_caps; i++) {
298  if (VA_TONE_MAPPING_HDR_TO_HDR & hdr_cap[i].caps_flag)
299  break;
300  }
301  if (i >= num_query_caps) {
302  av_log(avctx, AV_LOG_ERROR,
303  "VAAPI driver doesn't support HDR to HDR\n");
304  return AVERROR(EINVAL);
305  }
306  } else {
307  for (i = 0; i < num_query_caps; i++) {
308  if (VA_TONE_MAPPING_HDR_TO_SDR & hdr_cap[i].caps_flag)
309  break;
310  }
311  if (i >= num_query_caps) {
312  av_log(avctx, AV_LOG_ERROR,
313  "VAAPI driver doesn't support HDR to SDR\n");
314  return AVERROR(EINVAL);
315  }
316  }
317 
318  hdrtm_param.type = VAProcFilterHighDynamicRangeToneMapping;
319  hdrtm_param.data.metadata_type = VAProcHighDynamicRangeMetadataHDR10;
320  hdrtm_param.data.metadata = &ctx->in_metadata;
321  hdrtm_param.data.metadata_size = sizeof(VAHdrMetaDataHDR10);
322 
323  return ff_vaapi_vpp_make_param_buffers(avctx,
324  VAProcFilterParameterBufferType,
325  &hdrtm_param, sizeof(hdrtm_param), 1);
326 }
327 
329 {
330  AVFilterContext *avctx = inlink->dst;
331  AVFilterLink *outlink = avctx->outputs[0];
332  VAAPIVPPContext *vpp_ctx = avctx->priv;
333  HDRVAAPIContext *ctx = avctx->priv;
335  VASurfaceID input_surface, output_surface;
336 
337  VAProcPipelineParameterBuffer params;
338  int err;
339 
340  VAHdrMetaData out_hdr_metadata;
341 
342  av_log(avctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n",
343  av_get_pix_fmt_name(input_frame->format),
344  input_frame->width, input_frame->height, input_frame->pts);
345 
346  if (vpp_ctx->va_context == VA_INVALID_ID){
347  av_frame_free(&input_frame);
348  return AVERROR(EINVAL);
349  }
350 
351  err = tonemap_vaapi_save_metadata(avctx, input_frame);
352  if (err < 0)
353  goto fail;
354 
355  err = tonemap_vaapi_set_filter_params(avctx, input_frame);
356  if (err < 0)
357  goto fail;
358 
359  input_surface = (VASurfaceID)(uintptr_t)input_frame->data[3];
360  av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for tonemap vpp input.\n",
361  input_surface);
362 
363  output_frame = ff_get_video_buffer(outlink, vpp_ctx->output_width,
364  vpp_ctx->output_height);
365  if (!output_frame) {
366  err = AVERROR(ENOMEM);
367  goto fail;
368  }
369 
370  output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3];
371  av_log(avctx, AV_LOG_DEBUG, "Using surface %#x for tonemap vpp output.\n",
372  output_surface);
373  memset(&params, 0, sizeof(params));
374 
375  err = av_frame_copy_props(output_frame, input_frame);
376  if (err < 0)
377  goto fail;
378 
381 
382  if (!ctx->mastering_display) {
383  /* Use BT709 by default for HDR to SDR output frame */
384  output_frame->color_primaries = AVCOL_PRI_BT709;
385  output_frame->color_trc = AVCOL_TRC_BT709;
386  output_frame->colorspace = AVCOL_SPC_BT709;
387  }
388 
389  if (ctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
390  output_frame->color_primaries = ctx->color_primaries;
391 
392  if (ctx->color_transfer != AVCOL_TRC_UNSPECIFIED)
393  output_frame->color_trc = ctx->color_transfer;
394 
395  if (ctx->color_matrix != AVCOL_SPC_UNSPECIFIED)
396  output_frame->colorspace = ctx->color_matrix;
397 
398  if (ctx->mastering_display) {
400  if (err < 0)
401  goto fail;
402  }
403 
404  err = ff_vaapi_vpp_init_params(avctx, &params,
405  input_frame, output_frame);
406  if (err < 0)
407  goto fail;
408 
409  if (ctx->mastering_display) {
410  out_hdr_metadata.metadata_type = VAProcHighDynamicRangeMetadataHDR10;
411  out_hdr_metadata.metadata = &ctx->out_metadata;
412  out_hdr_metadata.metadata_size = sizeof(VAHdrMetaDataHDR10);
413  params.output_hdr_metadata = &out_hdr_metadata;
414  }
415 
416  if (vpp_ctx->nb_filter_buffers) {
417  params.filters = &vpp_ctx->filter_buffers[0];
418  params.num_filters = vpp_ctx->nb_filter_buffers;
419  }
420 
421  err = ff_vaapi_vpp_render_picture(avctx, &params, output_frame);
422  if (err < 0)
423  goto fail;
424 
425  av_frame_free(&input_frame);
426 
427  av_log(avctx, AV_LOG_DEBUG, "Filter output: %s, %ux%u (%"PRId64").\n",
429  output_frame->width, output_frame->height, output_frame->pts);
430 
431  return ff_filter_frame(outlink, output_frame);
432 
433 fail:
434  av_frame_free(&input_frame);
436  return err;
437 }
438 
440 {
441  VAAPIVPPContext *vpp_ctx = avctx->priv;
442  HDRVAAPIContext *ctx = avctx->priv;
443 
444  ff_vaapi_vpp_ctx_init(avctx);
447 
448  if (ctx->output_format_string) {
449  vpp_ctx->output_format = av_get_pix_fmt(ctx->output_format_string);
450  } else {
451  if (ctx->mastering_display) {
452  vpp_ctx->output_format = AV_PIX_FMT_P010;
453  av_log(avctx, AV_LOG_VERBOSE, "Output format not set, use default format P010 for HDR to HDR tone mapping.\n");
454  } else {
455  vpp_ctx->output_format = AV_PIX_FMT_NV12;
456  av_log(avctx, AV_LOG_VERBOSE, "Output format not set, use default format NV12 for HDR to SDR tone mapping.\n");
457  }
458  }
459 
460 #define STRING_OPTION(var_name, func_name, default_value) do { \
461  if (ctx->var_name ## _string) { \
462  int var = av_ ## func_name ## _from_name(ctx->var_name ## _string); \
463  if (var < 0) { \
464  av_log(avctx, AV_LOG_ERROR, "Invalid %s.\n", #var_name); \
465  return AVERROR(EINVAL); \
466  } \
467  ctx->var_name = var; \
468  } else { \
469  ctx->var_name = default_value; \
470  } \
471  } while (0)
472 
474  STRING_OPTION(color_transfer, color_transfer, AVCOL_TRC_UNSPECIFIED);
475  STRING_OPTION(color_matrix, color_space, AVCOL_SPC_UNSPECIFIED);
476 
477  if (ctx->mastering_display) {
478  if (10 != sscanf(ctx->mastering_display,
479  "%hu %hu|%hu %hu|%hu %hu|%hu %hu|%u %u",
480  &ctx->out_metadata.display_primaries_x[0],
481  &ctx->out_metadata.display_primaries_y[0],
482  &ctx->out_metadata.display_primaries_x[1],
483  &ctx->out_metadata.display_primaries_y[1],
484  &ctx->out_metadata.display_primaries_x[2],
485  &ctx->out_metadata.display_primaries_y[2],
486  &ctx->out_metadata.white_point_x,
487  &ctx->out_metadata.white_point_y,
488  &ctx->out_metadata.min_display_mastering_luminance,
489  &ctx->out_metadata.max_display_mastering_luminance)) {
490  av_log(avctx, AV_LOG_ERROR,
491  "Option mastering-display input invalid\n");
492  return AVERROR(EINVAL);
493  }
494 
495  if (!ctx->content_light) {
496  ctx->out_metadata.max_content_light_level = 0;
497  ctx->out_metadata.max_pic_average_light_level = 0;
498  } else if (2 != sscanf(ctx->content_light,
499  "%hu %hu",
500  &ctx->out_metadata.max_content_light_level,
501  &ctx->out_metadata.max_pic_average_light_level)) {
502  av_log(avctx, AV_LOG_ERROR,
503  "Option content-light input invalid\n");
504  return AVERROR(EINVAL);
505  }
506  }
507 
508  return 0;
509 }
510 
511 #define OFFSET(x) offsetof(HDRVAAPIContext, x)
512 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
513 static const AVOption tonemap_vaapi_options[] = {
514  { "format", "Output pixel format set", OFFSET(output_format_string), AV_OPT_TYPE_STRING, .flags = FLAGS, .unit = "format" },
515  { "matrix", "Output color matrix coefficient set",
516  OFFSET(color_matrix_string), AV_OPT_TYPE_STRING,
517  { .str = NULL }, .flags = FLAGS, .unit = "matrix" },
518  { "m", "Output color matrix coefficient set",
519  OFFSET(color_matrix_string), AV_OPT_TYPE_STRING,
520  { .str = NULL }, .flags = FLAGS, .unit = "matrix" },
521  { "primaries", "Output color primaries set",
522  OFFSET(color_primaries_string), AV_OPT_TYPE_STRING,
523  { .str = NULL }, .flags = FLAGS, .unit = "primaries" },
524  { "p", "Output color primaries set",
525  OFFSET(color_primaries_string), AV_OPT_TYPE_STRING,
526  { .str = NULL }, .flags = FLAGS, .unit = "primaries" },
527  { "transfer", "Output color transfer characteristics set",
528  OFFSET(color_transfer_string), AV_OPT_TYPE_STRING,
529  { .str = NULL }, .flags = FLAGS, .unit = "transfer" },
530  { "t", "Output color transfer characteristics set",
531  OFFSET(color_transfer_string), AV_OPT_TYPE_STRING,
532  { .str = NULL }, .flags = FLAGS, .unit = "transfer" },
533  { "display", "set mastering display colour volume",
534  OFFSET(mastering_display), AV_OPT_TYPE_STRING,
535  { .str = NULL }, .flags = FLAGS },
536  { "light", "set content light level information",
537  OFFSET(content_light), AV_OPT_TYPE_STRING,
538  { .str = NULL }, .flags = FLAGS },
539  { NULL }
540 };
541 
542 
543 AVFILTER_DEFINE_CLASS(tonemap_vaapi);
544 
546  {
547  .name = "default",
548  .type = AVMEDIA_TYPE_VIDEO,
549  .filter_frame = &tonemap_vaapi_filter_frame,
550  .config_props = &ff_vaapi_vpp_config_input,
551  },
552 };
553 
555  {
556  .name = "default",
557  .type = AVMEDIA_TYPE_VIDEO,
558  .config_props = &ff_vaapi_vpp_config_output,
559  },
560 };
561 
563  .name = "tonemap_vaapi",
564  .description = NULL_IF_CONFIG_SMALL("VAAPI VPP for tone-mapping"),
565  .priv_size = sizeof(HDRVAAPIContext),
571  .priv_class = &tonemap_vaapi_class,
572  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
573 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:672
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
ff_vaapi_vpp_pipeline_uninit
void ff_vaapi_vpp_pipeline_uninit(AVFilterContext *avctx)
Definition: vaapi_vpp.c:45
ff_vaapi_vpp_ctx_init
void ff_vaapi_vpp_ctx_init(AVFilterContext *avctx)
Definition: vaapi_vpp.c:714
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
HDRVAAPIContext::vpp_ctx
VAAPIVPPContext vpp_ctx
Definition: vf_tonemap_vaapi.c:30
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
HDRVAAPIContext::color_matrix
enum AVColorSpace color_matrix
Definition: vf_tonemap_vaapi.c:40
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:611
ff_vaapi_vpp_render_picture
int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, AVFrame *output_frame)
Definition: vaapi_vpp.c:707
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:951
av_frame_new_side_data
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
Definition: frame.c:799
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
AVFrame::width
int width
Definition: frame.h:461
tonemap_vaapi_save_metadata
static int tonemap_vaapi_save_metadata(AVFilterContext *avctx, AVFrame *input_frame)
Definition: vf_tonemap_vaapi.c:52
HDRVAAPIContext::color_primaries_string
char * color_primaries_string
Definition: vf_tonemap_vaapi.c:34
AVOption
AVOption.
Definition: opt.h:429
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:614
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
AVVAAPIDeviceContext::display
VADisplay display
The VADisplay handle, to be filled by the user.
Definition: hwcontext_vaapi.h:72
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:586
HDRVAAPIContext::mastering_display
char * mastering_display
Definition: vf_tonemap_vaapi.c:42
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
video.h
ff_vaapi_vpp_query_formats
int ff_vaapi_vpp_query_formats(const AVFilterContext *avctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vaapi_vpp.c:29
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
HDRVAAPIContext::src_light
AVFrameSideData * src_light
Definition: vf_tonemap_vaapi.c:49
VAAPIVPPContext::build_filter_params
int(* build_filter_params)(AVFilterContext *avctx)
Definition: vaapi_vpp.h:61
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:472
fail
#define fail()
Definition: checkasm.h:188
OFFSET
#define OFFSET(x)
Definition: vf_tonemap_vaapi.c:511
HDRVAAPIContext::color_primaries
enum AVColorPrimaries color_primaries
Definition: vf_tonemap_vaapi.c:38
HDRVAAPIContext::color_transfer
enum AVColorTransferCharacteristic color_transfer
Definition: vf_tonemap_vaapi.c:39
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
lrint
#define lrint
Definition: tablegen.h:53
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
filters.h
VAAPIVPPContext::output_width
int output_width
Definition: vaapi_vpp.h:53
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ctx
AVFormatContext * ctx
Definition: movenc.c:49
VAAPIVPPContext::output_format
enum AVPixelFormat output_format
Definition: vaapi_vpp.h:52
ff_vaapi_vpp_make_param_buffers
int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, size_t size, int count)
Definition: vaapi_vpp.c:582
VAAPIVPPContext::hwctx
AVVAAPIDeviceContext * hwctx
Definition: vaapi_vpp.h:41
HDRVAAPIContext::color_transfer_string
char * color_transfer_string
Definition: vf_tonemap_vaapi.c:35
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:589
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_tonemap_vaapi.c:512
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:713
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:588
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
ff_vaapi_vpp_config_input
int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
Definition: vaapi_vpp.c:71
ff_vaapi_vpp_ctx_uninit
void ff_vaapi_vpp_ctx_uninit(AVFilterContext *avctx)
Definition: vaapi_vpp.c:728
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:206
color_primaries
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition: csp.c:76
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:628
vaapi_vpp.h
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(tonemap_vaapi)
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:476
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:1017
output_frame
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition: h264dec.c:877
tonemap_vaapi_build_filter_params
static int tonemap_vaapi_build_filter_params(AVFilterContext *avctx)
Definition: vf_tonemap_vaapi.c:262
tonemap_vaapi_options
static const AVOption tonemap_vaapi_options[]
Definition: vf_tonemap_vaapi.c:513
ff_vf_tonemap_vaapi
const AVFilter ff_vf_tonemap_vaapi
Definition: vf_tonemap_vaapi.c:562
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:613
HDRVAAPIContext::out_metadata
VAHdrMetaDataHDR10 out_metadata
Definition: vf_tonemap_vaapi.c:46
VAAPIVPPContext::output_height
int output_height
Definition: vaapi_vpp.h:54
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
STRING_OPTION
#define STRING_OPTION(var_name, func_name, default_value)
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
VAAPIVPPContext::filter_buffers
VABufferID filter_buffers[VAProcFilterCount]
Definition: vaapi_vpp.h:56
tonemap_vaapi_outputs
static const AVFilterPad tonemap_vaapi_outputs[]
Definition: vf_tonemap_vaapi.c:554
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:643
AVFilter
Filter definition.
Definition: avfilter.h:201
tonemap_vaapi_filter_frame
static int tonemap_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
Definition: vf_tonemap_vaapi.c:328
VAAPIVPPContext
Definition: vaapi_vpp.h:38
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
VAAPIVPPContext::va_context
VAContextID va_context
Definition: vaapi_vpp.h:46
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3102
HDRVAAPIContext::output_format_string
char * output_format_string
Definition: vf_tonemap_vaapi.c:32
AVFrame::height
int height
Definition: frame.h:461
ff_vaapi_vpp_config_output
int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
Definition: vaapi_vpp.c:97
AVRational::den
int den
Denominator.
Definition: rational.h:60
avfilter.h
HDRVAAPIContext::src_display
AVFrameSideData * src_display
Definition: vf_tonemap_vaapi.c:48
VAAPIVPPContext::pipeline_uninit
void(* pipeline_uninit)(AVFilterContext *avctx)
Definition: vaapi_vpp.h:63
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
tonemap_vaapi_init
static av_cold int tonemap_vaapi_init(AVFilterContext *avctx)
Definition: vf_tonemap_vaapi.c:439
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:552
HDRVAAPIContext::in_metadata
VAHdrMetaDataHDR10 in_metadata
Definition: vf_tonemap_vaapi.c:45
VAAPIVPPContext::nb_filter_buffers
int nb_filter_buffers
Definition: vaapi_vpp.h:57
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mastering_display_metadata.h
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HDRVAAPIContext::content_light
char * content_light
Definition: vf_tonemap_vaapi.c:43
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
tonemap_vaapi_set_filter_params
static int tonemap_vaapi_set_filter_params(AVFilterContext *avctx, AVFrame *input_frame)
Definition: vf_tonemap_vaapi.c:234
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:642
tonemap_vaapi_update_sidedata
static int tonemap_vaapi_update_sidedata(AVFilterContext *avctx, AVFrame *output_frame)
Definition: vf_tonemap_vaapi.c:153
HDRVAAPIContext::color_matrix_string
char * color_matrix_string
Definition: vf_tonemap_vaapi.c:36
tonemap_vaapi_inputs
static const AVFilterPad tonemap_vaapi_inputs[]
Definition: vf_tonemap_vaapi.c:545
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3090
ff_vaapi_vpp_init_params
int ff_vaapi_vpp_init_params(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, const AVFrame *input_frame, AVFrame *output_frame)
Definition: vaapi_vpp.c:533
AVFilterContext::outputs
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:469
HDRVAAPIContext
Definition: vf_tonemap_vaapi.c:29