FFmpeg
Loading...
Searching...
No Matches
libx264.c File Reference
#include "config_components.h"
#include "libavutil/buffer.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/stereo3d.h"
#include "libavutil/time.h"
#include "libavutil/video_hint.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "internal.h"
#include "packet_internal.h"
#include "atsc_a53.h"
#include "sei.h"
#include "golomb.h"
#include <x264.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  X264Opaque
 
struct  X264Context
 

Macros

#define MB_SIZE   16
 
#define MB_LSIZE   4
 
#define MB_FLOOR(x)
 
#define MB_CEIL(x)
 
#define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_)
 
#define PARSE_X264_OPT(name, var)
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define VER   VE | AV_OPT_FLAG_RUNTIME_PARAM
 

Functions

static void X264_log (void *p, int level, const char *fmt, va_list args)
 
static void opaque_uninit (X264Opaque *o)
 
static int encode_nals (AVCodecContext *ctx, AVPacket *pkt, const x264_nal_t *nals, int nnal)
 
static void reconfig_encoder (AVCodecContext *ctx)
 
static void reconfig_encoder_from_frame (AVCodecContext *ctx, const AVFrame *frame)
 
static void free_picture (x264_picture_t *pic)
 
static enum AVPixelFormat csp_to_pixfmt (int csp)
 
static void av_always_inline mbinfo_compute_changed_coords (const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
 
static void av_always_inline mbinfo_compute_constant_coords (const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
 
static int setup_mb_info (AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const AVVideoHint *info)
 
static int setup_roi (AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const uint8_t *data, size_t size)
 
static int setup_frame (AVCodecContext *ctx, const AVFrame *frame, x264_picture_t **ppic)
 
static int X264_frame (AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static void X264_flush (AVCodecContext *avctx)
 
static av_cold int X264_reconf (AVCodecContext *avctx, AVDictionary **dict)
 
static av_cold int X264_close (AVCodecContext *avctx)
 
static int parse_opts (AVCodecContext *avctx, const char *opt, const char *param)
 
static int convert_pix_fmt (enum AVPixelFormat pix_fmt)
 
static int save_sei (AVCodecContext *avctx, x264_nal_t *nal)
 
static int set_extradata (AVCodecContext *avctx)
 
static void handle_side_data (AVCodecContext *avctx, x264_param_t *params)
 
static av_cold int X264_init (AVCodecContext *avctx)
 

Variables

static enum AVPixelFormat pix_fmts_8bit []
 
static enum AVPixelFormat pix_fmts_9bit []
 
static enum AVPixelFormat pix_fmts_10bit []
 
static enum AVPixelFormat pix_fmts_all []
 
static const AVOption options []
 
static const FFCodecDefault x264_defaults []
 

Macro Definition Documentation

◆ MB_SIZE

#define MB_SIZE   16

Definition at line 51 of file libx264.c.

◆ MB_LSIZE

#define MB_LSIZE   4

Definition at line 52 of file libx264.c.

◆ MB_FLOOR

#define MB_FLOOR ( x)
Value:
((x) >> (MB_LSIZE))
#define MB_LSIZE
Definition libx264.c:52

Definition at line 53 of file libx264.c.

Referenced by mbinfo_compute_changed_coords(), and mbinfo_compute_constant_coords().

◆ MB_CEIL

#define MB_CEIL ( x)
Value:
MB_FLOOR((x) + (MB_SIZE - 1))
#define MB_SIZE
Definition cinepakenc.c:54
#define MB_FLOOR(x)
Definition libx264.c:53

Definition at line 54 of file libx264.c.

Referenced by mbinfo_compute_changed_coords(), and mbinfo_compute_constant_coords().

◆ COMPUTE_MBINFO

#define COMPUTE_MBINFO ( mbinfo_filler_,
mbinfo_marker_,
compute_coords_fn_ )
Value:
memset(mbinfo, mbinfo_filler_, sizeof(*mbinfo) * mb_width * mb_height); \
\
for (int i = 0; i < nb_rects; i++) { \
int min_x, max_x, min_y, max_y; \
\
compute_coords_fn_(mbinfo_rects, &min_x, &max_x, &min_y, &max_y); \
for (int mb_y = min_y; mb_y < max_y; ++mb_y) { \
memset(mbinfo + mb_y * mb_width + min_x, mbinfo_marker_, max_x - min_x); \
} \
\
mbinfo_rects++; \
} \
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63

Referenced by setup_mb_info().

◆ PARSE_X264_OPT

#define PARSE_X264_OPT ( name,
var )
Value:
if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
return AVERROR(EINVAL);\
}
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * name
Definition qsvenc.c:142

Definition at line 1005 of file libx264.c.

Referenced by X264_init().

◆ OFFSET

#define OFFSET ( x)
Value:
offsetof(X264Context, x)

Definition at line 1516 of file libx264.c.

◆ VE

Definition at line 1517 of file libx264.c.

◆ VER

#define VER   VE | AV_OPT_FLAG_RUNTIME_PARAM

Definition at line 1518 of file libx264.c.

Function Documentation

◆ X264_log()

static void X264_log ( void * p,
int level,
const char * fmt,
va_list args )
static

Definition at line 131 of file libx264.c.

Referenced by X264_init().

◆ opaque_uninit()

static void opaque_uninit ( X264Opaque * o)
static

Definition at line 146 of file libx264.c.

Referenced by setup_frame(), X264_close(), X264_flush(), and X264_frame().

◆ encode_nals()

static int encode_nals ( AVCodecContext * ctx,
AVPacket * pkt,
const x264_nal_t * nals,
int nnal )
static

Definition at line 152 of file libx264.c.

Referenced by X264_frame().

◆ reconfig_encoder()

static void reconfig_encoder ( AVCodecContext * ctx)
static

Definition at line 195 of file libx264.c.

Referenced by reconfig_encoder_from_frame(), and X264_reconf().

◆ reconfig_encoder_from_frame()

static void reconfig_encoder_from_frame ( AVCodecContext * ctx,
const AVFrame * frame )
static

Definition at line 242 of file libx264.c.

Referenced by setup_frame().

◆ free_picture()

static void free_picture ( x264_picture_t * pic)
static

Definition at line 303 of file libx264.c.

Referenced by setup_frame().

◆ csp_to_pixfmt()

static enum AVPixelFormat csp_to_pixfmt ( int csp)
static

Definition at line 313 of file libx264.c.

Referenced by X264_frame().

◆ mbinfo_compute_changed_coords()

static void av_always_inline mbinfo_compute_changed_coords ( const AVVideoRect * rect,
int * min_x,
int * max_x,
int * min_y,
int * max_y )
static

Definition at line 335 of file libx264.c.

Referenced by setup_mb_info().

◆ mbinfo_compute_constant_coords()

static void av_always_inline mbinfo_compute_constant_coords ( const AVVideoRect * rect,
int * min_x,
int * max_x,
int * min_y,
int * max_y )
static

Definition at line 347 of file libx264.c.

Referenced by setup_mb_info().

◆ setup_mb_info()

static int setup_mb_info ( AVCodecContext * ctx,
x264_picture_t * pic,
const AVFrame * frame,
const AVVideoHint * info )
static

Definition at line 359 of file libx264.c.

Referenced by setup_frame().

◆ setup_roi()

static int setup_roi ( AVCodecContext * ctx,
x264_picture_t * pic,
const AVFrame * frame,
const uint8_t * data,
size_t size )
static

Definition at line 403 of file libx264.c.

Referenced by setup_frame().

◆ setup_frame()

static int setup_frame ( AVCodecContext * ctx,
const AVFrame * frame,
x264_picture_t ** ppic )
static

Definition at line 476 of file libx264.c.

Referenced by X264_frame().

◆ X264_frame()

static int X264_frame ( AVCodecContext * ctx,
AVPacket * pkt,
const AVFrame * frame,
int * got_packet )
static

Definition at line 619 of file libx264.c.

◆ X264_flush()

static void X264_flush ( AVCodecContext * avctx)
static

Definition at line 752 of file libx264.c.

◆ X264_reconf()

static av_cold int X264_reconf ( AVCodecContext * avctx,
AVDictionary ** dict )
static

Definition at line 770 of file libx264.c.

◆ X264_close()

static av_cold int X264_close ( AVCodecContext * avctx)
static

Definition at line 783 of file libx264.c.

◆ parse_opts()

static int parse_opts ( AVCodecContext * avctx,
const char * opt,
const char * param )
static

Definition at line 805 of file libx264.c.

Referenced by X264_init().

◆ convert_pix_fmt()

static int convert_pix_fmt ( enum AVPixelFormat pix_fmt)
static

Definition at line 831 of file libx264.c.

Referenced by X264_init().

◆ save_sei()

static int save_sei ( AVCodecContext * avctx,
x264_nal_t * nal )
static

Definition at line 866 of file libx264.c.

Referenced by set_extradata().

◆ set_extradata()

static int set_extradata ( AVCodecContext * avctx)
static

Definition at line 969 of file libx264.c.

Referenced by X264_init().

◆ handle_side_data()

static void handle_side_data ( AVCodecContext * avctx,
x264_param_t * params )
static

Definition at line 1059 of file libx264.c.

Referenced by X264_init().

◆ X264_init()

static av_cold int X264_init ( AVCodecContext * avctx)
static

Definition at line 1086 of file libx264.c.

Variable Documentation

◆ pix_fmts_8bit

enum AVPixelFormat pix_fmts_8bit[]
static
Initial value:
= {
}
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:198
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition pixfmt.h:86
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition pixfmt.h:87
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85

Definition at line 1459 of file libx264.c.

◆ pix_fmts_9bit

enum AVPixelFormat pix_fmts_9bit[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542

Definition at line 1473 of file libx264.c.

◆ pix_fmts_10bit

enum AVPixelFormat pix_fmts_10bit[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_NV20
Definition pixfmt.h:606
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548

Definition at line 1478 of file libx264.c.

◆ pix_fmts_all

◆ options

const AVOption options[]
static

Definition at line 1519 of file libx264.c.

◆ x264_defaults

const FFCodecDefault x264_defaults[]
static
Initial value:
= {
{ "sar", "0", AV_OPT_FLAG_RUNTIME_PARAM },
{ "bufsize", "0", AV_OPT_FLAG_RUNTIME_PARAM },
{ "maxrate", "0", AV_OPT_FLAG_RUNTIME_PARAM },
{ "bf", "-1" },
{ "flags2", "0" },
{ "g", "-1" },
{ "i_qfactor", "-1" },
{ "b_qfactor", "-1" },
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "qdiff", "-1" },
{ "qblur", "-1" },
{ "qcomp", "-1" },
{ "refs", "-1" },
{ "trellis", "-1" },
{ "me_range", "-1" },
{ "subq", "-1" },
{ "keyint_min", "-1" },
{ "cmp", "-1" },
{ "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
{ "thread_type", "0" },
{ "flags", "+cgop" },
{ "rc_init_occupancy","-1" },
{ NULL },
}
#define NULL
Definition coverity.c:32
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition opt.h:376
#define AV_STRINGIFY(s)
Definition macros.h:66

Definition at line 1600 of file libx264.c.