From 5d504f1267d1f03408b8633b44f4c6e2d1f3d7c9 Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 18 May 2024 17:43:01 +0300 Subject: [PATCH] Remove 16px resolution alignment from MediaCodec More details: https://trac.ffmpeg.org/ticket/11010 --- scripts/android/ffmpeg.sh | 4 +++ tools/patch/cpp/ffmpeg/mediacodecenc.c.patch | 32 ++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tools/patch/cpp/ffmpeg/mediacodecenc.c.patch diff --git a/scripts/android/ffmpeg.sh b/scripts/android/ffmpeg.sh index 23ded93..86900fe 100755 --- a/scripts/android/ffmpeg.sh +++ b/scripts/android/ffmpeg.sh @@ -478,6 +478,10 @@ if [[ $? -ne 0 ]]; then exit 1 fi +patch "${BASEDIR}"/src/ffmpeg/libavcodec/mediacodecenc.c \ + "${BASEDIR}"/tools/patch/cpp/ffmpeg/mediacodecenc.c.patch \ + -N -r /dev/null || true 1>> build.log 2>&1 + if [[ -z ${NO_OUTPUT_REDIRECTION} ]]; then make -j$(get_cpu_count) 1>>"${BASEDIR}"/build.log 2>&1 diff --git a/tools/patch/cpp/ffmpeg/mediacodecenc.c.patch b/tools/patch/cpp/ffmpeg/mediacodecenc.c.patch new file mode 100644 index 0000000..de3ba16 --- /dev/null +++ b/tools/patch/cpp/ffmpeg/mediacodecenc.c.patch @@ -0,0 +1,32 @@ +diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c +index 984014f..f2e5ab1 100644 +--- a/libavcodec/mediacodecenc.c ++++ b/libavcodec/mediacodecenc.c +@@ -198,19 +198,14 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) + } + + ff_AMediaFormat_setString(format, "mime", codec_mime); +- // Workaround the alignment requirement of mediacodec. We can't do it +- // silently for AV_PIX_FMT_MEDIACODEC. +- if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) { +- s->width = FFALIGN(avctx->width, 16); +- s->height = FFALIGN(avctx->height, 16); +- } else { +- s->width = avctx->width; +- s->height = avctx->height; +- if (s->width % 16 || s->height % 16) +- av_log(avctx, AV_LOG_WARNING, +- "Video size %dx%d isn't align to 16, it may have device compatibility issue\n", +- s->width, s->height); +- } ++ ++ s->width = avctx->width; ++ s->height = avctx->height; ++ if (s->width % 16 || s->height % 16) ++ av_log(avctx, AV_LOG_WARNING, ++ "Video size %dx%d isn't align to 16, it may have device compatibility issue\n", ++ s->width, s->height); ++ + ff_AMediaFormat_setInt32(format, "width", s->width); + ff_AMediaFormat_setInt32(format, "height", s->height); +