72 return RA_PIXEL_RANGE_FULL;
77 return RA_PIXEL_RANGE_FULL;
80 return RA_PIXEL_RANGE_LIMITED;
91 return RA_CHROMA_SAMPLING_CS420;
96 return RA_CHROMA_SAMPLING_CS422;
101 return RA_CHROMA_SAMPLING_CS444;
109 switch (chroma_loc) {
111 return RA_CHROMA_SAMPLE_POSITION_VERTICAL;
113 return RA_CHROMA_SAMPLE_POSITION_COLOCATED;
115 return RA_CHROMA_SAMPLE_POSITION_UNKNOWN;
122 RaData* buf = rav1e_twopass_out(
ctx->ctx);
128 ctx->pass_pos + buf->len);
130 rav1e_data_unref(buf);
135 memcpy(
ctx->pass_data +
ctx->pass_pos, buf->data, buf->len);
136 ctx->pass_pos += buf->len;
140 memcpy(
ctx->pass_data, buf->data, buf->len);
144 rav1e_data_unref(buf);
153 rav1e_data_unref(buf);
163 while (ret > 0 &&
ctx->pass_size -
ctx->pass_pos > 0) {
164 ret = rav1e_twopass_in(
ctx->ctx,
ctx->pass_data +
ctx->pass_pos,
ctx->pass_size);
167 ctx->pass_pos += ret;
178 rav1e_context_unref(
ctx->ctx);
182 rav1e_frame_unref(
ctx->rframe);
204 cfg = rav1e_config_default();
216 rav1e_config_set_time_base(
cfg, (RaRational) {
220 rav1e_config_set_time_base(
cfg, (RaRational) {
238 ctx->pass_size = (strlen(avctx->
stats_in) * 3) / 4;
240 if (!
ctx->pass_data) {
247 if (
ctx->pass_size < 0) {
257 if (rav1e_config_parse(
cfg, en->
key, en->
value) < 0)
262 rret = rav1e_config_parse_int(
cfg,
"width", avctx->
width);
269 rret = rav1e_config_parse_int(
cfg,
"height", avctx->
height);
277 rav1e_config_set_sample_aspect_ratio(
cfg, (RaRational) {
286 if (
ctx->speed >= 0) {
287 rret = rav1e_config_parse_int(
cfg,
"speed",
ctx->speed);
296 if (
ctx->tiles > 0) {
297 rret = rav1e_config_parse_int(
cfg,
"tiles",
ctx->tiles);
304 if (
ctx->tile_rows > 0) {
305 rret = rav1e_config_parse_int(
cfg,
"tile_rows",
ctx->tile_rows);
312 if (
ctx->tile_cols > 0) {
313 rret = rav1e_config_parse_int(
cfg,
"tile_cols",
ctx->tile_cols);
322 rret = rav1e_config_parse_int(
cfg,
"key_frame_interval", avctx->
gop_size);
331 rret = rav1e_config_parse_int(
cfg,
"min_key_frame_interval", avctx->
keyint_min);
340 int max_quantizer = avctx->
qmax >= 0 ? avctx->
qmax : 255;
342 rret = rav1e_config_parse_int(
cfg,
"quantizer", max_quantizer);
349 if (avctx->
qmin >= 0) {
350 rret = rav1e_config_parse_int(
cfg,
"min_quantizer", avctx->
qmin);
358 rret = rav1e_config_parse_int(
cfg,
"bitrate", avctx->
bit_rate);
364 }
else if (
ctx->quantizer >= 0) {
368 rret = rav1e_config_parse_int(
cfg,
"quantizer",
ctx->quantizer);
376 rret = rav1e_config_set_pixel_format(
cfg,
desc->comp[0].depth,
387 rret = rav1e_config_set_color_description(
cfg, (RaMatrixCoefficients) avctx->
colorspace,
389 (RaTransferCharacteristics) avctx->
color_trc);
398 ctx->ctx = rav1e_context_new(
cfg);
406 RaData *seq_hdr = rav1e_container_sequence_header(
ctx->ctx);
411 rav1e_data_unref(seq_hdr);
417 memcpy(avctx->
extradata, seq_hdr->data, seq_hdr->len);
419 rav1e_data_unref(seq_hdr);
426 rav1e_config_unref(
cfg);
445 RaFrame *rframe =
ctx->rframe;
446 RaPacket *rpkt =
NULL;
474 rframe = rav1e_frame_new(
ctx->ctx);
482 for (
int i = 0;
i <
desc->nb_components;
i++) {
484 int bytes =
desc->comp[0].depth == 8 ? 1 : 2;
485 rav1e_frame_fill_plane(rframe,
i,
frame->data[
i],
487 frame->linesize[
i], bytes);
494 ret = rav1e_send_frame(
ctx->ctx, rframe);
496 if (ret == RA_ENCODER_STATUS_ENOUGH_DATA) {
497 ctx->rframe = rframe;
499 rav1e_frame_unref(rframe);
504 case RA_ENCODER_STATUS_SUCCESS:
505 case RA_ENCODER_STATUS_ENOUGH_DATA:
507 case RA_ENCODER_STATUS_FAILURE:
511 av_log(avctx,
AV_LOG_ERROR,
"Unknown return code %d from rav1e_send_frame: %s\n", ret, rav1e_status_to_str(ret));
527 ret = rav1e_receive_packet(
ctx->ctx, &rpkt);
529 case RA_ENCODER_STATUS_SUCCESS:
531 case RA_ENCODER_STATUS_LIMIT_REACHED:
538 case RA_ENCODER_STATUS_ENCODED:
540 case RA_ENCODER_STATUS_NEED_MORE_DATA:
546 case RA_ENCODER_STATUS_FAILURE:
547 av_log(avctx,
AV_LOG_ERROR,
"Could not encode frame: %s\n", rav1e_status_to_str(ret));
550 av_log(avctx,
AV_LOG_ERROR,
"Unknown return code %d from rav1e_receive_packet: %s\n", ret, rav1e_status_to_str(ret));
557 rav1e_packet_unref(rpkt);
561 memcpy(
pkt->data, rpkt->data, rpkt->len);
563 if (rpkt->frame_type == RA_FRAME_TYPE_KEY)
591 rav1e_packet_unref(rpkt);
595 for (
int i = 0;
i <
desc->nb_components;
i++) {
597 rav1e_frame_extract_plane(rpkt->rec,
i,
frame->data[
i],
603 rav1e_packet_unref(rpkt);
608#define OFFSET(x) offsetof(librav1eContext, x)
609#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
617 {
"rav1e-params",
"set the rav1e configuration using a :-separated list of key=value parameters",
OFFSET(rav1e_opts),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
624 {
"keyint_min",
"0" },
654 .p.name =
"librav1e",
662 .p.priv_class = &
class,
671 .p.wrapper_name =
"librav1e",
const FFCodec ff_librav1e_encoder
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
refcounted data buffer API
#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_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal and external API header
#define AV_EF_EXPLODE
abort decoding on minor error detection
static enum AVPixelFormat pix_fmt
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
static CheckasmConfig cfg
static void frame_data_free(void *opaque, uint8_t *data)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#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_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
#define AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#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.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
#define LIBAVUTIL_VERSION_INT
static int shift(int a, int b)
common internal api header.
common internal API header
static const FFCodecDefault librav1e_defaults[]
static int set_stats(AVCodecContext *avctx)
static RaChromaSampling pix_fmt_map(enum AVPixelFormat pix_fmt)
static RaChromaSamplePosition chroma_loc_map(enum AVChromaLocation chroma_loc)
static void frame_data_free(void *data)
static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
static RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range)
static av_cold int librav1e_encode_close(AVCodecContext *avctx)
enum AVPixelFormat librav1e_pix_fmts[]
static av_cold int librav1e_encode_init(AVCodecContext *avctx)
static int get_stats(AVCodecContext *avctx, int eos)
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV444P12
AVChromaLocation
Location of chroma samples.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
#define AV_PIX_FMT_YUV420P10
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUV444P10
A reference to a data buffer.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
char * stats_out
pass1 encoding statistics output buffer
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int qmin
minimum quantizer
int keyint_min
minimum GOP size
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int64_t bit_rate
the average bitrate
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int qmax
maximum quantizer
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
struct AVCodecInternal * internal
Private context used for internal data.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVBufferRef * frame_opaque_ref
AVDictionary * rav1e_opts