FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
libaomenc.c File Reference

AV1 encoder support via libaom. More...

#include <aom/aom_encoder.h>
#include <aom/aomcx.h>
#include "libavutil/avassert.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "av1.h"
#include "avcodec.h"
#include "internal.h"
#include "profiles.h"

Go to the source code of this file.

Data Structures

struct  FrameListData
 Portion of struct vpx_codec_cx_pkt from vpx_encoder.h. More...
 
struct  AOMContext
 

Macros

#define AOM_DISABLE_CTRL_TYPECHECKS   1
 
#define OFFSET(x)   offsetof(AOMContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static av_cold void log_encoder_error (AVCodecContext *avctx, const char *desc)
 
static av_cold void dump_enc_cfg (AVCodecContext *avctx, const struct aom_codec_enc_cfg *cfg)
 
static void coded_frame_add (void *list, struct FrameListData *cx_frame)
 
static av_cold void free_coded_frame (struct FrameListData *cx_frame)
 
static av_cold void free_frame_list (struct FrameListData *list)
 
static av_cold int codecctl_int (AVCodecContext *avctx, enum aome_enc_control_id id, int val)
 
static av_cold int aom_free (AVCodecContext *avctx)
 
static int set_pix_fmt (AVCodecContext *avctx, aom_codec_caps_t codec_caps, struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *flags, aom_img_fmt_t *img_fmt)
 
static void set_color_range (AVCodecContext *avctx)
 
static int count_uniform_tiling (int dim, int sb_size, int tiles_log2)
 
static int choose_tiling (AVCodecContext *avctx, struct aom_codec_enc_cfg *enccfg)
 
static av_cold int aom_init (AVCodecContext *avctx, const struct aom_codec_iface *iface)
 
static void cx_pktcpy (AOMContext *ctx, struct FrameListData *dst, const struct aom_codec_cx_pkt *src)
 
static int storeframe (AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt)
 Store coded frame information in format suitable for return from encode2(). More...
 
static int queue_frames (AVCodecContext *avctx, AVPacket *pkt_out)
 Queue multiple output frames from the encoder, returning the front-most. More...
 
static int aom_encode (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static av_cold void av1_init_static (AVCodec *codec)
 
static av_cold int av1_init (AVCodecContext *avctx)
 

Variables

static const char *const ctlidstr []
 
static enum AVPixelFormat av1_pix_fmts []
 
static enum AVPixelFormat av1_pix_fmts_highbd []
 
static const AVOption options []
 
static const AVCodecDefault defaults []
 
static const AVClass class_aom
 
AVCodec ff_libaom_av1_encoder
 

Detailed Description

AV1 encoder support via libaom.

Definition in file libaomenc.c.

Macro Definition Documentation

#define AOM_DISABLE_CTRL_TYPECHECKS   1

Definition at line 26 of file libaomenc.c.

#define OFFSET (   x)    offsetof(AOMContext, x)

Definition at line 970 of file libaomenc.c.

Definition at line 971 of file libaomenc.c.

Function Documentation

static av_cold void log_encoder_error ( AVCodecContext avctx,
const char *  desc 
)
static

Definition at line 98 of file libaomenc.c.

Referenced by aom_encode(), aom_init(), and codecctl_int().

static av_cold void dump_enc_cfg ( AVCodecContext avctx,
const struct aom_codec_enc_cfg *  cfg 
)
static

Definition at line 109 of file libaomenc.c.

Referenced by aom_init().

static void coded_frame_add ( void list,
struct FrameListData cx_frame 
)
static

Definition at line 167 of file libaomenc.c.

Referenced by queue_frames().

static av_cold void free_coded_frame ( struct FrameListData cx_frame)
static

Definition at line 177 of file libaomenc.c.

Referenced by free_frame_list(), and queue_frames().

static av_cold void free_frame_list ( struct FrameListData list)
static

Definition at line 183 of file libaomenc.c.

Referenced by aom_free().

static av_cold int codecctl_int ( AVCodecContext avctx,
enum aome_enc_control_id  id,
int  val 
)
static

Definition at line 194 of file libaomenc.c.

Referenced by aom_init(), and set_color_range().

static av_cold int aom_free ( AVCodecContext avctx)
static

Definition at line 216 of file libaomenc.c.

static int set_pix_fmt ( AVCodecContext avctx,
aom_codec_caps_t  codec_caps,
struct aom_codec_enc_cfg *  enccfg,
aom_codec_flags_t *  flags,
aom_img_fmt_t *  img_fmt 
)
static

Definition at line 228 of file libaomenc.c.

Referenced by aom_init().

static void set_color_range ( AVCodecContext avctx)
static

Definition at line 289 of file libaomenc.c.

Referenced by aom_init(), and vpx_init().

static int count_uniform_tiling ( int  dim,
int  sb_size,
int  tiles_log2 
)
static

Definition at line 305 of file libaomenc.c.

Referenced by choose_tiling().

static int choose_tiling ( AVCodecContext avctx,
struct aom_codec_enc_cfg *  enccfg 
)
static

Definition at line 313 of file libaomenc.c.

Referenced by aom_init().

static av_cold int aom_init ( AVCodecContext avctx,
const struct aom_codec_iface *  iface 
)
static

Definition at line 468 of file libaomenc.c.

Referenced by av1_init().

static void cx_pktcpy ( AOMContext ctx,
struct FrameListData dst,
const struct aom_codec_cx_pkt *  src 
)
inlinestatic

Definition at line 697 of file libaomenc.c.

Referenced by queue_frames().

static int storeframe ( AVCodecContext avctx,
struct FrameListData cx_frame,
AVPacket pkt 
)
static

Store coded frame information in format suitable for return from encode2().

Write information from cx_frame to pkt

Returns
packet data size on success
a negative AVERROR on error

Definition at line 726 of file libaomenc.c.

Referenced by queue_frames().

static int queue_frames ( AVCodecContext avctx,
AVPacket pkt_out 
)
static

Queue multiple output frames from the encoder, returning the front-most.

In cases where aom_codec_get_cx_data() returns more than 1 frame append the frame queue. Return the head frame if available.

Returns
Stored frame size
AVERROR(EINVAL) on output size error
AVERROR(ENOMEM) on coded frame queue data allocation error

Definition at line 788 of file libaomenc.c.

Referenced by aom_encode().

static int aom_encode ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int got_packet 
)
static

Definition at line 880 of file libaomenc.c.

static av_cold void av1_init_static ( AVCodec codec)
static

Definition at line 956 of file libaomenc.c.

static av_cold int av1_init ( AVCodecContext avctx)
static

Definition at line 965 of file libaomenc.c.

Variable Documentation

const char* const ctlidstr[]
static
Initial value:
= {
[AOME_SET_CPUUSED] = "AOME_SET_CPUUSED",
[AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
[AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
[AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
[AV1E_SET_COLOR_RANGE] = "AV1E_SET_COLOR_RANGE",
[AV1E_SET_COLOR_PRIMARIES] = "AV1E_SET_COLOR_PRIMARIES",
[AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
[AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
[AV1E_SET_SUPERBLOCK_SIZE] = "AV1E_SET_SUPERBLOCK_SIZE",
[AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
[AV1E_SET_TILE_ROWS] = "AV1E_SET_TILE_ROWS",
}

Definition at line 84 of file libaomenc.c.

Referenced by codecctl_int().

enum AVPixelFormat av1_pix_fmts[]
static
Initial value:
= {
}
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66

Definition at line 936 of file libaomenc.c.

Referenced by av1_init_static().

enum AVPixelFormat av1_pix_fmts_highbd[]
static
Initial value:
= {
}
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:383
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:384
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:382
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:379
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:386
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66

Definition at line 943 of file libaomenc.c.

Referenced by av1_init_static().

const AVOption options[]
static
Initial value:
= {
{ "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VE},
{ "auto-alt-ref", "Enable use of alternate reference "
"frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
{ "lag-in-frames", "Number of frames to look ahead at for "
"alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
{ "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"},
{ "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
{ "crf", "Select the quality for constant quality mode", 0x42, AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE },
{ "static-thresh", "A change threshold on blocks below which they will be skipped by the encoder", OFFSET(static_thresh), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "drop-threshold", "Frame drop threshold", 0x42, AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE },
{ "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE},
{ "tiles", "Tile columns x rows", OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, VE },
{ "tile-columns", "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
{ "tile-rows", "Log2 of number of tile rows to use", OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
{ NULL }
}
#define OFFSET(x)
Definition: libaomenc.c:970
#define NULL
Definition: coverity.c:32
#define VE
Definition: libaomenc.c:971
offset must point to two consecutive integers
Definition: opt.h:233

Definition at line 972 of file libaomenc.c.

const AVCodecDefault defaults[]
static
Initial value:
= {
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "g", "-1" },
{ "keyint_min", "-1" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 990 of file libaomenc.c.

const AVClass class_aom
static
Initial value:
= {
.class_name = "libaom-av1 encoder",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVOption options[]
Definition: libaomenc.c:972

Definition at line 998 of file libaomenc.c.

AVCodec ff_libaom_av1_encoder
Initial value:
= {
.name = "libaom-av1",
.long_name = NULL_IF_CONFIG_SMALL("libaom AV1"),
.priv_data_size = sizeof(AOMContext),
.encode2 = aom_encode,
.close = aom_free,
.priv_class = &class_aom,
.defaults = defaults,
.init_static_data = av1_init_static,
.wrapper_name = "libaom",
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1016
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:1036
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:993
static av_cold void av1_init_static(AVCodec *codec)
Definition: libaomenc.c:956
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static const AVClass class_aom
Definition: libaomenc.c:998
const AVProfile ff_av1_profiles[]
Definition: profiles.c:142
static av_cold int av1_init(AVCodecContext *avctx)
Definition: libaomenc.c:965
static const AVProfile profiles[]
static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: libaomenc.c:880
static const AVCodecDefault defaults[]
Definition: libaomenc.c:990
static av_cold int aom_free(AVCodecContext *avctx)
Definition: libaomenc.c:216

Definition at line 1005 of file libaomenc.c.