41#define MAX_BS_BUF (16*1024*1024)
46#define XEVE_PARAM_BAD_NAME -100
47#define XEVE_PARAM_BAD_VALUE -200
101 switch (av_pix_fmt) {
103 *xeve_col_fmt = XEVE_CF_YCBCR420;
106 *xeve_col_fmt = XEVE_CF_YCBCR420;
109 *xeve_col_fmt = XEVE_CF_UNKNOWN;
126 int cs = XEVE_CF_UNKNOWN;
128 switch (av_pix_fmt) {
130 cs = XEVE_CS_YCBCR420;
134 cs = XEVE_CS_SET(XEVE_CF_YCBCR420, 10, 1);
136 cs = XEVE_CS_YCBCR420_10LE;
141 cs = XEVE_CF_UNKNOWN;
180 ret = xeve_param_default(&cdsc->param);
181 if (XEVE_FAILED(ret)) {
187 if (avctx->
width > 0)
188 cdsc->param.w = avctx->
width;
191 cdsc->param.h = avctx->
height;
200 cdsc->param.keyint = avctx->
gop_size;
207 "Acceptable values for bf option (maximum number of B frames) are 0,1,3,7 or 15\n", avctx->
max_b_frames);
211 cdsc->param.level_idc = avctx->
level;
216 cdsc->param.rc_type = xectx->
rc_mode;
218 if (xectx->
rc_mode == XEVE_RC_CQP)
219 cdsc->param.qp = xectx->
qp;
220 else if (xectx->
rc_mode == XEVE_RC_ABR) {
222 av_log(avctx,
AV_LOG_ERROR,
"Not supported bitrate bit_rate and rc_max_rate > %d000\n", INT_MAX);
225 cdsc->param.bitrate = (int)(avctx->
bit_rate / 1000);
226 }
else if (xectx->
rc_mode == XEVE_RC_CRF)
227 cdsc->param.crf = xectx->
crf;
237 cdsc->param.threads = XEVE_MAX_THREADS;
244 cdsc->param.cs = XEVE_CS_SET(xectx->
color_format, cdsc->param.codec_bit_depth, AV_HAVE_BIGENDIAN);
249 if (XEVE_FAILED(ret)) {
281 ret = xeve_config(
id, XEVE_CFG_SET_SEI_CMD, &
ctx->sei_info, &
size);
282 if (XEVE_FAILED(ret)) {
287 ret = xeve_config(
id, XEVE_CFG_SET_USE_PIC_SIGNATURE, &
ctx->hash, &
size);
288 if (XEVE_FAILED(ret)) {
305 int size =
sizeof(int);
306 if (XEVE_FAILED(xeve_config(
id, XEVE_CFG_SET_FORCE_OUT, (
void *)(&
val), &
size)))
322 unsigned char *bs_buf =
NULL;
326 int width_chroma = 0;
327 int height_chroma = 0;
328 XEVE_IMGB *imgb =
NULL;
331 XEVE_CDSC *cdsc = &(xectx->
cdsc);
335 if (bs_buf ==
NULL) {
339 xectx->
bitb.addr = bs_buf;
343 if ((ret =
get_conf(avctx, cdsc)) != 0) {
348 if ((ret = xeve_param_check(&cdsc->param)) != 0) {
356 if ((ret = xeve_param_parse(&cdsc->param, en->
key, en->
value)) < 0) {
358 "Error parsing option '%s = %s'.\n",
365 xectx->
id = xeve_create(cdsc,
NULL);
396 for (
i = 0;
i < imgb->np;
i++)
397 imgb->x[
i] = imgb->y[
i] = 0;
399 imgb->w[0] = imgb->aw[0] = avctx->
width;
400 imgb->w[1] = imgb->w[2] = imgb->aw[1] = imgb->aw[2] = width_chroma;
401 imgb->h[0] = imgb->ah[0] = avctx->
height;
402 imgb->h[1] = imgb->h[2] = imgb->ah[1] = imgb->ah[2] = height_chroma;
439 XEVE_IMGB *imgb =
NULL;
443 for (
i = 0;
i < imgb->np;
i++) {
445 imgb->s[
i] =
frame->linesize[
i];
448 imgb->ts[XEVE_TS_PTS] =
frame->pts;
451 ret = xeve_push(xectx->
id, imgb);
452 if (XEVE_FAILED(ret)) {
459 ret = xeve_encode(xectx->
id, &(xectx->
bitb), &(xectx->
stat));
460 if (XEVE_FAILED(ret)) {
466 if (ret == XEVE_OK_OUT_NOT_AVAILABLE) {
469 }
else if (ret == XEVE_OK) {
470 if (xectx->
stat.write > 0) {
476 memcpy(avpkt->
data, xectx->
bitb.addr, xectx->
stat.write);
481 avpkt->
pts = xectx->
bitb.ts[XEVE_TS_PTS];
482 avpkt->
dts = xectx->
bitb.ts[XEVE_TS_DTS];
485 switch(xectx->
stat.stype) {
496 case XEVE_ST_UNKNOWN:
505 }
else if (ret == XEVE_OK_NO_MORE_FRM) {
531 xeve_delete(xectx->
id);
540#define OFFSET(x) offsetof(XeveContext, x)
541#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
552 {
"preset",
"Encoding preset for setting encoding speed",
OFFSET(preset_id),
AV_OPT_TYPE_INT, { .i64 = XEVE_PRESET_MEDIUM }, XEVE_PRESET_DEFAULT, XEVE_PRESET_PLACEBO,
VE, .unit =
"preset" },
553 {
"default",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_DEFAULT }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
555 {
"medium",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_MEDIUM }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
557 {
"placebo",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = XEVE_PRESET_PLACEBO }, INT_MIN, INT_MAX,
VE, .unit =
"preset" },
558 {
"tune",
"Tuning parameter for special purpose operation",
OFFSET(tune_id),
AV_OPT_TYPE_INT, { .i64 = XEVE_TUNE_NONE }, XEVE_TUNE_NONE, XEVE_TUNE_PSNR,
VE, .unit =
"tune"},
560 {
"zerolatency",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = XEVE_TUNE_ZEROLATENCY }, INT_MIN, INT_MAX,
VE, .unit =
"tune" },
562 {
"profile",
"Encoding profile",
OFFSET(profile_id),
AV_OPT_TYPE_INT, { .i64 = XEVE_PROFILE_BASELINE }, XEVE_PROFILE_BASELINE, XEVE_PROFILE_MAIN,
VE, .unit =
"profile" },
563 {
"baseline",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = XEVE_PROFILE_BASELINE }, INT_MIN, INT_MAX,
VE, .unit =
"profile" },
569 {
"qp",
"Quantization parameter value for CQP rate control mode",
OFFSET(qp),
AV_OPT_TYPE_INT, { .i64 = 32 }, 0, 51,
VE },
570 {
"crf",
"Constant rate factor value for CRF rate control mode",
OFFSET(crf),
AV_OPT_TYPE_INT, { .i64 = 32 }, 10, 49,
VE },
571 {
"hash",
"Embed picture signature (HASH) for conformance checking in decoding",
OFFSET(
hash),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
572 {
"sei_info",
"Embed SEI messages identifying encoder parameters and command line arguments",
OFFSET(sei_info),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
573 {
"xeve-params",
"Override the xeve configuration using a :-separated list of key=value parameters",
OFFSET(xeve_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
578 .class_name =
"libxeve",
609 .p.wrapper_name =
"libxeve",
static double val(void *priv, double ch)
const FFCodec ff_libxeve_encoder
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define LIBAVUTIL_VERSION_INT
static atomic_int cpu_count
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const FFCodecDefault libxeve_defaults[]
libavcodec generic global options, which can be set on all the encoders and decoders
static int get_conf(AVCodecContext *avctx, XEVE_CDSC *cdsc)
The function returns a pointer to the object of the XEVE_CDSC type.
static int setup_bumping(XEVE id)
Switch encoder to bumping mode.
static const AVClass libxeve_class
static const AVOption libxeve_options[]
static int libxeve_color_fmt(enum AVPixelFormat av_pix_fmt, int *xeve_col_fmt)
Convert FFmpeg pixel format (AVPixelFormat) to XEVE pre-defined color format.
static av_cold int libxeve_close(AVCodecContext *avctx)
Destroy the encoder and release all the allocated resources.
static enum AVPixelFormat supported_pixel_formats[]
static av_cold int libxeve_init(AVCodecContext *avctx)
Initialize eXtra-fast Essential Video Encoder codec Create an encoder instance and allocate all the n...
static int set_extra_config(AVCodecContext *avctx, XEVE id, XeveContext *ctx)
Set XEVE_CFG_SET_USE_PIC_SIGNATURE for encoder.
static int libxeve_color_space(enum AVPixelFormat av_pix_fmt)
Convert FFmpeg pixel format (AVPixelFormat) into XEVE pre-defined color space.
static int libxeve_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Encode raw data frame into EVC packet.
Memory handling functions.
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
const AVProfile ff_evc_profiles[]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int level
Encoding level descriptor.
int64_t bit_rate
the average bitrate
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
AVRational time_base
Time base of the packet's timestamps.
The structure stores all the states associated with the instance of Xeve MPEG-5 EVC encoder.
AVDictionary * xeve_params
static uint8_t hash[HASH_SIZE]
static AVFormatContext * ctx