Commit Graph

32 Commits

Author SHA1 Message Date
Zhao Zhili cf4af4bca0 avcodec/mediacodecenc: Flush bsf after create extradata
Avoid leaving any data inside bsf while also avoid keep bsf in
EOF state.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-29 15:58:48 +08:00
Zhao Zhili 66161166dc avcodec/mediacodecenc: add AV_CODEC_CAP_ENCODER_FLUSH support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili 9e49915195 avcodec/mediacodecenc: Add global header support
The extradata is generated by encoding a dummy frame, then reset
the encoder state by mediacodec flush(). It only works for pixel
format other than AV_PIX_FMT_MEDIACODEC, since I'm not sure how
to create a dummy frame safely with AV_PIX_FMT_MEDIACODEC.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili 3cfea6993a avcodec/mediacodecenc: Remove write only variable
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili a5a3788f56 avcodec/mediacodecenc: Fix return empty packet when bsf is used
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Zhao Zhili b0e17e0f95 avcodec/mediacodecenc: Add a hint message to use nv12 pix_fmt
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-03-05 21:25:56 +08:00
Anton Khirnov 1e7d2007c3 all: use designated initializers for AVOption.unit
Makes it robust against adding fields before it, which will be useful in
following commits.

Majority of the patch generated by the following Coccinelle script:

@@
typedef AVOption;
identifier arr_name;
initializer list il;
initializer list[8] il1;
expression tail;
@@
AVOption arr_name[] = { il, { il1,
- tail
+ .unit = tail
}, ...  };

with some manual changes, as the script:
* has trouble with options defined inside macros
* sometimes does not handle options under an #else branch
* sometimes swallows whitespace
2024-02-14 14:53:41 +01:00
Anton Khirnov 08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Andreas Rheinhardt 0c6203c97a all: Don't set AVClass.item_name to its default value
Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-12-22 15:12:33 +01:00
Zhao Zhili 287e22f745 avcodec/mediacodecenc: set quality in cq mode
From AOSP doc, these values are device and codec specific, but lower
values generally result in more efficient (smaller-sized) encoding.

For example, global_quality 50 on Pixel 6 results a 1080P 30 FPS
HEVC with 3744 kb/s, while global_quality 80 results 28178 kb/s.

Fix #10689

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-12-21 19:28:47 +08:00
Andreas Rheinhardt 423b6a7e49 avutil/imgutils: Add wrapper for av_image_copy() to avoid casts
av_image_copy() accepts const uint8_t* const * as source;
lots of user have uint8_t* const * and therefore either
cast (the majority) or copy the array of pointers.

This commit changes this by adding a static inline wrapper
for av_image_copy() that casts between the two types
so that we do not need to add casts everywhere else.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-12 09:42:27 +02:00
Andreas Rheinhardt 8238bc0b5e avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* defines
These defines are also used in other contexts than just AVCodecContext
ones, e.g. in libavformat. Furthermore, given that these defines are
public, the AV-prefix is the right one, so deprecate (and not just move)
the FF-macros.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:39:02 +02:00
Zhao Zhili fb85aa959a avcodec/mediacodecenc: add profile names to options
H.264 high10/high422/high44 are unlikely supported by devices.
It's there for developers to do the experiment.

H.265 main10 works on my device with AV_PIX_FMT_MEDIACODEC.
OMX_COLOR_FormatYUV420Planar16 doesn't work.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-06-19 12:19:29 +08:00
Samuel Mira 416fd1b43b avcodec/mediacodec: Add VP8 encoder
Connected FFmpeg to Mediacodec VP8 encoder.

Signed-off-by: Samuel Mira <samuel.mira@qt.io>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-05-17 19:20:57 +08:00
Samuel Mira acd37fd566 avcodec/mediacodec: Add AV1 encoder
Connected FFmpeg to Mediacodec AV1 encoder

Signed-off-by: Samuel Mira <samuel.mira@qt.io>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-05-17 19:19:51 +08:00
Zhao Zhili 862a626c9d avcodec/mediacodecenc: warning when global header is requested.
Add suggests to use extract_extradata bsf.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-09 21:44:29 +08:00
Samuel Raposo Vieira Mira b4eca5cce2 avcodec/mediacodec: add mpeg4 encoder
This patch will add MPEG4 encoder using Android Mediacodec

Signed-off-by: Samuel Mira <samuel.mira@qt.io<mailto:samuel.mira@qt.io>>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-02 15:10:15 +08:00
Samuel Raposo Vieira Mira 139f3352ed avcodec/mediacodec: add vp9 encoder using mediacodec
The only encoders avaliable using mediacodec were h264 and hevc. This
patch adds the vp9 encoder.

Signed-off-by: Samuel Mira <samuel.mira@qt.io<mailto:samuel.mira@qt.io>>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-04-02 15:09:45 +08:00
Zhao Zhili f543f12817 avcodec/mediacodecenc: pass colorspace info to encoder
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-03-18 00:13:17 +08:00
Zhao Zhili a598be44df avcodec/mediacodecenc: enable B frames only with -strict experimental
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-09 19:21:57 +08:00
Zhao Zhili 10a56363a7 avcodec/mediacodecenc: add pts_as_dts option
It works since most of Android devices don't output B frames by
default. The behavior is documented by Android now, although there
is some exception in history, which should have been fixed now.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:32:57 +08:00
Zhao Zhili a86bb1d2ce avcodec/mediacodecenc: add max-bframes support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:31:04 +08:00
Zhao Zhili 7da1adfc02 avcodec/mediacodecenc: remove the strategy to create DTS
Use input PTS as DTS has multiple problems:
1. If there is no reordering, it's better to just use the output
PTS as DTS, since encoder may change the timestamp value (do it
on purpose or rounding error).

2. If there is reordering, input PTS should be shift a few frames
as DTS to satisfy the requirement of PTS >= DTS. I can't find a
reliable way to determine how many frames to be shift. For example,
we don't known if the encoder use hierarchical B frames. The
max_num_reorder_frames can be get from VUI, but VUI is optional.

3. Encoder dropping frames makes the case worse. Android has an
BITRATE_MODE_CBR_FD option to allow it explicitly.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:30:36 +08:00
Zhao Zhili e3f2d01d70 avcodec/mediacodecenc: use bsf to handle crop
It's well known that mediacodec encoder requires 16x16 alignment.
Use our bsf to fix the crop info.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:28:27 +08:00
Zhao Zhili f0c296f578 avcodec/mediacodecenc: add level option
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:27:43 +08:00
Zhao Zhili 2b5d1b423a avcodec/mediacodecenc: add bitrate_mode option
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:27:00 +08:00
Zhao Zhili 0a0f2d1a8c avcodec/mediacodecenc: make each encoder has its own option
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-17 04:24:56 +08:00
Zhao Zhili 2401494e96 avcodec/mediacodecenc: configure profile
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-08 23:55:37 +08:00
Zhao Zhili 3dcb630ca1 avcodec/mediacodecenc: add option to select codec by name
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-08 23:54:50 +08:00
Zhao Zhili 567633895b avcodec/mediacodecenc: check missing Surface
It's an invalid combination of Java MediaCodec with ANativeWindow.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-12-08 23:53:20 +08:00
Zhao Zhili 0ff18a7d6d avcodec: add MediaCodec encoder
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-11-21 23:56:16 +08:00