Go to the documentation of this file.
27 #include <oapv/oapv.h>
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)
71 int refcnt = --imgb->refcnt;
73 for (
int i = 0;
i < imgb->np;
i++)
83 int refcnt = ++imgb->refcnt;
99 int cf = OAPV_CF_UNKNOWN;
103 cf = OAPV_CF_YCBCR400;
106 cf = OAPV_CF_YCBCR422;
109 cf = OAPV_CF_YCBCR422;
112 cf = OAPV_CF_YCBCR444;
115 cf = OAPV_CF_YCBCR444;
118 cf = OAPV_CF_YCBCR4444;
121 cf = OAPV_CF_YCBCR4444;
235 "Profile %s (%d) is incompatible with pixel format %s; minimum compatible profile is %s (%d)\n",
236 profile_name ? profile_name :
"unknown",
profile,
238 minimum_name ? minimum_name :
"unknown", minimum);
259 input_depth =
desc->comp[0].depth;
261 cs = OAPV_CS_SET(cfmt, input_depth, AV_HAVE_BIGENDIAN);
263 imgb->np =
desc->nb_components;
265 for (
int i = 0;
i < imgb->np;
i++) {
266 imgb->w[
i] = avctx->
width >> ((
i == 1 ||
i == 2) ?
desc->log2_chroma_w : 0);
268 imgb->aw[
i] =
FFALIGN(imgb->w[
i], OAPV_MB_W);
269 imgb->ah[
i] =
FFALIGN(imgb->h[
i], OAPV_MB_H);
270 imgb->s[
i] = imgb->aw[
i] * OAPV_CS_GET_BYTE_DEPTH(cs);
272 imgb->bsize[
i] = imgb->e[
i] = imgb->s[
i] * imgb->ah[
i];
274 if (imgb->a[
i] ==
NULL)
288 for (
int i = 0;
i < imgb->np;
i++)
313 int ret = oapve_param_default(&cdsc->param[
FRM_IDX]);
314 if (OAPV_FAILED(
ret)) {
320 if (avctx->
width > 0)
344 av_log(avctx,
AV_LOG_ERROR,
"bit_rate and rc_max_rate > %d000 is not supported\n", INT_MAX);
348 if (cdsc->param[
FRM_IDX].bitrate) {
350 av_log(avctx,
AV_LOG_WARNING,
"You cannot set both the bitrate and the QP parameter at the same time.\n"
351 "If the bitrate is set, the rate control type is set to ABR, which means that the QP value is ignored.\n");
353 cdsc->param[
FRM_IDX].rc_type = OAPV_RC_ABR;
360 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
365 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
370 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
375 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
407 oapve_cdesc_t *cdsc = &apv->
cdsc;
408 unsigned char *bs_buf;
413 if (bs_buf ==
NULL) {
417 apv->
bitb.addr = bs_buf;
428 apv->
id = oapve_create(cdsc, &
ret);
431 if (
ret == OAPV_ERR_INVALID_LEVEL)
437 apv->
mid = oapvm_create(&
ret);
443 int value = OAPV_CFG_VAL_AU_BS_FMT_NONE;
445 ret = oapve_config(apv->
id, OAPV_CFG_SET_AU_BS_FMT, &
value, &
size);
446 if (OAPV_FAILED(
ret)) {
447 av_log(avctx,
AV_LOG_ERROR,
"Failed to set config for using encoder output format\n");
454 apv->
ifrms.num_frms++;
457 if (cdsc->param[
FRM_IDX].color_description_present_flag) {
482 const oapve_cdesc_t *cdsc = &apv->
cdsc;
484 oapv_imgb_t *imgb = frm->imgb;
495 imgb->ts[0] =
frame->pts;
498 frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
501 if (OAPV_FAILED(
ret)) {
507 if (OAPV_SUCCEEDED(
ret) && apv->
stat.write > 0) {
545 for (
int i = 0;
i < apv->
ifrms.num_frms;
i++) {
547 apv->
ifrms.frm[
i].imgb->release(apv->
ifrms.frm[
i].imgb);
552 oapvm_rem_all(apv->
mid);
556 oapve_delete(apv->
id);
561 oapvm_delete(apv->
mid);
570 #define OFFSET(x) offsetof(ApvEncContext, x)
571 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
585 {
"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" },
586 {
"fastest",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FASTEST }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
588 {
"medium",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_MEDIUM }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
590 {
"placebo",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_PLACEBO }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
591 {
"default",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_DEFAULT }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
593 {
"qp",
"Quantization parameter value for CQP rate control mode",
OFFSET(qp),
AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63,
VE },
594 {
"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 },
622 .p.wrapper_name =
"liboapv",
static int get_color_format(enum AVPixelFormat pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into APV pre-defined color format.
static const AVOption liboapv_options[]
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
enum AVColorSpace colorspace
YUV colorspace type.
#define AV_PROFILE_APV_444_10
static int validate_profile(AVCodecContext *avctx, int profile)
The structure stores all the states associated with the instance of APV encoder.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
static int get_min_profile(enum AVPixelFormat pix_fmt)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static const AVClass liboapve_class
static int apv_imgb_release(oapv_imgb_t *imgb)
const AVProfile ff_apv_profiles[]
AVCodec p
The public AVCodec.
const struct AVCodec * codec
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
#define FF_CODEC_ENCODE_CB(func)
#define AV_PIX_FMT_YUV444P10
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PROFILE_UNKNOWN
static const FFCodecDefault liboapve_defaults[]
static enum AVPixelFormat pix_fmt
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_PIX_FMT_YUVA444P12
static av_cold int liboapve_init(AVCodecContext *avctx)
Initialize APV codec Create an encoder instance and allocate all the needed resources.
int64_t rc_max_rate
maximum bitrate
#define AV_PIX_FMT_GRAY10
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static int apv_imgb_addref(oapv_imgb_t *imgb)
int64_t bit_rate
the average bitrate
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static av_cold int liboapve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
#define AV_PIX_FMT_YUV422P10
static oapv_imgb_t * apv_imgb_create(AVCodecContext *avctx)
@ AVCOL_RANGE_UNSPECIFIED
static int apv_imgb_getref(oapv_imgb_t *imgb)
AVDictionary * oapv_params
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define i(width, name, range_min, range_max)
#define AV_PIX_FMT_YUV422P12
#define AV_PROFILE_APV_4444_12
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
#define AV_PIX_FMT_YUV444P12
static enum AVPixelFormat supported_pixel_formats[]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AV_PIX_FMT_YUVA444P10
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
#define AV_PROFILE_APV_400_10
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
#define AV_PROFILE_APV_422_10
#define AV_PROFILE_APV_4444_10
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
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
const FFCodec ff_liboapv_encoder
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_PROFILE_APV_444_12
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int get_chroma_format_idc(enum AVPixelFormat pix_fmt)
This structure stores compressed data.
int width
picture width / height.
#define AV_PROFILE_APV_422_12
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
static int get_conf(AVCodecContext *avctx, oapve_cdesc_t *cdsc)
Populate the liboapv configuration from AVCodecContext and encoder options.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static int profile_is_compatible(enum AVPixelFormat pix_fmt, int profile)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
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.