FFmpeg
Loading...
Searching...
No Matches
rkmppenc.c
Go to the documentation of this file.
1/*
2 * RockChip MPP Video Encoder
3 *
4 * This file is part of FFmpeg.
5 *
6 * Copyright (c) 2025 Zhao Zhili <quinkblack@foxmail.com>
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "config_components.h"
24
25#include <assert.h>
26#include <stdbool.h>
27
28#include <rockchip/mpp_frame.h>
29#include <rockchip/mpp_packet.h>
30#include <rockchip/rk_mpi.h>
31
32#include "libavutil/avassert.h"
33#include "libavutil/hwcontext.h"
35#include "libavutil/imgutils.h"
36#include "libavutil/log.h"
37#include "libavutil/mem.h"
38#include "libavutil/opt.h"
39
40#include "avcodec.h"
41#include "codec_internal.h"
42#include "encode.h"
43#include "hwconfig.h"
44
45#define RKMPP_TIME_BASE AV_TIME_BASE_Q
46#define RKMPP_ALIGN_SIZE 16
47
48typedef struct RKMPPEncoderContext {
50
51 MppCtx enc;
52 MppApi *mpi;
53 MppEncCfg cfg;
55
56 MppFrameFormat pix_fmt;
59 // When pix_fmt isn't hardware pixel format
60 MppBufferGroup buf_group;
61 MppBuffer frame_buf;
62
63 MppEncRcMode rc_mode;
66
73
75{
77
78 if (ctx->enc) {
79 ctx->mpi->reset(ctx->enc);
80 mpp_destroy(ctx->enc);
81 ctx->enc = NULL;
82 }
83
84 if (ctx->cfg) {
85 mpp_enc_cfg_deinit(ctx->cfg);
86 ctx->cfg = NULL;
87 }
88
89 if (ctx->frame_buf) {
90 mpp_buffer_put(ctx->frame_buf);
91 ctx->frame_buf = NULL;
92 }
93
94 if (ctx->buf_group) {
95 mpp_buffer_group_put(ctx->buf_group);
96 ctx->buf_group = NULL;
97 }
98
99 av_frame_free(&ctx->frame);
100
101 return 0;
102}
103
105{
107
108 ctx->frame = av_frame_alloc();
109 if (!ctx->frame)
110 return AVERROR(ENOMEM);
111
112 if (avctx->pix_fmt == AV_PIX_FMT_DRM_PRIME)
113 return 0;
114
115 int ret = mpp_buffer_group_get_internal(&ctx->buf_group,
116 MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CACHABLE);
117 if (ret != MPP_OK) {
118 av_log(avctx, AV_LOG_ERROR, "Failed to create buffer group, %d\n",
119 ret);
120 return AVERROR_EXTERNAL;
121 }
122
123 int n = av_image_get_buffer_size(avctx->pix_fmt, ctx->mpp_stride,
124 ctx->mpp_height, 1);
125 if (n < 0)
126 return ret;
127 ret = mpp_buffer_get(ctx->buf_group, &ctx->frame_buf, n);
128 if (ret != MPP_OK) {
129 av_log(avctx, AV_LOG_ERROR, "Failed to get frame buffer, %d\n",
130 ret);
131 return AVERROR_EXTERNAL;
132 }
133
134 return 0;
135}
136
138{
140 MppEncHeaderMode mode = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ?
141 MPP_ENC_HEADER_MODE_DEFAULT : MPP_ENC_HEADER_MODE_EACH_IDR;
142
143 int ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_HEADER_MODE, &mode);
144 if (ret != MPP_OK) {
145 av_log(avctx, AV_LOG_ERROR, "Failed to set header mode: %d\n", ret);
146 return AVERROR_EXTERNAL;
147 }
148
149 if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
150 return 0;
151
152 size_t size = 4096;
154 if (!avctx->extradata)
155 return AVERROR(ENOMEM);
156
157 MppPacket packet = NULL;
158 mpp_packet_init(&packet, avctx->extradata, size);
159 mpp_packet_set_length(packet, 0);
160 ret = ctx->mpi->control(ctx->enc, MPP_ENC_GET_HDR_SYNC, packet);
161 if (ret != MPP_OK) {
162 av_log(avctx, AV_LOG_ERROR, "Failed to get header: %d\n", ret);
163 ret = AVERROR_EXTERNAL;
164 goto out;
165 }
166
167 avctx->extradata_size = mpp_packet_get_length(packet);
168 if (avctx->extradata_size == 0 || avctx->extradata_size > size) {
169 av_log(avctx, AV_LOG_ERROR, "Invalid extradata size %d\n",
170 avctx->extradata_size);
171 ret = AVERROR_EXTERNAL;
172 goto out;
173 }
174
175 ret = 0;
176out:
177 mpp_packet_deinit(&packet);
178
179 return ret;
180}
181
183{
185 int ret;
186
187 MppCodingType codectype;
188 switch (avctx->codec_id) {
189 case AV_CODEC_ID_H264:
190 codectype = MPP_VIDEO_CodingAVC;
191 break;
192 case AV_CODEC_ID_HEVC:
193 codectype = MPP_VIDEO_CodingHEVC;
194 break;
195 default:
196 av_unreachable("Invalid codec_id");
197 }
198
199 ret = mpp_check_support_format(MPP_CTX_ENC, codectype);
200 if (ret != MPP_OK) {
201 av_log(avctx, AV_LOG_ERROR, "The device doesn't support %s\n",
202 avcodec_get_name(avctx->codec_id));
203 return AVERROR_EXTERNAL;
204 }
205
206 ret = mpp_create(&ctx->enc, &ctx->mpi);
207 if (ret != MPP_OK) {
208 av_log(avctx, AV_LOG_ERROR, "Failed to create MPP context (%d).\n", ret);
209 return AVERROR_EXTERNAL;
210 }
211
212 ret = mpp_init(ctx->enc, MPP_CTX_ENC, codectype);
213 if (ret != MPP_OK) {
214 av_log(avctx, AV_LOG_ERROR, "Failed to initialize MPP context (%d).\n", ret);
215 return AVERROR_EXTERNAL;
216 }
217
218 ret = mpp_enc_cfg_init(&ctx->cfg);
219 if (ret != MPP_OK) {
220 av_log(avctx, AV_LOG_ERROR, "Failed to initialize config (%d).\n", ret);
221 return AVERROR_EXTERNAL;
222 }
223
224 MppEncCfg cfg = ctx->cfg;
225 ret = ctx->mpi->control(ctx->enc, MPP_ENC_GET_CFG, cfg);
226 if (ret != MPP_OK) {
227 av_log(avctx, AV_LOG_ERROR, "Failed to get encoder config: %d\n", ret);
228 return AVERROR_EXTERNAL;
229 }
230
231 mpp_enc_cfg_set_s32(cfg, "prep:width", avctx->width);
232 mpp_enc_cfg_set_s32(cfg, "prep:height", avctx->height);
233 ctx->mpp_stride = FFALIGN(avctx->width, RKMPP_ALIGN_SIZE);
234 ctx->mpp_height = FFALIGN(avctx->height, RKMPP_ALIGN_SIZE);
235 mpp_enc_cfg_set_s32(cfg, "prep:hor_stride", ctx->mpp_stride);
236 mpp_enc_cfg_set_s32(cfg, "prep:ver_stride", ctx->mpp_height);
237
238 if (avctx->pix_fmt == AV_PIX_FMT_DRM_PRIME || avctx->pix_fmt == AV_PIX_FMT_NV12)
239 ctx->pix_fmt = MPP_FMT_YUV420SP;
240 else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
241 ctx->pix_fmt = MPP_FMT_YUV420P;
242 else // Can only happen during development
243 return AVERROR_BUG;
244 mpp_enc_cfg_set_s32(cfg, "prep:format", ctx->pix_fmt);
245
246 if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
247 mpp_enc_cfg_set_s32(cfg, "prep:colorspace", avctx->colorspace);
249 mpp_enc_cfg_set_s32(cfg, "prep:colorprim", avctx->color_primaries);
250 if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
251 mpp_enc_cfg_set_s32(cfg, "prep:colortrc", avctx->color_trc);
252 static_assert((int)AVCOL_RANGE_MPEG == (int)MPP_FRAME_RANGE_MPEG &&
253 (int)AVCOL_RANGE_JPEG == (int)MPP_FRAME_RANGE_JPEG &&
254 (int)AVCOL_RANGE_UNSPECIFIED == (int) MPP_FRAME_RANGE_UNSPECIFIED,
255 "MppFrameColorRange not equal to AVColorRange");
256 mpp_enc_cfg_set_s32(cfg, "prep:colorrange", avctx->color_range);
257
258 /* These two options sound like variable frame rate from the doc, but they
259 * are not. When they are false, bitrate control is based on frame numbers
260 * and framerate. But when they are true, bitrate control is based on wall
261 * clock time, not based on frame timestamps, which makes these options
262 * almost useless, except in certain rare realtime case.
263 */
264 mpp_enc_cfg_set_s32(cfg, "rc:fps_in_flex", 0);
265 mpp_enc_cfg_set_s32(cfg, "rc:fps_out_flex", 0);
266 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
267 mpp_enc_cfg_set_s32(cfg, "rc:fps_in_num", avctx->framerate.num);
268 mpp_enc_cfg_set_s32(cfg, "rc:fps_in_denom", avctx->framerate.den);
269 mpp_enc_cfg_set_s32(cfg, "rc:fps_out_num", avctx->framerate.num);
270 mpp_enc_cfg_set_s32(cfg, "rc:fps_out_denom", avctx->framerate.den);
271 }
272
273 if (avctx->gop_size >= 0)
274 mpp_enc_cfg_set_s32(cfg, "rc:gop", avctx->gop_size);
275
276 mpp_enc_cfg_set_u32(cfg, "rc:mode", ctx->rc_mode);
277 if (avctx->bit_rate > 0) {
278 mpp_enc_cfg_set_s32(cfg, "rc:bps_target", avctx->bit_rate);
279 if (avctx->rc_buffer_size >= avctx->bit_rate) {
280 int seconds = round((double)avctx->rc_buffer_size / avctx->bit_rate);
281 // 60 is the upper bound from the doc
282 seconds = FFMIN(seconds, 60);
283 mpp_enc_cfg_set_s32(cfg, "rc:stats_time", seconds);
284 }
285 }
286 if (avctx->rc_max_rate > 0)
287 mpp_enc_cfg_set_s32(cfg, "rc:bps_max", avctx->rc_max_rate);
288 if (avctx->rc_min_rate > 0)
289 mpp_enc_cfg_set_s32(cfg, "rc:bps_min", avctx->rc_min_rate);
290
291 mpp_enc_cfg_set_u32(cfg, "rc:drop_mode", MPP_ENC_RC_DROP_FRM_DISABLED);
292
293 ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_CFG, cfg);
294 if (ret != MPP_OK) {
295 av_log(avctx, AV_LOG_ERROR, "Failed to set config: %d\n", ret);
296 return AVERROR_EXTERNAL;
297 }
298
299 ret = rkmpp_create_frame_buf(avctx);
300 if (ret < 0)
301 return ret;
302
303 ret = rkmpp_export_extradata(avctx);
304 if (ret < 0)
305 return ret;
306
307 return 0;
308}
309
310static int rkmpp_output_pkt(AVCodecContext *avctx, AVPacket *pkt, MppPacket packet)
311{
312 if (mpp_packet_get_eos(packet)) {
313 av_log(avctx, AV_LOG_INFO, "Receive eos packet\n");
314 return AVERROR_EOF;
315 }
316
317 size_t size = mpp_packet_get_length(packet);
318 void *data = mpp_packet_get_pos(packet);
319
320 if (!size || !data) {
321 av_log(avctx, AV_LOG_ERROR, "Encoder return empty packet\n");
322 return AVERROR_EXTERNAL;
323 }
324
325 int ret = ff_get_encode_buffer(avctx, pkt, size, 0);
326 if (ret < 0)
327 return ret;
328 memcpy(pkt->data, data, size);
329
330 int64_t pts = mpp_packet_get_pts(packet);
331 int64_t dts = mpp_packet_get_dts(packet);
332
334 /* dts is always zero currently, since rkmpp copy dts from MppFrame to
335 * MppPacket, and we don't set dts for MppFrame (it make no sense for
336 * encoder). rkmpp encoder doesn't support reordering, so we can just
337 * set dts as pts.
338 *
339 * TODO: remove this workaround once rkmpp fixed the issue.
340 */
341 if (dts)
342 pkt->dts = av_rescale_q(dts, RKMPP_TIME_BASE, avctx->time_base);
343 else
344 pkt->dts = pkt->pts;
345
346 MppMeta meta = mpp_packet_get_meta(packet);
347 if (!meta) {
348 av_log(avctx, AV_LOG_ERROR, "Failed to get meta from mpp packet\n");
349 return AVERROR_EXTERNAL;
350 }
351
352 int key_frame = 0;
353 ret = mpp_meta_get_s32(meta, KEY_OUTPUT_INTRA, &key_frame);
354 if (ret != MPP_OK) {
355 av_log(avctx, AV_LOG_ERROR, "Failed to get key frame info\n");
356 return AVERROR_EXTERNAL;
357 }
358
359 if (key_frame)
360 pkt->flags |= AV_PKT_FLAG_KEY;
361
362 return 0;
363}
364
365static int rkmpp_set_hw_frame(AVCodecContext *avctx, MppFrame frame)
366{
368 AVBufferRef *hw_ref = ctx->frame->hw_frames_ctx;
369 int ret;
370
371 if (!hw_ref)
372 return AVERROR(EINVAL);
373
374 AVHWFramesContext *hwframes = (AVHWFramesContext *)hw_ref->data;
375 if (hwframes->sw_format != AV_PIX_FMT_NV12)
376 return AVERROR(EINVAL);
377
378
379 const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)ctx->frame->data[0];
380 const AVDRMLayerDescriptor *layer = &desc->layers[0];
381
382 int stride = layer->planes[0].pitch;
383 int vertical = layer->planes[1].offset / stride;
384 if (stride != ctx->mpp_stride || vertical != ctx->mpp_height) {
385 // Update stride info
386 ctx->mpp_stride = stride;
387 ctx->mpp_height = vertical;
388 mpp_enc_cfg_set_s32(ctx->cfg, "prep:hor_stride", ctx->mpp_stride);
389 mpp_enc_cfg_set_s32(ctx->cfg, "prep:ver_stride", ctx->mpp_height);
390 ret = ctx->mpi->control(ctx->enc, MPP_ENC_SET_CFG, ctx->cfg);
391 if (ret != MPP_OK) {
392 av_log(avctx, AV_LOG_ERROR, "Failed to set config: %d\n", ret);
393 return AVERROR_EXTERNAL;
394 }
395 }
396 mpp_frame_set_hor_stride(frame, stride);
397 mpp_frame_set_ver_stride(frame, vertical);
398
399 MppBuffer buffer = {0};
400 MppBufferInfo info = {
401 .type = MPP_BUFFER_TYPE_DRM,
402 .size = desc->objects[0].size,
403 .fd = desc->objects[0].fd,
404 };
405 ret = mpp_buffer_import(&buffer, &info);
406 if (ret != MPP_OK)
407 return AVERROR_EXTERNAL;
408
409 mpp_frame_set_buffer(frame, buffer);
410 mpp_buffer_put(buffer);
411
412 return 0;
413}
414
415static int rkmpp_set_sw_frame(AVCodecContext *avctx, MppFrame frame)
416{
418 AVFrame *f = ctx->frame;
419
420 mpp_buffer_sync_begin(ctx->frame_buf);
421 void *buf = mpp_buffer_get_ptr(ctx->frame_buf);
422
423 uint8_t *dst[4] = {NULL};
424 int dst_linesizes[4] = {0};
425 int ret = av_image_fill_linesizes(dst_linesizes, f->format, ctx->mpp_stride);
426 if (ret < 0)
427 goto out;
428 ret = av_image_fill_pointers(dst, f->format, ctx->mpp_height, buf,
429 dst_linesizes);
430 if (ret < 0)
431 goto out;
432
433 av_image_copy2(dst, dst_linesizes, f->data, f->linesize,
434 f->format, f->width, f->height);
435 mpp_frame_set_hor_stride(frame, ctx->mpp_stride);
436 mpp_frame_set_ver_stride(frame, ctx->mpp_height);
437
438 ret = 0;
439
440out:
441 mpp_buffer_sync_end(ctx->frame_buf);
442 if (!ret)
443 mpp_frame_set_buffer(frame, ctx->frame_buf);
444
445 return ret;
446}
447
449{
451 MppFrame frame = NULL;
452 int ret = 0;
453
454 ret = mpp_frame_init(&frame);
455 if (ret != MPP_OK) {
456 ret = AVERROR_EXTERNAL;
457 goto out;
458 }
459
460 if (ctx->frame->buf[0]) {
461 if (ctx->frame->format == AV_PIX_FMT_DRM_PRIME)
462 ret = rkmpp_set_hw_frame(avctx, frame);
463 else
464 ret = rkmpp_set_sw_frame(avctx, frame);
465
466 if (ret < 0)
467 goto out;
468
469 mpp_frame_set_fmt(frame, ctx->pix_fmt);
470 mpp_frame_set_width(frame, ctx->frame->width);
471 mpp_frame_set_height(frame, ctx->frame->height);
472 mpp_frame_set_pts(frame, av_rescale_q(ctx->frame->pts,
473 avctx->time_base, RKMPP_TIME_BASE));
474 } else {
475 mpp_frame_set_buffer(frame, NULL);
476 mpp_frame_set_eos(frame, 1);
477 }
478
479 ret = ctx->mpi->encode_put_frame(ctx->enc, frame);
480 if (ret != MPP_OK)
481 ret = AVERROR_EXTERNAL;
482
483out:
484 if (frame)
485 mpp_frame_deinit(&frame);
486
487 return ret;
488}
489
491{
493
494 while (true) {
495 MppPacket packet = NULL;
496 int ret = ctx->mpi->encode_get_packet(ctx->enc, &packet);
497
498 if (ret == MPP_OK && packet) {
499 ret = rkmpp_output_pkt(avctx, pkt, packet);
500 mpp_packet_deinit(&packet);
501 return ret;
502 }
503
504 if (ctx->eof_sent)
505 continue;
506
507 if (!ctx->frame->buf[0]) {
508 ret = ff_encode_get_frame(avctx, ctx->frame);
509 if (ret < 0 && ret != AVERROR_EOF)
510 return ret;
511 }
512
513 ret = rkmpp_send_frame(avctx);
514 if (ret < 0)
515 return ret;
516
517 if (!ctx->frame->buf[0])
518 ctx->eof_sent = true;
519 else
520 av_frame_unref(ctx->frame);
521 }
522}
523
525{
527 ctx->mpi->reset(ctx->enc);
528 ctx->eof_sent = true;
529}
530
532 HW_CONFIG_ENCODER_FRAMES(DRM_PRIME, DRM),
533 NULL
534};
535
536#define OFFSET(x) offsetof(RKMPPEncoderContext, x)
537#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
538static const AVOption rkmpp_options[] = {
539 {"rc", "rate-control mode",
540 OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = MPP_ENC_RC_MODE_VBR }, MPP_ENC_RC_MODE_VBR, INT_MAX, VE, .unit = "rc"},
541 {"vbr", "Variable bitrate mode",
542 0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_VBR}, 0, 0, VE, .unit = "rc"},
543 {"cbr", "Constant bitrate mode",
544 0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_CBR}, 0, 0, VE, .unit = "rc"},
545 {"avbr", "Adaptive bit rate mode",
546 0, AV_OPT_TYPE_CONST, {.i64 = MPP_ENC_RC_MODE_AVBR}, 0, 0, VE, .unit = "rc"},
547 {NULL},
548};
549
550static const AVClass rkmpp_enc_class = {
551 .class_name = "rkmpp_enc",
552 .item_name = av_default_item_name,
553 .version = LIBAVUTIL_VERSION_INT,
554 .option = rkmpp_options,
555};
556
557#define RKMPP_ENC(NAME, ID) \
558 const FFCodec ff_##NAME##_rkmpp_encoder = { \
559 .p.name = #NAME "_rkmpp", \
560 CODEC_LONG_NAME(#NAME " (rkmpp)"), \
561 .p.type = AVMEDIA_TYPE_VIDEO, \
562 .p.id = ID, \
563 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
564 AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_ENCODER_FLUSH, \
565 .priv_data_size = sizeof(RKMPPEncoderContext), \
566 CODEC_PIXFMTS_ARRAY(rkmpp_pix_fmts), \
567 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
568 .init = rkmpp_init_encoder, \
569 FF_CODEC_RECEIVE_PACKET_CB(rkmpp_receive), \
570 .close = rkmpp_close_encoder, \
571 .flush = rkmpp_flush, \
572 .p.priv_class = &rkmpp_enc_class, \
573 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
574 .p.wrapper_name = "rkmpp", \
575 .hw_configs = rkmpp_hw_configs, \
576 };
577
578#if CONFIG_H264_RKMPP_ENCODER
580#endif
581
582#if CONFIG_HEVC_RKMPP_ENCODER
584#endif
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define VE
Definition amfenc_av1.c:30
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
Libavcodec external API header.
#define f(width, name)
Definition cbs_vp8.c:236
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static AVFrame * frame
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition encode.c:218
static CheckasmConfig cfg
Definition checkasm.c:74
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition avcodec.h:318
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition imgutils.c:466
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition imgutils.c:145
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition imgutils.h:184
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition imgutils.c:89
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition hwconfig.h:100
API-specific header for AV_HWDEVICE_TYPE_DRM.
misc image utilities
#define av_cold
Definition attributes.h:117
static av_always_inline av_const double round(double x)
Definition libm.h:446
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
const char data[16]
Definition mxf.c:149
AVOptions.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ 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_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
Definition pixfmt.h:351
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:645
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:675
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
mfxU16 rc_mode
Definition qsvenc.c:141
static const AVCodecHWConfigInternal *const rkmpp_hw_configs[]
Definition rkmppdec.c:548
static int rkmpp_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition rkmppenc.c:490
static av_cold int rkmpp_close_encoder(AVCodecContext *avctx)
Definition rkmppenc.c:74
static int rkmpp_output_pkt(AVCodecContext *avctx, AVPacket *pkt, MppPacket packet)
Definition rkmppenc.c:310
static enum AVPixelFormat rkmpp_pix_fmts[]
Definition rkmppenc.c:67
#define RKMPP_TIME_BASE
Definition rkmppenc.c:45
static int rkmpp_export_extradata(AVCodecContext *avctx)
Definition rkmppenc.c:137
static int rkmpp_send_frame(AVCodecContext *avctx)
Definition rkmppenc.c:448
#define RKMPP_ALIGN_SIZE
Definition rkmppenc.c:46
static int rkmpp_set_sw_frame(AVCodecContext *avctx, MppFrame frame)
Definition rkmppenc.c:415
#define RKMPP_ENC(NAME, ID)
Definition rkmppenc.c:557
static int rkmpp_create_frame_buf(AVCodecContext *avctx)
Definition rkmppenc.c:104
static const AVClass rkmpp_enc_class
Definition rkmppenc.c:550
static int rkmpp_set_hw_frame(AVCodecContext *avctx, MppFrame frame)
Definition rkmppenc.c:365
#define OFFSET(x)
Definition rkmppenc.c:536
static const AVOption rkmpp_options[]
Definition rkmppenc.c:538
static av_cold void rkmpp_flush(AVCodecContext *avctx)
Definition rkmppenc.c:524
static av_cold int rkmpp_init_encoder(AVCodecContext *avctx)
Definition rkmppenc.c:182
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
int rc_buffer_size
decoder bitstream buffer size
Definition avcodec.h:1273
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
AVRational framerate
Definition avcodec.h:563
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition avcodec.h:1021
int64_t rc_max_rate
maximum bitrate
Definition avcodec.h:1288
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avcodec.h:547
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int64_t rc_min_rate
minimum bitrate
Definition avcodec.h:1295
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
void * priv_data
Definition avcodec.h:470
DRM frame descriptor.
DRM layer descriptor.
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
ptrdiff_t pitch
Pitch (linesize) of this plane.
ptrdiff_t offset
Offset within that object of this plane.
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
MppBufferGroup buf_group
Definition rkmppenc.c:60
const AVClass * av_class
Definition rkmppenc.c:49
AVFrame * frame
Definition rkmppenc.c:54
MppBuffer frame_buf
Definition rkmppenc.c:61
MppFrameFormat pix_fmt
Definition rkmppenc.c:56
MppEncRcMode rc_mode
Definition rkmppenc.c:63
Definition swscale.c:71
#define stride
#define av_mallocz(s)
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static char buffer[20]
Definition seek.c:32
static int64_t pts
int size