Go to the documentation of this file.
27 #include <oapv/oapv.h>
44 #define MAX_BS_BUF (128 * 1024 * 1024)
45 #define MAX_NUM_FRMS (1) // supports only 1-frame in an access unit
46 #define FRM_IDX (0) // supports only 1-frame in an access unit
47 #define MAX_NUM_CC (OAPV_MAX_CC) // Max number of color componets (upto 4:4:4:4)
74 int refcnt = --imgb->refcnt;
76 for (
int i = 0;
i < imgb->np;
i++)
86 int refcnt = ++imgb->refcnt;
102 int cf = OAPV_CF_UNKNOWN;
106 cf = OAPV_CF_YCBCR422;
109 cf = OAPV_CF_YCBCR444;
132 input_depth =
desc->comp[0].depth;
134 cs = OAPV_CS_SET(cfmt, input_depth, AV_HAVE_BIGENDIAN);
136 imgb->np =
desc->nb_components;
138 for (
int i = 0;
i < imgb->np;
i++) {
139 imgb->w[
i] = avctx->
width >> ((
i == 1 ||
i == 2) ?
desc->log2_chroma_w : 0);
141 imgb->aw[
i] =
FFALIGN(imgb->w[
i], OAPV_MB_W);
142 imgb->ah[
i] =
FFALIGN(imgb->h[
i], OAPV_MB_H);
143 imgb->s[
i] = imgb->aw[
i] * OAPV_CS_GET_BYTE_DEPTH(cs);
145 imgb->bsize[
i] = imgb->e[
i] = imgb->s[
i] * imgb->ah[
i];
147 if (imgb->a[
i] ==
NULL)
161 for (
int i = 0;
i < imgb->np;
i++)
196 int ret = oapve_param_default(&cdsc->param[
FRM_IDX]);
197 if (OAPV_FAILED(
ret)) {
203 if (avctx->
width > 0)
220 av_log(avctx,
AV_LOG_ERROR,
"bit_rate and rc_max_rate > %d000 is not supported\n", INT_MAX);
224 if (cdsc->param[
FRM_IDX].bitrate) {
226 av_log(avctx,
AV_LOG_WARNING,
"You cannot set both the bitrate and the QP parameter at the same time.\n"
227 "If the bitrate is set, the rate control type is set to ABR, which means that the QP value is ignored.\n");
229 cdsc->param[
FRM_IDX].rc_type = OAPV_RC_ABR;
236 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
241 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
246 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
251 cdsc->param[
FRM_IDX].color_description_present_flag = 1;
277 oapve_cdesc_t *cdsc = &apv->
cdsc;
278 unsigned char *bs_buf;
283 if (bs_buf ==
NULL) {
287 apv->
bitb.addr = bs_buf;
298 apv->
id = oapve_create(cdsc, &
ret);
301 if (
ret == OAPV_ERR_INVALID_LEVEL)
307 apv->
mid = oapvm_create(&
ret);
316 apv->
ifrms.num_frms++;
319 if (cdsc->param[
FRM_IDX].color_description_present_flag) {
344 const oapve_cdesc_t *cdsc = &apv->
cdsc;
346 oapv_imgb_t *imgb = frm->imgb;
357 imgb->ts[0] =
frame->pts;
360 frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
363 if (OAPV_FAILED(
ret)) {
369 if (OAPV_SUCCEEDED(
ret) && apv->
stat.write > 0) {
409 apv->
ifrms.frm[
i].imgb->release(apv->
ifrms.frm[
i].imgb);
414 oapvm_rem_all(apv->
mid);
418 oapve_delete(apv->
id);
423 oapvm_delete(apv->
mid);
432 #define OFFSET(x) offsetof(ApvEncContext, x)
433 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
442 {
"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" },
443 {
"fastest",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_FASTEST }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
445 {
"medium",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_MEDIUM }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
447 {
"placebo",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_PLACEBO }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
448 {
"default",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = OAPV_PRESET_DEFAULT }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
450 {
"qp",
"Quantization parameter value for CQP rate control mode",
OFFSET(qp),
AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 63,
VE },
451 {
"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 },
479 .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.
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.
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#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.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
#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.
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.
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 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.
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
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 AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into APV packet.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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 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...
This structure stores compressed data.
int width
picture width / height.
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
#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)
The function returns a pointer to the object of the oapve_cdesc_t type.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.