FFmpeg
liboapvenc.c
Go to the documentation of this file.
1 /*
2  * liboapv encoder
3  * Advanced Professional Video codec library
4  *
5  * Copyright (C) 2025 Dawid Kozinski <d.kozinski@samsung.com>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include <oapv/oapv.h>
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/pixfmt.h"
36 
37 #include "avcodec.h"
38 #include "apv.h"
39 #include "codec_internal.h"
40 #include "encode.h"
41 #include "profiles.h"
42 
43 #define MAX_BS_BUF (128 * 1024 * 1024)
44 #define MAX_NUM_FRMS (1) // supports only 1-frame in an access unit
45 #define FRM_IDX (0) // supports only 1-frame in an access unit
46 #define MAX_NUM_CC (OAPV_MAX_CC) // Max number of color components (upto 4:4:4:4)
47 
48 /**
49  * The structure stores all the states associated with the instance of APV encoder
50  */
51 typedef struct ApvEncContext {
52  const AVClass *class;
53 
54  oapve_t id; // APV instance identifier
55  oapvm_t mid;
56  oapve_cdesc_t cdsc; // coding parameters i.e profile, width & height of input frame, num of therads, frame rate ...
57  oapv_bitb_t bitb; // bitstream buffer (output)
58  oapve_stat_t stat; // encoding status (output)
59 
60  oapv_frms_t ifrms; // frames for input
61 
62  int preset_id; // preset of apv ( fastest, fast, medium, slow, placebo)
63 
64  int qp; // quantization parameter (QP) [0,63]
65 
68 
69 static int apv_imgb_release(oapv_imgb_t *imgb)
70 {
71  int refcnt = --imgb->refcnt;
72  if (refcnt == 0) {
73  for (int i = 0; i < imgb->np; i++)
74  av_freep(&imgb->baddr[i]);
75  av_free(imgb);
76  }
77 
78  return refcnt;
79 }
80 
81 static int apv_imgb_addref(oapv_imgb_t * imgb)
82 {
83  int refcnt = ++imgb->refcnt;
84  return refcnt;
85 }
86 
87 static int apv_imgb_getref(oapv_imgb_t * imgb)
88 {
89  return imgb->refcnt;
90 }
91 
92 /**
93  * Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format
94  *
95  * @return APV pre-defined color format (@see oapv.h) on success, OAPV_CF_UNKNOWN on failure
96  */
97 static inline int get_color_format(enum AVPixelFormat pix_fmt)
98 {
99  switch (pix_fmt) {
100  default:
101  av_unreachable("Already checked via CODEC_PIXFMTS");
102  case AV_PIX_FMT_GRAY10:
103  return OAPV_CF_YCBCR400;
105  return OAPV_CF_YCBCR422;
107  return OAPV_CF_YCBCR422;
109  return OAPV_CF_YCBCR444;
111  return OAPV_CF_YCBCR444;
113  return OAPV_CF_YCBCR4444;
115  return OAPV_CF_YCBCR4444;
116  }
117 }
118 
120 {
121  switch (pix_fmt) {
122  default:
123  av_unreachable("Already checked via CODEC_PIXFMTS");
124  case AV_PIX_FMT_GRAY10:
125  return APV_CHROMA_FORMAT_400;
128  return APV_CHROMA_FORMAT_422;
131  return APV_CHROMA_FORMAT_444;
134  return APV_CHROMA_FORMAT_4444;
135  }
136 }
137 
138 static inline int get_min_profile(enum AVPixelFormat pix_fmt)
139 {
140  switch (pix_fmt) {
141  default:
142  av_unreachable("Already checked via CODEC_PIXFMTS");
143  case AV_PIX_FMT_GRAY10:
144  return AV_PROFILE_APV_400_10;
146  return AV_PROFILE_APV_422_10;
148  return AV_PROFILE_APV_422_12;
150  return AV_PROFILE_APV_444_10;
152  return AV_PROFILE_APV_444_12;
154  return AV_PROFILE_APV_4444_10;
156  return AV_PROFILE_APV_4444_12;
157  }
158 }
159 
161 {
163  const int chroma_format_idc = get_chroma_format_idc(pix_fmt);
164  const int bit_depth = desc->comp[0].depth;
165 
166  av_assert0(desc);
167 
168  switch (profile) {
170  return chroma_format_idc == APV_CHROMA_FORMAT_422 && bit_depth == 10;
172  return chroma_format_idc == APV_CHROMA_FORMAT_422 &&
173  bit_depth >= 10 && bit_depth <= 12;
175  return chroma_format_idc >= APV_CHROMA_FORMAT_422 &&
176  chroma_format_idc <= APV_CHROMA_FORMAT_444 &&
177  bit_depth == 10;
179  return chroma_format_idc >= APV_CHROMA_FORMAT_422 &&
180  chroma_format_idc <= APV_CHROMA_FORMAT_444 &&
181  bit_depth >= 10 && bit_depth <= 12;
183  return chroma_format_idc >= APV_CHROMA_FORMAT_422 &&
184  chroma_format_idc <= APV_CHROMA_FORMAT_4444 &&
185  bit_depth == 10;
187  return chroma_format_idc >= APV_CHROMA_FORMAT_422 &&
188  chroma_format_idc <= APV_CHROMA_FORMAT_4444 &&
189  bit_depth >= 10 && bit_depth <= 12;
191  return chroma_format_idc == APV_CHROMA_FORMAT_400 && bit_depth == 10;
192  default:
193  return 0;
194  }
195 }
196 
197 static int validate_profile(AVCodecContext *avctx, int profile)
198 {
199  const int minimum = get_min_profile(avctx->pix_fmt);
200  const char *profile_name = av_get_profile_name(avctx->codec, profile);
201  const char *minimum_name = av_get_profile_name(avctx->codec, minimum);
202 
203  if (!profile_is_compatible(avctx->pix_fmt, profile)) {
204  av_log(avctx, AV_LOG_ERROR,
205  "Profile %s (%d) is incompatible with pixel format %s; minimum compatible profile is %s (%d)\n",
206  profile_name ? profile_name : "unknown", profile,
208  minimum_name ? minimum_name : "unknown", minimum);
209  return AVERROR(EINVAL);
210  }
211 
212  return 0;
213 }
214 
215 static oapv_imgb_t *apv_imgb_create(AVCodecContext *avctx)
216 {
218  oapv_imgb_t *imgb;
219  int input_depth;
220  int cfmt; // color format
221  int cs;
222 
223  av_assert0(desc);
224 
225  imgb = av_mallocz(sizeof(oapv_imgb_t));
226  if (!imgb)
227  goto fail;
228 
229  input_depth = desc->comp[0].depth;
230  cfmt = get_color_format(avctx->pix_fmt);
231  cs = OAPV_CS_SET(cfmt, input_depth, AV_HAVE_BIGENDIAN);
232 
233  imgb->np = desc->nb_components;
234 
235  for (int i = 0; i < imgb->np; i++) {
236  imgb->w[i] = avctx->width >> ((i == 1 || i == 2) ? desc->log2_chroma_w : 0);
237  imgb->h[i] = avctx->height;
238  imgb->aw[i] = FFALIGN(imgb->w[i], OAPV_MB_W);
239  imgb->ah[i] = FFALIGN(imgb->h[i], OAPV_MB_H);
240  imgb->s[i] = imgb->aw[i] * OAPV_CS_GET_BYTE_DEPTH(cs);
241 
242  imgb->bsize[i] = imgb->e[i] = imgb->s[i] * imgb->ah[i];
243  imgb->a[i] = imgb->baddr[i] = av_mallocz(imgb->bsize[i]);
244  if (imgb->a[i] == NULL)
245  goto fail;
246  }
247 
248  imgb->cs = cs;
249  imgb->addref = apv_imgb_addref;
250  imgb->getref = apv_imgb_getref;
251  imgb->release = apv_imgb_release;
252  imgb->refcnt = 1;
253 
254  return imgb;
255 fail:
256  av_log(avctx, AV_LOG_ERROR, "cannot create image buffer\n");
257  if (imgb) {
258  for (int i = 0; i < imgb->np; i++)
259  av_freep(&imgb->a[i]);
260  av_freep(&imgb);
261  }
262  return NULL;
263 }
264 
265 /**
266  * Populate the liboapv configuration from AVCodecContext and encoder options.
267  *
268  * AVCodecContext fields are applied first, followed by liboapv private options
269  * and finally oapv-params. The APV profile defaults to the minimum profile
270  * implied by pix_fmt, and later overrides must remain compatible with that
271  * pixel format.
272  *
273  * @param[in] avctx codec context (AVCodecContext)
274  * @param[out] cdsc contains all APV encoder encoder parameters that should be initialized before the encoder is use
275  *
276  * @return 0 on success, negative error code on failure
277  */
278 static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
279 {
280  ApvEncContext *apv = avctx->priv_data;
281 
282  /* initialize apv_param struct with default values */
283  int ret = oapve_param_default(&cdsc->param[FRM_IDX]);
284  if (OAPV_FAILED(ret)) {
285  av_log(avctx, AV_LOG_ERROR, "Cannot set default parameter\n");
286  return AVERROR_EXTERNAL;
287  }
288 
289  /* read options from AVCodecContext */
290  cdsc->param[FRM_IDX].w = avctx->width;
291  cdsc->param[FRM_IDX].h = avctx->height;
292 
293  if (avctx->framerate.num > 0) {
294  cdsc->param[FRM_IDX].fps_num = avctx->framerate.num;
295  cdsc->param[FRM_IDX].fps_den = avctx->framerate.den;
296  } else if (avctx->time_base.num > 0) {
297  cdsc->param[FRM_IDX].fps_num = avctx->time_base.den;
298  cdsc->param[FRM_IDX].fps_den = avctx->time_base.num;
299  }
300 
301  cdsc->param[FRM_IDX].profile_idc = get_min_profile(avctx->pix_fmt);
302  if (avctx->profile != AV_PROFILE_UNKNOWN) {
303  ret = validate_profile(avctx, avctx->profile);
304  if (ret < 0)
305  return ret;
306  cdsc->param[FRM_IDX].profile_idc = avctx->profile;
307  }
308  cdsc->param[FRM_IDX].preset = apv->preset_id;
309  cdsc->param[FRM_IDX].qp = apv->qp;
310  if (avctx->bit_rate / 1000 > INT_MAX || avctx->rc_max_rate / 1000 > INT_MAX) {
311  av_log(avctx, AV_LOG_ERROR, "bit_rate and rc_max_rate > %d000 is not supported\n", INT_MAX);
312  return AVERROR(EINVAL);
313  }
314  cdsc->param[FRM_IDX].bitrate = (int)(avctx->bit_rate / 1000);
315  if (cdsc->param[FRM_IDX].bitrate) {
316  if (cdsc->param[FRM_IDX].qp) {
317  av_log(avctx, AV_LOG_WARNING, "You cannot set both the bitrate and the QP parameter at the same time.\n"
318  "If the bitrate is set, the rate control type is set to ABR, which means that the QP value is ignored.\n");
319  }
320  cdsc->param[FRM_IDX].rc_type = OAPV_RC_ABR;
321  }
322 
323  cdsc->threads = avctx->thread_count;
324 
325  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) {
326  cdsc->param[FRM_IDX].color_primaries = avctx->color_primaries;
327  cdsc->param[FRM_IDX].color_description_present_flag = 1;
328  }
329 
330  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED) {
331  cdsc->param[FRM_IDX].transfer_characteristics = avctx->color_trc;
332  cdsc->param[FRM_IDX].color_description_present_flag = 1;
333  }
334 
335  if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
336  cdsc->param[FRM_IDX].matrix_coefficients = avctx->colorspace;
337  cdsc->param[FRM_IDX].color_description_present_flag = 1;
338  }
339 
340  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) {
341  cdsc->param[FRM_IDX].full_range_flag = (avctx->color_range == AVCOL_RANGE_JPEG);
342  cdsc->param[FRM_IDX].color_description_present_flag = 1;
343  }
344 
345  cdsc->max_bs_buf_size = MAX_BS_BUF; /* maximum bitstream buffer size */
346  cdsc->max_num_frms = MAX_NUM_FRMS;
347 
348  const AVDictionaryEntry *en = NULL;
349  while (en = av_dict_iterate(apv->oapv_params, en)) {
350  ret = oapve_param_parse(&cdsc->param[FRM_IDX], en->key, en->value);
351  if (ret < 0)
352  av_log(avctx, AV_LOG_WARNING, "Error parsing option '%s = %s'.\n", en->key, en->value);
353  }
354 
355  ret = validate_profile(avctx, cdsc->param[FRM_IDX].profile_idc);
356  if (ret < 0)
357  return ret;
358 
359  avctx->profile = cdsc->param[FRM_IDX].profile_idc;
360 
361  return 0;
362 }
363 
364 /**
365  * @brief Initialize APV codec
366  * Create an encoder instance and allocate all the needed resources
367  *
368  * @param avctx codec context
369  * @return 0 on success, negative error code on failure
370  */
372 {
373  ApvEncContext *apv = avctx->priv_data;
374  oapve_cdesc_t *cdsc = &apv->cdsc;
375  unsigned char *bs_buf;
376  int ret;
377 
378  /* allocate bitstream buffer */
379  bs_buf = (unsigned char *)av_malloc(MAX_BS_BUF);
380  if (bs_buf == NULL) {
381  av_log(avctx, AV_LOG_ERROR, "Cannot allocate bitstream buffer, size=%d\n", MAX_BS_BUF);
382  return AVERROR(ENOMEM);
383  }
384  apv->bitb.addr = bs_buf;
385  apv->bitb.bsize = MAX_BS_BUF;
386 
387  /* read configurations and set values for created descriptor (APV_CDSC) */
388  ret = get_conf(avctx, cdsc);
389  if (ret < 0) {
390  av_log(avctx, AV_LOG_ERROR, "Cannot get OAPV configuration\n");
391  return ret;
392  }
393 
394  /* create encoder */
395  apv->id = oapve_create(cdsc, &ret);
396  if (apv->id == NULL) {
397  av_log(avctx, AV_LOG_ERROR, "Cannot create OAPV encoder\n");
398  if (ret == OAPV_ERR_INVALID_LEVEL)
399  av_log(avctx, AV_LOG_ERROR, "Invalid level idc: %d\n", cdsc->param[0].level_idc);
400  return AVERROR_EXTERNAL;
401  }
402 
403  /* create metadata handler */
404  apv->mid = oapvm_create(&ret);
405  if (apv->mid == NULL || OAPV_FAILED(ret)) {
406  av_log(avctx, AV_LOG_ERROR, "cannot create OAPV metadata handler\n");
407  return AVERROR_EXTERNAL;
408  }
409 
410  int value = OAPV_CFG_VAL_AU_BS_FMT_NONE;
411  int size = 4;
412  ret = oapve_config(apv->id, OAPV_CFG_SET_AU_BS_FMT, &value, &size);
413  if (OAPV_FAILED(ret)) {
414  av_log(avctx, AV_LOG_ERROR, "Failed to set config for using encoder output format\n");
415  return AVERROR_EXTERNAL;
416  }
417 
418  apv->ifrms.frm[FRM_IDX].imgb = apv_imgb_create(avctx);
419  if (apv->ifrms.frm[FRM_IDX].imgb == NULL)
420  return AVERROR(ENOMEM);
421  apv->ifrms.num_frms++;
422 
423  /* color description values */
424  if (cdsc->param[FRM_IDX].color_description_present_flag) {
425  avctx->color_primaries = cdsc->param[FRM_IDX].color_primaries;
426  avctx->color_trc = cdsc->param[FRM_IDX].transfer_characteristics;
427  avctx->colorspace = cdsc->param[FRM_IDX].matrix_coefficients;
428  avctx->color_range = (cdsc->param[FRM_IDX].full_range_flag) ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
429  }
430 
431  return 0;
432 }
433 
434 /**
435  * Encode raw data frame into APV packet
436  *
437  * @param[in] avctx codec context
438  * @param[out] avpkt output AVPacket containing encoded data
439  * @param[in] frame AVFrame containing the raw data to be encoded
440  * @param[out] got_packet encoder sets to 0 or 1 to indicate that a
441  * non-empty packet was returned in pkt
442  *
443  * @return 0 on success, negative error code on failure
444  */
445 static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt,
446  const AVFrame *frame, int *got_packet)
447 {
448  ApvEncContext *apv = avctx->priv_data;
449  const oapve_cdesc_t *cdsc = &apv->cdsc;
450  oapv_frm_t *frm = &apv->ifrms.frm[FRM_IDX];
451  oapv_imgb_t *imgb = frm->imgb;
452  int ret;
453 
454  av_image_copy2((uint8_t **)imgb->a, imgb->s, frame->data, frame->linesize,
455  frame->format, frame->width, frame->height);
456 
457  imgb->ts[0] = frame->pts;
458 
459  frm->group_id = 1; // @todo FIX-ME : need to set properly in case of multi-frame
460  frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
461 
462  ret = oapve_encode(apv->id, &apv->ifrms, apv->mid, &apv->bitb, &apv->stat, NULL);
463  if (OAPV_FAILED(ret)) {
464  av_log(avctx, AV_LOG_ERROR, "oapve_encode() failed\n");
465  return AVERROR_EXTERNAL;
466  }
467 
468  /* store bitstream */
469  if (OAPV_SUCCEEDED(ret) && apv->stat.write > 0) {
470  uint8_t *data = apv->bitb.addr;
471  int size = apv->stat.write;
472 
473  // The encoder may return a "Raw bitstream" formatted AU, including au_size.
474  // Discard it as we only need the access_unit() structure.
475  if (size > 4 && AV_RB32(data) != APV_SIGNATURE) {
476  data += 4;
477  size -= 4;
478  }
479 
480  ret = ff_get_encode_buffer(avctx, avpkt, size, 0);
481  if (ret < 0)
482  return ret;
483 
484  memcpy(avpkt->data, data, size);
485  avpkt->pts = avpkt->dts = frame->pts;
486  avpkt->flags |= AV_PKT_FLAG_KEY;
487 
488  if (cdsc->param[FRM_IDX].qp)
490 
491  *got_packet = 1;
492  }
493 
494  return 0;
495 }
496 
497 /**
498  * Destroy the encoder and release all the allocated resources
499  *
500  * @param avctx codec context
501  * @return 0 on success, negative error code on failure
502  */
504 {
505  ApvEncContext *apv = avctx->priv_data;
506 
507  for (int i = 0; i < apv->ifrms.num_frms; i++) {
508  if (apv->ifrms.frm[i].imgb != NULL)
509  apv->ifrms.frm[i].imgb->release(apv->ifrms.frm[i].imgb);
510  apv->ifrms.frm[i].imgb = NULL;
511  }
512 
513  if (apv->mid) {
514  oapvm_rem_all(apv->mid);
515  }
516 
517  if (apv->id) {
518  oapve_delete(apv->id);
519  apv->id = NULL;
520  }
521 
522  if (apv->mid) {
523  oapvm_delete(apv->mid);
524  apv->mid = NULL;
525  }
526 
527  av_freep(&apv->bitb.addr); /* release bitstream buffer */
528 
529  return 0;
530 }
531 
532 #define OFFSET(x) offsetof(ApvEncContext, x)
533 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
534 
535 static const AVOption liboapv_options[] = {
536  { "preset", "Encoding preset for setting encoding speed (optimization level control)", OFFSET(preset_id), AV_OPT_TYPE_INT, { .i64 = OAPV_PRESET_DEFAULT }, OAPV_PRESET_FASTEST, OAPV_PRESET_PLACEBO, VE, .unit = "preset" },
537  { "fastest", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FASTEST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
538  { "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FAST }, INT_MIN, INT_MAX, VE, .unit = "preset" },
539  { "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_MEDIUM }, INT_MIN, INT_MAX, VE, .unit = "preset" },
540  { "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_SLOW }, INT_MIN, INT_MAX, VE, .unit = "preset" },
541  { "placebo", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_PLACEBO }, INT_MIN, INT_MAX, VE, .unit = "preset" },
542  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "preset" },
543 
544  { "qp", "Quantization parameter value for CQP rate control mode", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63, VE },
545  { "oapv-params", "Override the apv configuration using a :-separated list of key=value parameters", OFFSET(oapv_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
546  { NULL }
547 };
548 
549 static const AVClass liboapve_class = {
550  .class_name = "liboapv",
551  .item_name = av_default_item_name,
552  .option = liboapv_options,
553  .version = LIBAVUTIL_VERSION_INT,
554 };
555 
557  { "b", "0" }, // bitrate in terms of kilo-bits per second (support for bit-rates from a few hundred Mbps to a few Gbps for 2K, 4K and 8K resolution content)
558  { NULL },
559 };
560 
562  .p.name = "liboapv",
563  .p.long_name = NULL_IF_CONFIG_SMALL("liboapv APV"),
564  .p.type = AVMEDIA_TYPE_VIDEO,
565  .p.id = AV_CODEC_ID_APV,
566  .init = liboapve_init,
568  .close = liboapve_close,
569  .priv_data_size = sizeof(ApvEncContext),
570  .p.priv_class = &liboapve_class,
571  .defaults = liboapve_defaults,
572  .p.capabilities = AV_CODEC_CAP_OTHER_THREADS | AV_CODEC_CAP_DR1,
573  .p.wrapper_name = "liboapv",
574  .p.profiles = NULL_IF_CONFIG_SMALL(ff_apv_profiles),
580 };
get_color_format
static int get_color_format(enum AVPixelFormat pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format.
Definition: liboapvenc.c:97
liboapv_options
static const AVOption liboapv_options[]
Definition: liboapvenc.c:535
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:392
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
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
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:671
AV_PROFILE_APV_444_10
#define AV_PROFILE_APV_444_10
Definition: defs.h:202
validate_profile
static int validate_profile(AVCodecContext *avctx, int profile)
Definition: liboapvenc.c:197
ApvEncContext::stat
oapve_stat_t stat
Definition: liboapvenc.c:58
ApvEncContext
The structure stores all the states associated with the instance of APV encoder.
Definition: liboapvenc.c:51
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
av_cold
#define av_cold
Definition: attributes.h:119
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:664
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
get_min_profile
static int get_min_profile(enum AVPixelFormat pix_fmt)
Definition: liboapvenc.c:138
AVPacket::data
uint8_t * data
Definition: packet.h:603
AVOption
AVOption.
Definition: opt.h:429
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
data
const char data[16]
Definition: mxf.c:149
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
FFCodec
Definition: codec_internal.h:127
ApvEncContext::qp
int qp
Definition: liboapvenc.c:64
AVDictionary
Definition: dict.c:32
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
APV_SIGNATURE
#define APV_SIGNATURE
Definition: apv.h:23
ApvEncContext::cdsc
oapve_cdesc_t cdsc
Definition: liboapvenc.c:56
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:658
ApvEncContext::bitb
oapv_bitb_t bitb
Definition: liboapvenc.c:57
liboapve_class
static const AVClass liboapve_class
Definition: liboapvenc.c:549
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:563
apv_imgb_release
static int apv_imgb_release(oapv_imgb_t *imgb)
Definition: liboapvenc.c:69
ff_apv_profiles
const AVProfile ff_apv_profiles[]
Definition: profiles.c:212
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ApvEncContext::id
oapve_t id
Definition: liboapvenc.c:54
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:452
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1579
ff_encode_add_stats_side_data
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
Definition: encode.c:947
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:359
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:657
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
ApvEncContext::ifrms
oapv_frms_t ifrms
Definition: liboapvenc.c:60
intreadwrite.h
liboapve_defaults
static const FFCodecDefault liboapve_defaults[]
Definition: liboapvenc.c:556
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
AVDictionaryEntry::key
char * key
Definition: dict.h:91
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:109
MAX_BS_BUF
#define MAX_BS_BUF
Definition: liboapvenc.c:43
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:594
liboapve_init
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
Definition: liboapvenc.c:371
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1288
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:519
fail
#define fail
Definition: test.h:478
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:681
APV_CHROMA_FORMAT_4444
@ APV_CHROMA_FORMAT_4444
Definition: apv.h:50
apv_imgb_addref
static int apv_imgb_addref(oapv_imgb_t *imgb)
Definition: liboapvenc.c:81
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:116
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:493
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition: opt.h:290
apv.h
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
profiles.h
liboapve_close
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
Definition: liboapvenc.c:503
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:540
apv_imgb_create
static oapv_imgb_t * apv_imgb_create(AVCodecContext *avctx)
Definition: liboapvenc.c:215
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
apv_imgb_getref
static int apv_imgb_getref(oapv_imgb_t *imgb)
Definition: liboapvenc.c:87
ApvEncContext::oapv_params
AVDictionary * oapv_params
Definition: liboapvenc.c:66
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:547
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
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
codec_internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
AV_PROFILE_APV_4444_12
#define AV_PROFILE_APV_4444_12
Definition: defs.h:205
size
int size
Definition: twinvq_data.h:10344
VE
#define VE
Definition: liboapvenc.c:533
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
OFFSET
#define OFFSET(x)
Definition: liboapvenc.c:532
FRM_IDX
#define FRM_IDX
Definition: liboapvenc.c:45
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:592
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:609
AV_PROFILE_APV_400_10
#define AV_PROFILE_APV_400_10
Definition: defs.h:206
liboapve_encode
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
Definition: liboapvenc.c:445
APV_CHROMA_FORMAT_422
@ APV_CHROMA_FORMAT_422
Definition: apv.h:48
MAX_NUM_FRMS
#define MAX_NUM_FRMS
Definition: liboapvenc.c:44
av_malloc
#define av_malloc(s)
Definition: ops_asmgen.c:44
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
av_get_profile_name
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:418
AV_PROFILE_APV_422_10
#define AV_PROFILE_APV_422_10
Definition: defs.h:200
ApvEncContext::preset_id
int preset_id
Definition: liboapvenc.c:62
AV_PROFILE_APV_4444_10
#define AV_PROFILE_APV_4444_10
Definition: defs.h:204
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
profile
int profile
Definition: mxfenc.c:2299
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
AVCodecContext::height
int height
Definition: avcodec.h:604
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:643
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
avcodec.h
ff_liboapv_encoder
const FFCodec ff_liboapv_encoder
Definition: liboapvenc.c:561
ret
ret
Definition: filter_design.txt:187
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:332
pixfmt.h
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:81
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVCodecContext
main external API structure.
Definition: avcodec.h:443
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1636
AV_PROFILE_APV_444_12
#define AV_PROFILE_APV_444_12
Definition: defs.h:203
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
mem.h
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:73
APV_CHROMA_FORMAT_444
@ APV_CHROMA_FORMAT_444
Definition: apv.h:49
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
get_chroma_format_idc
static int get_chroma_format_idc(enum AVPixelFormat pix_fmt)
Definition: liboapvenc.c:119
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
imgutils.h
AV_PROFILE_APV_422_12
#define AV_PROFILE_APV_422_12
Definition: defs.h:201
APV_CHROMA_FORMAT_400
@ APV_CHROMA_FORMAT_400
Definition: apv.h:47
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVDictionaryEntry::value
char * value
Definition: dict.h:92
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:226
get_conf
static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
Populate the liboapv configuration from AVCodecContext and encoder options.
Definition: liboapvenc.c:278
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
ApvEncContext::mid
oapvm_t mid
Definition: liboapvenc.c:55
profile_is_compatible
static int profile_is_compatible(enum AVPixelFormat pix_fmt, int profile)
Definition: liboapvenc.c:160
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
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:3376