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

VP8 encoder support via libvpx. More...

#include <vpx/vpx_encoder.h>
#include <vpx/vp8cx.h>
#include "avcodec.h"
#include "internal.h"
#include "libavutil/avassert.h"
#include "libvpx.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.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  VP8Context
 

Macros

#define VPX_DISABLE_CTRL_TYPECHECKS   1
 
#define VPX_CODEC_DISABLE_COMPAT   1
 
#define VP8F_ERROR_RESILIENT   0x00000001
 Enable measures appropriate for streaming over lossy links.
 
#define VP8F_AUTO_ALT_REF   0x00000002
 Enable automatic alternate reference frame generation.
 
#define OFFSET(x)   offsetof(VP8Context, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define VPX_ERROR_RESILIENT_DEFAULT   1
 
#define VPX_ERROR_RESILIENT_PARTITIONS   2
 
#define COMMON_OPTIONS
 
#define LEGACY_OPTIONS
 

Functions

static av_cold void log_encoder_error (AVCodecContext *avctx, const char *desc)
 
static av_cold void dump_enc_cfg (AVCodecContext *avctx, const struct vpx_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 vp8e_enc_control_id id, int val)
 
static av_cold int vp8_free (AVCodecContext *avctx)
 
static av_cold int vpx_init (AVCodecContext *avctx, const struct vpx_codec_iface *iface)
 
static void cx_pktcpy (struct FrameListData *dst, const struct vpx_codec_cx_pkt *src, const struct vpx_codec_cx_pkt *src_alpha, VP8Context *ctx)
 
static int storeframe (AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt, AVFrame *coded_frame)
 Store coded frame information in format suitable for return from encode2().
 
static int queue_frames (AVCodecContext *avctx, AVPacket *pkt_out, AVFrame *coded_frame)
 Queue multiple output frames from the encoder, returning the front-most.
 
static int vp8_encode (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 

Variables

static const char *const ctlidstr []
 String mappings for enum vp8e_enc_control_id.
 
static const AVCodecDefault defaults []
 

Detailed Description

VP8 encoder support via libvpx.

Definition in file libvpxenc.c.

Macro Definition Documentation

#define VPX_DISABLE_CTRL_TYPECHECKS   1

Definition at line 26 of file libvpxenc.c.

#define VPX_CODEC_DISABLE_COMPAT   1

Definition at line 27 of file libvpxenc.c.

#define VP8F_ERROR_RESILIENT   0x00000001

Enable measures appropriate for streaming over lossy links.

Definition at line 80 of file libvpxenc.c.

Referenced by vpx_init().

#define VP8F_AUTO_ALT_REF   0x00000002

Enable automatic alternate reference frame generation.

Definition at line 81 of file libvpxenc.c.

Referenced by vpx_init().

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

Definition at line 764 of file libvpxenc.c.

Definition at line 765 of file libvpxenc.c.

#define VPX_ERROR_RESILIENT_DEFAULT   1

Definition at line 768 of file libvpxenc.c.

#define VPX_ERROR_RESILIENT_PARTITIONS   2

Definition at line 769 of file libvpxenc.c.

#define COMMON_OPTIONS
Value:
{ "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
{ "auto-alt-ref", "Enable use of alternate reference " \
"frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE}, \
{ "lag-in-frames", "Number of frames to look ahead for " \
"alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
{ "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
{ "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
{ "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "arnr_type"}, \
{ "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "arnr_type" }, \
{ "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "arnr_type" }, \
{ "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "arnr_type" }, \
{ "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
{ "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, \
{ "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, \
{ "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, "quality"}, \
{ "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, \
{ "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
{ "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, \
{ "partitions", "The frame partitions are independently decodable " \
"by the bool decoder, meaning that partitions can be decoded even " \
"though earlier partitions have been lost. Note that intra predicition" \
" is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \
{ "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \

Definition at line 772 of file libvpxenc.c.

#define LEGACY_OPTIONS
Value:
{"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
{"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
{"vp8flags", "", offsetof(VP8Context, flags), FF_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, "flags"}, \
{"error_resilient", "enable error resilience", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, \
{"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, "flags"}, \
{"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
{"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
{"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
{"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \

Definition at line 797 of file libvpxenc.c.

Function Documentation

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

Definition at line 131 of file libvpxenc.c.

Referenced by codecctl_int(), vp8_encode(), and vpx_init().

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

Definition at line 142 of file libvpxenc.c.

Referenced by vpx_init().

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

Definition at line 197 of file libvpxenc.c.

Referenced by queue_frames().

static av_cold void free_coded_frame ( struct FrameListData cx_frame)
static

Definition at line 207 of file libvpxenc.c.

Referenced by free_frame_list(), and queue_frames().

static av_cold void free_frame_list ( struct FrameListData list)
static

Definition at line 215 of file libvpxenc.c.

Referenced by vp8_free().

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

Definition at line 226 of file libvpxenc.c.

Referenced by vpx_init().

static av_cold int vp8_free ( AVCodecContext avctx)
static

Definition at line 247 of file libvpxenc.c.

Referenced by vpx_init().

static av_cold int vpx_init ( AVCodecContext avctx,
const struct vpx_codec_iface *  iface 
)
static

Definition at line 261 of file libvpxenc.c.

static void cx_pktcpy ( struct FrameListData dst,
const struct vpx_codec_cx_pkt *  src,
const struct vpx_codec_cx_pkt *  src_alpha,
VP8Context ctx 
)
inlinestatic

Definition at line 486 of file libvpxenc.c.

Referenced by queue_frames().

static int storeframe ( AVCodecContext avctx,
struct FrameListData cx_frame,
AVPacket pkt,
AVFrame coded_frame 
)
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 529 of file libvpxenc.c.

Referenced by queue_frames().

static int queue_frames ( AVCodecContext avctx,
AVPacket pkt_out,
AVFrame coded_frame 
)
static

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

In cases where vpx_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 584 of file libvpxenc.c.

Referenced by vp8_encode().

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

Definition at line 687 of file libvpxenc.c.

Variable Documentation

const char* const ctlidstr[]
static
Initial value:
= {
[VP8E_UPD_ENTROPY] = "VP8E_UPD_ENTROPY",
[VP8E_UPD_REFERENCE] = "VP8E_UPD_REFERENCE",
[VP8E_USE_REFERENCE] = "VP8E_USE_REFERENCE",
[VP8E_SET_ROI_MAP] = "VP8E_SET_ROI_MAP",
[VP8E_SET_ACTIVEMAP] = "VP8E_SET_ACTIVEMAP",
[VP8E_SET_SCALEMODE] = "VP8E_SET_SCALEMODE",
[VP8E_SET_CPUUSED] = "VP8E_SET_CPUUSED",
[VP8E_SET_ENABLEAUTOALTREF] = "VP8E_SET_ENABLEAUTOALTREF",
[VP8E_SET_NOISE_SENSITIVITY] = "VP8E_SET_NOISE_SENSITIVITY",
[VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS",
[VP8E_SET_STATIC_THRESHOLD] = "VP8E_SET_STATIC_THRESHOLD",
[VP8E_SET_TOKEN_PARTITIONS] = "VP8E_SET_TOKEN_PARTITIONS",
[VP8E_GET_LAST_QUANTIZER] = "VP8E_GET_LAST_QUANTIZER",
[VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES",
[VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH",
[VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE",
[VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL",
[VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
}

String mappings for enum vp8e_enc_control_id.

Definition at line 103 of file libvpxenc.c.

Referenced by codecctl_int().

const AVCodecDefault defaults[]
static
Initial value:
= {
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "g", "-1" },
{ "keyint_min", "-1" },
{ NULL },
}

Definition at line 836 of file libvpxenc.c.