FFmpeg
Data Structures | Macros | Functions | Variables
libxvid.c File Reference
#include <stdio.h>
#include <string.h>
#include <xvid.h>
#include "libavutil/avassert.h"
#include "libavutil/file_open.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "mpegutils.h"
#include "packet_internal.h"

Go to the source code of this file.

Data Structures

struct  xvid_context
 Structure for the private Xvid context. More...
 
struct  xvid_ff_pass1
 Structure for the private first-pass plugin. More...
 

Macros

#define BUFFER_SIZE   1024
 Buffer management macros. More...
 
#define BUFFER_REMAINING(x)   (BUFFER_SIZE - strlen(x))
 
#define BUFFER_CAT(x)   (&((x)[strlen(x)]))
 
#define OFFSET(x)   offsetof(struct xvid_context, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static int xvid_encode_close (AVCodecContext *avctx)
 
static int xvid_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *picture, int *got_packet)
 
static int xvid_ff_2pass_create (xvid_plg_create_t *param, void **handle)
 Initialize the two-pass plugin and context. More...
 
static int xvid_ff_2pass_destroy (struct xvid_context *ref, xvid_plg_destroy_t *param)
 Destroy the two-pass plugin context. More...
 
static int xvid_ff_2pass_before (struct xvid_context *ref, xvid_plg_data_t *param)
 Enable fast encode mode during the first pass. More...
 
static int xvid_ff_2pass_after (struct xvid_context *ref, xvid_plg_data_t *param)
 Capture statistic data and write it during first pass. More...
 
static int xvid_ff_2pass (void *ref, int cmd, void *p1, void *p2)
 Dispatch function for our custom plugin. More...
 
static int xvid_strip_vol_header (AVCodecContext *avctx, AVPacket *pkt, unsigned int header_len, unsigned int frame_len)
 Routine to create a global VO/VOL header for MP4 container. More...
 
static void xvid_correct_framerate (AVCodecContext *avctx)
 Routine to correct a possibly erroneous framerate being fed to us. More...
 
static av_cold int xvid_encode_init (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass xvid_class
 
const FFCodec ff_libxvid_encoder
 

Detailed Description

Interface to xvidcore for MPEG-4 compliant encoding.

Author
Adam Thayer (krevn.nosp@m.ik@c.nosp@m.omcas.nosp@m.t.ne.nosp@m.t)

Definition in file libxvid.c.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   1024

Buffer management macros.

Definition at line 57 of file libxvid.c.

◆ BUFFER_REMAINING

#define BUFFER_REMAINING (   x)    (BUFFER_SIZE - strlen(x))

Definition at line 58 of file libxvid.c.

◆ BUFFER_CAT

#define BUFFER_CAT (   x)    (&((x)[strlen(x)]))

Definition at line 59 of file libxvid.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(struct xvid_context, x)

Definition at line 877 of file libxvid.c.

◆ VE

Definition at line 878 of file libxvid.c.

Function Documentation

◆ xvid_encode_close()

static av_cold int xvid_encode_close ( AVCodecContext avctx)
static

Definition at line 851 of file libxvid.c.

◆ xvid_encode_frame()

static int xvid_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame picture,
int *  got_packet 
)
static

Definition at line 730 of file libxvid.c.

Referenced by xvid_encode_init().

◆ xvid_ff_2pass_create()

static int xvid_ff_2pass_create ( xvid_plg_create_t *  param,
void **  handle 
)
static

Initialize the two-pass plugin and context.

Parameters
paramInput construction parameter structure
handlePrivate context handle
Returns
Returns XVID_ERR_xxxx on failure, or 0 on success.

Definition at line 120 of file libxvid.c.

Referenced by xvid_ff_2pass().

◆ xvid_ff_2pass_destroy()

static int xvid_ff_2pass_destroy ( struct xvid_context ref,
xvid_plg_destroy_t *  param 
)
static

Destroy the two-pass plugin context.

Parameters
refContext pointer for the plugin
paramDestroy context
Returns
Returns 0, success guaranteed

Definition at line 151 of file libxvid.c.

Referenced by xvid_ff_2pass().

◆ xvid_ff_2pass_before()

static int xvid_ff_2pass_before ( struct xvid_context ref,
xvid_plg_data_t *  param 
)
static

Enable fast encode mode during the first pass.

Parameters
refContext pointer for the plugin
paramFrame data
Returns
Returns 0, success guaranteed

Definition at line 168 of file libxvid.c.

Referenced by xvid_ff_2pass().

◆ xvid_ff_2pass_after()

static int xvid_ff_2pass_after ( struct xvid_context ref,
xvid_plg_data_t *  param 
)
static

Capture statistic data and write it during first pass.

Parameters
refContext pointer for the plugin
paramStatistic data
Returns
Returns XVID_ERR_xxxx on failure, or 0 on success

Definition at line 212 of file libxvid.c.

Referenced by xvid_ff_2pass().

◆ xvid_ff_2pass()

static int xvid_ff_2pass ( void *  ref,
int  cmd,
void *  p1,
void *  p2 
)
static

Dispatch function for our custom plugin.

This handles the dispatch for the Xvid plugin. It passes data on to other functions for actual processing.

Parameters
refContext pointer for the plugin
cmdThe task given for us to complete
p1First parameter (varies)
p2Second parameter (varies)
Returns
Returns XVID_ERR_xxxx on failure, or 0 on success

Definition at line 249 of file libxvid.c.

Referenced by xvid_encode_init().

◆ xvid_strip_vol_header()

static int xvid_strip_vol_header ( AVCodecContext avctx,
AVPacket pkt,
unsigned int  header_len,
unsigned int  frame_len 
)
static

Routine to create a global VO/VOL header for MP4 container.

What we do here is extract the header from the Xvid bitstream as it is encoded. We also strip the repeated headers from the bitstream when a global header is requested for MPEG-4 ISO compliance.

Parameters
avctxAVCodecContext pointer to context
framePointer to encoded frame data
header_lenLength of header to search
frame_lenLength of encoded frame data
Returns
Returns new length of frame data

Definition at line 281 of file libxvid.c.

Referenced by xvid_encode_frame().

◆ xvid_correct_framerate()

static void xvid_correct_framerate ( AVCodecContext avctx)
static

Routine to correct a possibly erroneous framerate being fed to us.

Xvid currently chokes on framerates where the ticks per frame is extremely large. This function works to correct problems in this area by estimating a new framerate and taking the simpler fraction of the two presented.

Parameters
avctxContext that contains the framerate to correct.

Definition at line 323 of file libxvid.c.

Referenced by xvid_encode_init().

◆ xvid_encode_init()

static av_cold int xvid_encode_init ( AVCodecContext avctx)
static

Definition at line 373 of file libxvid.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "lumi_aq", "Luminance masking AQ", OFFSET(lumi_aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "variance_aq", "Variance AQ", OFFSET(variance_aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "ssim", "Show SSIM information to stdout", OFFSET(ssim), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE, .unit = "ssim" },
{ "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "ssim" },
{ "avg", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "ssim" },
{ "frame", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, .unit = "ssim" },
{ "ssim_acc", "SSIM accuracy", OFFSET(ssim_acc), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, 4, VE },
{ "gmc", "use GMC", OFFSET(gmc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "me_quality", "Motion estimation quality", OFFSET(me_quality), AV_OPT_TYPE_INT, { .i64 = 4 }, 0, 6, VE },
{ "mpeg_quant", "Use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ NULL },
}

Definition at line 879 of file libxvid.c.

◆ xvid_class

const AVClass xvid_class
static
Initial value:
= {
.class_name = "libxvid",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 893 of file libxvid.c.

◆ ff_libxvid_encoder

const FFCodec ff_libxvid_encoder
Initial value:
= {
.p.name = "libxvid",
CODEC_LONG_NAME("libxvidcore MPEG-4 part 2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(struct xvid_context),
.p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
.color_ranges = AVCOL_RANGE_MPEG,
.p.priv_class = &xvid_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.wrapper_name = "libxvid",
}

Definition at line 900 of file libxvid.c.

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
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
xvid_encode_frame
static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *picture, int *got_packet)
Definition: libxvid.c:730
xvid_context
Structure for the private Xvid context.
Definition: libxvid.c:65
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
OFFSET
#define OFFSET(x)
Definition: libxvid.c:877
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
options
static const AVOption options[]
Definition: libxvid.c:879
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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
xvid_class
static const AVClass xvid_class
Definition: libxvid.c:893
xvid_encode_close
static int xvid_encode_close(AVCodecContext *avctx)
Definition: libxvid.c:851
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:700
VE
#define VE
Definition: libxvid.c:878
xvid_encode_init
static av_cold int xvid_encode_init(AVCodecContext *avctx)
Definition: libxvid.c:373
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299