FFmpeg
mediacodecenc.c
Go to the documentation of this file.
1 /*
2  * Android MediaCodec encoders
3  *
4  * Copyright (c) 2022 Zhao Zhili <zhilizhao@tencent.com>
5  *
6  * This file is part of FFmpeg.
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 "libavutil/avassert.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/opt.h"
29 
30 #include "avcodec.h"
31 #include "bsf.h"
32 #include "codec_internal.h"
33 #include "encode.h"
34 #include "hwconfig.h"
35 #include "jni.h"
36 #include "mediacodec.h"
37 #include "mediacodec_wrapper.h"
38 #include "mediacodecdec_common.h"
39 
40 #define INPUT_DEQUEUE_TIMEOUT_US 8000
41 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
42 
44  /* Constant quality mode */
46  /* Variable bitrate mode */
48  /* Constant bitrate mode */
50  /* Constant bitrate mode with frame drops */
52 };
53 
54 typedef struct MediaCodecEncContext {
58  const char *name;
60 
61  int fps;
62  int width;
63  int height;
64 
65  uint8_t *extradata;
67  int eof_sent;
68 
71 
73  int level;
76 
77 enum {
80  COLOR_FormatSurface = 0x7F000789,
81 };
82 
83 static const struct {
86 } color_formats[] = {
90 };
91 
92 static const enum AVPixelFormat avc_pix_fmts[] = {
97 };
98 
100 {
101  MediaCodecEncContext *s = avctx->priv_data;
102  char *name = ff_AMediaCodec_getName(s->codec);
103  FFAMediaFormat *out_format = ff_AMediaCodec_getOutputFormat(s->codec);
104  char *str = ff_AMediaFormat_toString(out_format);
105 
106  av_log(avctx, AV_LOG_DEBUG, "MediaCodec encoder %s output format %s\n",
107  name ? name : "unknown", str);
108  av_free(name);
109  av_free(str);
110  ff_AMediaFormat_delete(out_format);
111 }
112 
114 {
115  MediaCodecEncContext *s = avctx->priv_data;
116  char str[128];
117  int ret;
118  int crop_right = s->width - avctx->width;
119  int crop_bottom = s->height - avctx->height;
120 
121  if (!crop_right && !crop_bottom)
122  return 0;
123 
124  if (avctx->codec_id == AV_CODEC_ID_H264)
125  ret = snprintf(str, sizeof(str), "h264_metadata=crop_right=%d:crop_bottom=%d",
126  crop_right, crop_bottom);
127  else if (avctx->codec_id == AV_CODEC_ID_HEVC)
128  ret = snprintf(str, sizeof(str), "hevc_metadata=crop_right=%d:crop_bottom=%d",
129  crop_right, crop_bottom);
130  else
131  return 0;
132 
133  if (ret >= sizeof(str))
135 
136  ret = av_bsf_list_parse_str(str, &s->bsf);
137  if (ret < 0)
138  return ret;
139 
140  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
141  if (ret < 0)
142  return ret;
143  s->bsf->time_base_in = avctx->time_base;
144  ret = av_bsf_init(s->bsf);
145 
146  return ret;
147 }
148 
150 {
151  const char *codec_mime = NULL;
152  MediaCodecEncContext *s = avctx->priv_data;
154  int ret;
155  int gop;
156 
157  if (s->use_ndk_codec < 0)
158  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
159 
160  switch (avctx->codec_id) {
161  case AV_CODEC_ID_H264:
162  codec_mime = "video/avc";
163  break;
164  case AV_CODEC_ID_HEVC:
165  codec_mime = "video/hevc";
166  break;
167  default:
168  av_assert0(0);
169  }
170 
171  if (s->name)
172  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
173  else
174  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
175  if (!s->codec) {
176  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
177  codec_mime);
178  return AVERROR_EXTERNAL;
179  }
180 
181  format = ff_AMediaFormat_new(s->use_ndk_codec);
182  if (!format) {
183  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
184  return AVERROR_EXTERNAL;
185  }
186 
187  ff_AMediaFormat_setString(format, "mime", codec_mime);
188  // Workaround the alignment requirement of mediacodec. We can't do it
189  // silently for AV_PIX_FMT_MEDIACODEC.
190  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) {
191  s->width = FFALIGN(avctx->width, 16);
192  s->height = FFALIGN(avctx->height, 16);
193  } else {
194  s->width = avctx->width;
195  s->height = avctx->height;
196  if (s->width % 16 || s->height % 16)
197  av_log(avctx, AV_LOG_WARNING,
198  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
199  s->width, s->height);
200  }
201  ff_AMediaFormat_setInt32(format, "width", s->width);
202  ff_AMediaFormat_setInt32(format, "height", s->height);
203 
204  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
205  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
206  if (avctx->hw_device_ctx) {
207  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
208  AVMediaCodecDeviceContext *dev_ctx;
209 
210  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
211  ret = AVERROR(EINVAL);
212  goto bailout;
213  }
214  dev_ctx = device_ctx->hwctx;
215  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
216  }
217 
218  if (!s->window && user_ctx && user_ctx->surface)
219  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
220 
221  if (!s->window) {
222  ret = AVERROR(EINVAL);
223  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
224  goto bailout;
225  }
226  /* Although there is a method ANativeWindow_toSurface() introduced in
227  * API level 26, it's easier and safe to always require a Surface for
228  * Java MediaCodec.
229  */
230  if (!s->use_ndk_codec && !s->window->surface) {
231  ret = AVERROR(EINVAL);
232  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
233  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
234  goto bailout;
235  }
236  }
237 
238  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
239  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
240  ff_AMediaFormat_setInt32(format, "color-format",
242  break;
243  }
244  }
245 
246  if (avctx->bit_rate)
247  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
248  if (s->bitrate_mode >= 0)
249  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
250  // frame-rate and i-frame-interval are required to configure codec
251  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
252  s->fps = avctx->framerate.num / avctx->framerate.den;
253  } else {
254  s->fps = 30;
255  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
256  }
257  gop = round(avctx->gop_size / s->fps);
258  if (gop == 0) {
259  gop = 1;
260  av_log(avctx, AV_LOG_INFO,
261  "Use %d as the default MediaFormat i-frame-interval, "
262  "please set gop_size properly (>= fps)\n", gop);
263  } else {
264  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
265  }
266 
267  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
268  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
269 
271  if (ret > 0) {
272  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
273  ff_AMediaFormat_setInt32(format, "profile", ret);
274  }
275  if (s->level > 0) {
276  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
277  ff_AMediaFormat_setInt32(format, "level", s->level);
278  }
279  if (avctx->max_b_frames > 0) {
281  av_log(avctx, AV_LOG_ERROR,
282  "Enabling B frames will produce packets with no DTS. "
283  "Use -strict experimental to use it anyway.\n");
284  ret = AVERROR(EINVAL);
285  goto bailout;
286  }
287  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
288  }
289  if (s->pts_as_dts == -1)
290  s->pts_as_dts = avctx->max_b_frames <= 0;
291 
293  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
294  if (ret) {
295  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
296  goto bailout;
297  }
298 
299  ret = ff_AMediaCodec_start(s->codec);
300  if (ret) {
301  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n", av_err2str(ret));
302  goto bailout;
303  }
304 
305  ret = mediacodec_init_bsf(avctx);
306  if (ret)
307  goto bailout;
308 
310 
311  s->frame = av_frame_alloc();
312  if (!s->frame)
313  ret = AVERROR(ENOMEM);
314 
315 bailout:
316  if (format)
318  return ret;
319 }
320 
322  AVPacket *pkt,
323  int *got_packet)
324 {
325  MediaCodecEncContext *s = avctx->priv_data;
326  FFAMediaCodec *codec = s->codec;
327  FFAMediaCodecBufferInfo out_info = {0};
328  uint8_t *out_buf;
329  size_t out_size = 0;
330  int ret;
331  int extradata_size = 0;
332  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
333  ssize_t index = ff_AMediaCodec_dequeueOutputBuffer(codec, &out_info, timeout_us);
334 
336  return AVERROR(EAGAIN);
337 
340  return AVERROR(EAGAIN);
341  }
342 
345  return AVERROR(EAGAIN);
346  }
347 
348  if (index < 0)
349  return AVERROR_EXTERNAL;
350 
351  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
352  return AVERROR_EOF;
353 
354  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
355  if (!out_buf) {
357  goto bailout;
358  }
359 
360  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
361  ret = av_reallocp(&s->extradata, out_info.size);
362  if (ret)
363  goto bailout;
364 
365  s->extradata_size = out_info.size;
366  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
368  // try immediately
369  return mediacodec_receive(avctx, pkt, got_packet);
370  }
371 
372  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
373  if (ret < 0)
374  goto bailout;
375 
376  if (s->extradata_size) {
377  extradata_size = s->extradata_size;
378  s->extradata_size = 0;
379  memcpy(pkt->data, s->extradata, extradata_size);
380  }
381  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
383  if (s->pts_as_dts)
384  pkt->dts = pkt->pts;
385  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
387  ret = 0;
388  *got_packet = 1;
389 
390  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
391  " flags %d extradata %d\n",
392  pkt->pts, pkt->dts, pkt->flags, extradata_size);
393 
394 bailout:
396  return ret;
397 }
398 
399 static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
400 {
401  MediaCodecEncContext *s = avctx->priv_data;
402  uint8_t *dst_data[4] = {};
403  int dst_linesize[4] = {};
404  const uint8_t *src_data[4] = {
405  frame->data[0], frame->data[1], frame->data[2], frame->data[3]
406  };
407 
408  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
409  dst_data[0] = dst;
410  dst_data[1] = dst + s->width * s->height;
411  dst_data[2] = dst_data[1] + s->width * s->height / 4;
412 
413  dst_linesize[0] = s->width;
414  dst_linesize[1] = dst_linesize[2] = s->width / 2;
415  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
416  dst_data[0] = dst;
417  dst_data[1] = dst + s->width * s->height;
418 
419  dst_linesize[0] = s->width;
420  dst_linesize[1] = s->width;
421  } else {
422  av_assert0(0);
423  }
424 
425  av_image_copy(dst_data, dst_linesize, src_data, frame->linesize,
426  avctx->pix_fmt, avctx->width, avctx->height);
427 }
428 
429 static int mediacodec_send(AVCodecContext *avctx,
430  const AVFrame *frame) {
431  MediaCodecEncContext *s = avctx->priv_data;
432  FFAMediaCodec *codec = s->codec;
433  ssize_t index;
434  uint8_t *input_buf = NULL;
435  size_t input_size = 0;
436  int64_t pts = 0;
437  uint32_t flags = 0;
438  int64_t timeout_us;
439 
440  if (s->eof_sent)
441  return 0;
442 
443  if (s->window) {
444  if (!frame) {
445  s->eof_sent = 1;
447  }
448 
449  if (frame->data[3])
450  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
451  return 0;
452  }
453 
454  timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
455  index = ff_AMediaCodec_dequeueInputBuffer(codec, timeout_us);
457  return AVERROR(EAGAIN);
458 
459  if (index < 0) {
460  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
461  return AVERROR_EXTERNAL;
462  }
463 
464  if (frame) {
465  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
466  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
467 
468  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
469  } else {
471  s->eof_sent = 1;
472  }
473 
474  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
475  return 0;
476 }
477 
479 {
480  MediaCodecEncContext *s = avctx->priv_data;
481  int ret;
482  int got_packet = 0;
483 
484  // Return on three case:
485  // 1. Serious error
486  // 2. Got a packet success
487  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
488  while (1) {
489  if (s->bsf) {
490  ret = av_bsf_receive_packet(s->bsf, pkt);
491  if (!ret)
492  return 0;
493  if (ret != AVERROR(EAGAIN))
494  return ret;
495  }
496 
497  ret = mediacodec_receive(avctx, pkt, &got_packet);
498  if (s->bsf) {
499  if (!ret || ret == AVERROR_EOF)
500  ret = av_bsf_send_packet(s->bsf, pkt);
501  } else {
502  if (!ret)
503  return 0;
504  }
505 
506  if (ret != AVERROR(EAGAIN))
507  return ret;
508 
509  if (!s->frame->buf[0]) {
510  ret = ff_encode_get_frame(avctx, s->frame);
511  if (ret && ret != AVERROR_EOF)
512  return ret;
513  }
514 
515  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
516  if (!ret)
517  av_frame_unref(s->frame);
518  else if (ret != AVERROR(EAGAIN))
519  return ret;
520  }
521 
522  return 0;
523 }
524 
526 {
527  MediaCodecEncContext *s = avctx->priv_data;
528  if (s->codec) {
529  ff_AMediaCodec_stop(s->codec);
530  ff_AMediaCodec_delete(s->codec);
531  s->codec = NULL;
532  }
533 
534  if (s->window) {
535  ff_mediacodec_surface_unref(s->window, avctx);
536  s->window = NULL;
537  }
538 
539  av_bsf_free(&s->bsf);
540  av_frame_free(&s->frame);
541 
542  return 0;
543 }
544 
546  &(const AVCodecHWConfigInternal) {
547  .public = {
551  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
552  },
553  .hwaccel = NULL,
554  },
555  NULL
556 };
557 
558 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
559 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
560 #define COMMON_OPTION \
561  { "ndk_codec", "Use MediaCodec from NDK", \
562  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
563  { "codec_name", "Select codec by name", \
564  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
565  { "bitrate_mode", "Bitrate control method", \
566  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" }, \
567  { "cq", "Constant quality mode", \
568  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" }, \
569  { "vbr", "Variable bitrate mode", \
570  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" }, \
571  { "cbr", "Constant bitrate mode", \
572  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" }, \
573  { "cbr_fd", "Constant bitrate mode with frame drops", \
574  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" }, \
575  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
576  "since most of Android devices don't output B frames by default.", \
577  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
578 
579 
580 #define MEDIACODEC_ENCODER_CLASS(name) \
581 static const AVClass name ## _mediacodec_class = { \
582  .class_name = #name "_mediacodec", \
583  .item_name = av_default_item_name, \
584  .option = name ## _options, \
585  .version = LIBAVUTIL_VERSION_INT, \
586 }; \
587 
588 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
589 MEDIACODEC_ENCODER_CLASS(short_name) \
590 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
591  .p.name = #short_name "_mediacodec", \
592  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
593  .p.type = AVMEDIA_TYPE_VIDEO, \
594  .p.id = codec_id, \
595  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY \
596  | AV_CODEC_CAP_HARDWARE, \
597  .priv_data_size = sizeof(MediaCodecEncContext), \
598  .p.pix_fmts = avc_pix_fmts, \
599  .init = mediacodec_init, \
600  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
601  .close = mediacodec_close, \
602  .p.priv_class = &short_name ## _mediacodec_class, \
603  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
604  .p.wrapper_name = "mediacodec", \
605  .hw_configs = mediacodec_hw_configs, \
606 }; \
607 
608 #if CONFIG_H264_MEDIACODEC_ENCODER
609 
610 enum MediaCodecAvcLevel {
611  AVCLevel1 = 0x01,
612  AVCLevel1b = 0x02,
613  AVCLevel11 = 0x04,
614  AVCLevel12 = 0x08,
615  AVCLevel13 = 0x10,
616  AVCLevel2 = 0x20,
617  AVCLevel21 = 0x40,
618  AVCLevel22 = 0x80,
619  AVCLevel3 = 0x100,
620  AVCLevel31 = 0x200,
621  AVCLevel32 = 0x400,
622  AVCLevel4 = 0x800,
623  AVCLevel41 = 0x1000,
624  AVCLevel42 = 0x2000,
625  AVCLevel5 = 0x4000,
626  AVCLevel51 = 0x8000,
627  AVCLevel52 = 0x10000,
628  AVCLevel6 = 0x20000,
629  AVCLevel61 = 0x40000,
630  AVCLevel62 = 0x80000,
631 };
632 
633 static const AVOption h264_options[] = {
635  { "level", "Specify level",
636  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
637  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, "level" },
638  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, "level" },
639  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, "level" },
640  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, "level" },
641  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, "level" },
642  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, "level" },
643  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, "level" },
644  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, "level" },
645  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, "level" },
646  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, "level" },
647  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, "level" },
648  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, "level" },
649  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, "level" },
650  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, "level" },
651  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, "level" },
652  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, "level" },
653  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, "level" },
654  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, "level" },
655  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, "level" },
656  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, "level" },
657  { NULL, }
658 };
659 
661 
662 #endif // CONFIG_H264_MEDIACODEC_ENCODER
663 
664 #if CONFIG_HEVC_MEDIACODEC_ENCODER
665 
666 enum MediaCodecHevcLevel {
667  HEVCMainTierLevel1 = 0x1,
668  HEVCHighTierLevel1 = 0x2,
669  HEVCMainTierLevel2 = 0x4,
670  HEVCHighTierLevel2 = 0x8,
671  HEVCMainTierLevel21 = 0x10,
672  HEVCHighTierLevel21 = 0x20,
673  HEVCMainTierLevel3 = 0x40,
674  HEVCHighTierLevel3 = 0x80,
675  HEVCMainTierLevel31 = 0x100,
676  HEVCHighTierLevel31 = 0x200,
677  HEVCMainTierLevel4 = 0x400,
678  HEVCHighTierLevel4 = 0x800,
679  HEVCMainTierLevel41 = 0x1000,
680  HEVCHighTierLevel41 = 0x2000,
681  HEVCMainTierLevel5 = 0x4000,
682  HEVCHighTierLevel5 = 0x8000,
683  HEVCMainTierLevel51 = 0x10000,
684  HEVCHighTierLevel51 = 0x20000,
685  HEVCMainTierLevel52 = 0x40000,
686  HEVCHighTierLevel52 = 0x80000,
687  HEVCMainTierLevel6 = 0x100000,
688  HEVCHighTierLevel6 = 0x200000,
689  HEVCMainTierLevel61 = 0x400000,
690  HEVCHighTierLevel61 = 0x800000,
691  HEVCMainTierLevel62 = 0x1000000,
692  HEVCHighTierLevel62 = 0x2000000,
693 };
694 
695 static const AVOption hevc_options[] = {
697  { "level", "Specify tier and level",
698  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
699  { "m1", "Main tier level 1",
700  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, "level" },
701  { "h1", "High tier level 1",
702  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, "level" },
703  { "m2", "Main tier level 2",
704  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, "level" },
705  { "h2", "High tier level 2",
706  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, "level" },
707  { "m2.1", "Main tier level 2.1",
708  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, "level" },
709  { "h2.1", "High tier level 2.1",
710  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, "level" },
711  { "m3", "Main tier level 3",
712  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, "level" },
713  { "h3", "High tier level 3",
714  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, "level" },
715  { "m3.1", "Main tier level 3.1",
716  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, "level" },
717  { "h3.1", "High tier level 3.1",
718  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, "level" },
719  { "m4", "Main tier level 4",
720  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, "level" },
721  { "h4", "High tier level 4",
722  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, "level" },
723  { "m4.1", "Main tier level 4.1",
724  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, "level" },
725  { "h4.1", "High tier level 4.1",
726  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, "level" },
727  { "m5", "Main tier level 5",
728  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, "level" },
729  { "h5", "High tier level 5",
730  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, "level" },
731  { "m5.1", "Main tier level 5.1",
732  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, "level" },
733  { "h5.1", "High tier level 5.1",
734  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, "level" },
735  { "m5.2", "Main tier level 5.2",
736  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, "level" },
737  { "h5.2", "High tier level 5.2",
738  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, "level" },
739  { "m6", "Main tier level 6",
740  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, "level" },
741  { "h6", "High tier level 6",
742  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, "level" },
743  { "m6.1", "Main tier level 6.1",
744  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, "level" },
745  { "h6.1", "High tier level 6.1",
746  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, "level" },
747  { "m6.2", "Main tier level 6.2",
748  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, "level" },
749  { "h6.2", "High tier level 6.2",
750  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, "level" },
751  { NULL, }
752 };
753 
755 
756 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
MediaCodecEncContext
Definition: mediacodecenc.c:54
ff_AMediaCodec_getInputBuffer
static uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:261
hwconfig.h
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
AVCodecContext::hwaccel_context
void * hwaccel_context
Legacy hardware accelerator context.
Definition: avcodec.h:1429
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:92
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:256
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
level
uint8_t level
Definition: svq3.c:204
MediaCodecEncContext::pts_as_dts
int pts_as_dts
Definition: mediacodecenc.c:74
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:588
ff_AMediaCodec_start
static int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:241
FFAMediaCodecBufferInfo::offset
int32_t offset
Definition: mediacodec_wrapper.h:173
MediaCodecEncContext::avclass
AVClass * avclass
Definition: mediacodecenc.c:55
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
color_format
int color_format
Definition: mediacodecenc.c:84
BITRATE_MODE_VBR
@ BITRATE_MODE_VBR
Definition: mediacodecenc.c:47
AVMediaCodecDeviceContext::surface
void * surface
android/view/Surface handle, to be filled by the user.
Definition: hwcontext_mediacodec.h:33
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:61
out_size
int out_size
Definition: movenc.c:55
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:99
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
ff_AMediaCodec_signalEndOfInputStream
static int ff_AMediaCodec_signalEndOfInputStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:341
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:59
AVPacket::data
uint8_t * data
Definition: packet.h:374
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:150
BitrateMode
BitrateMode
Definition: mediacodecenc.c:43
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:311
AVOption
AVOption.
Definition: opt.h:251
encode.h
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:306
AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition: hwcontext.h:38
ff_AMediaCodec_queueInputBuffer
static int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.h:276
MediaCodecEncContext::eof_sent
int eof_sent
Definition: mediacodecenc.c:67
COMMON_OPTION
#define COMMON_OPTION
Definition: mediacodecenc.c:560
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:478
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
hwcontext_mediacodec.h
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:53
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
VE
#define VE
Definition: mediacodecenc.c:559
mediacodec_output_format
static void mediacodec_output_format(AVCodecContext *avctx)
Definition: mediacodecenc.c:99
ff_AMediaCodec_configure
static int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:233
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1750
bsf.h
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:525
MediaCodecEncContext::extradata
uint8_t * extradata
Definition: mediacodecenc.c:65
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecenc.c:85
AVERROR_BUFFER_TOO_SMALL
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:53
pts
static int64_t pts
Definition: transcode_aac.c:653
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2485
AVRational::num
int num
Numerator.
Definition: rational.h:59
mediacodecdec_common.h
mediacodec_receive
static int mediacodec_receive(AVCodecContext *avctx, AVPacket *pkt, int *got_packet)
Definition: mediacodecenc.c:321
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:87
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:429
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
MediaCodecEncContext::bitrate_mode
int bitrate_mode
Definition: mediacodecenc.c:72
ff_AMediaCodec_getName
static char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:224
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:321
s
#define s(width, name)
Definition: cbs_vp9.c:256
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2778
BITRATE_MODE_CQ
@ BITRATE_MODE_CQ
Definition: mediacodecenc.c:45
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
OFFSET
#define OFFSET(x)
Definition: mediacodecenc.c:558
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:347
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:66
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
MediaCodecEncContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecenc.c:57
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:313
OUTPUT_DEQUEUE_TIMEOUT_US
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:41
ff_AMediaCodec_getOutputFormat
static FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:286
MediaCodecEncContext::level
int level
Definition: mediacodecenc.c:73
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:150
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2492
NULL
#define NULL
Definition: coverity.c:32
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:231
FFAMediaCodecBufferInfo::size
int32_t size
Definition: mediacodec_wrapper.h:174
AVMediaCodecContext
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
Definition: mediacodec.h:33
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:80
color_formats
static const struct @111 color_formats[]
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:476
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2506
ff_AMediaCodec_stop
static int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:246
ff_mediacodec_surface_unref
int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
Definition: mediacodec_surface.c:59
BITRATE_MODE_CBR_FD
@ BITRATE_MODE_CBR_FD
Definition: mediacodecenc.c:51
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:326
BITRATE_MODE_CBR
@ BITRATE_MODE_CBR
Definition: mediacodecenc.c:49
index
int index
Definition: gxfenc.c:89
AVMediaCodecDeviceContext
MediaCodec details.
Definition: hwcontext_mediacodec.h:27
ff_AMediaFormat_toString
static char * ff_AMediaFormat_toString(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:97
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:548
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:620
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1048
codec_internal.h
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:203
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
avc_pix_fmts
static enum AVPixelFormat avc_pix_fmts[]
Definition: mediacodecenc.c:92
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:186
AVCodecHWConfigInternal
Definition: hwconfig.h:29
MediaCodecEncContext::bsf
AVBSFContext * bsf
Definition: mediacodecenc.c:70
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_AMediaCodecProfile_getProfileFromAVCodecContext
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
Definition: mediacodec_wrapper.c:303
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:58
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
MediaCodecEncContext::width
int width
Definition: mediacodecenc.c:62
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:331
MediaCodecEncContext::codec
FFAMediaCodec * codec
Definition: mediacodecenc.c:56
FFANativeWindow
Definition: mediacodec_surface.h:28
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
mediacodec_wrapper.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
FFAMediaCodec
Definition: mediacodec_wrapper.h:181
MediaCodecEncContext::height
int height
Definition: mediacodecenc.c:63
MediaCodecEncContext::extradata_size
int extradata_size
Definition: mediacodecenc.c:66
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:478
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:176
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1928
AVMediaCodecContext::surface
void * surface
android/view/Surface object reference.
Definition: mediacodec.h:38
ff_mediacodec_surface_ref
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
Definition: mediacodec_surface.c:30
MediaCodecEncContext::frame
AVFrame * frame
Definition: mediacodecenc.c:69
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:40
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:74
AVMediaCodecDeviceContext::native_window
void * native_window
Pointer to ANativeWindow.
Definition: hwcontext_mediacodec.h:45
FFAMediaCodecBufferInfo::presentationTimeUs
int64_t presentationTimeUs
Definition: mediacodec_wrapper.h:175
ff_AMediaCodec_dequeueInputBuffer
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:271
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:79
AV_PIX_FMT_NV12
@ 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:89
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:335
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1341
av_mediacodec_release_buffer
int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render)
Release a MediaCodec buffer and render it to the surface that is associated with the decoder.
Definition: mediacodec.c:138
AVCodecContext
main external API structure.
Definition: avcodec.h:426
av_image_copy
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:422
mediacodec_init
static av_cold int mediacodec_init(AVCodecContext *avctx)
Definition: mediacodecenc.c:149
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:79
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
ff_AMediaCodec_getBufferFlagCodecConfig
static int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:316
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:527
AVCodecContext::max_b_frames
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...
Definition: avcodec.h:697
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:183
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:266
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ff_AMediaCodec_cleanOutputBuffers
static int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:336
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:301
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
convert_header.str
string str
Definition: convert_header.py:20
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:306
ff_AMediaCodec_releaseOutputBuffer
static int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h:291
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
jni.h
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:78
mediacodec_hw_configs
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
Definition: mediacodecenc.c:545
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:79
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
ff_AMediaCodec_dequeueOutputBuffer
static ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:281
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
copy_frame_to_buffer
static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
Definition: mediacodecenc.c:399
mediacodec_init_bsf
static int mediacodec_init_bsf(AVCodecContext *avctx)
Definition: mediacodecenc.c:113
mediacodec.h