Re: [FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder

2023-05-16 Thread zhilizhao(赵志立)
Pushed as acd37fd.

> On May 17, 2023, at 00:26, Samuel Raposo Vieira Mira  
> wrote:
> 
> 
> 
> <0001-avcodec-mediacodec-Add-AV1-encoder.patch><0001-avcodec-mediacodec-Add-AV1-encoder.patch.b64>___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder

2023-05-16 Thread Samuel Raposo Vieira Mira





0001-avcodec-mediacodec-Add-AV1-encoder.patch
Description: 0001-avcodec-mediacodec-Add-AV1-encoder.patch


0001-avcodec-mediacodec-Add-AV1-encoder.patch.b64
Description: 0001-avcodec-mediacodec-Add-AV1-encoder.patch.b64
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder

2023-05-16 Thread Samuel Raposo Vieira Mira
All comments done. Thanks for the review :)

> By the way, which hardware did you use to run the test?
I used a Samsung S21 and a Pixel 6.



From: Zhao Zhili 
Date: Sunday, 7. May 2023 at 11.57
To: Samuel Raposo Vieira Mira , FFmpeg development 
discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder
On Tue, 2023-05-02 at 12:22 +, Samuel Raposo Vieira Mira wrote:
> @@ -3162,6 +3162,7 @@ aac_mf_encoder_deps="mediafoundation"
> ac3_mf_encoder_deps="mediafoundation"
> av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
> av1_mediacodec_decoder_deps="mediacodec"
> +av1_mediacodec_encoder_deps="mediacodec"

This patch format is broken too.

>
> diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
> index 1c29bb7406..015f275a0f 100644
> --- a/libavcodec/mediacodec_wrapper.c
> +++ b/libavcodec/mediacodec_wrapper.c
> @@ -35,6 +35,8 @@
> #include "ffjni.h"
> #include "mediacodec_wrapper.h"
> +#include "libavutil/pixdesc.h"
> +

Please keep the include in some order.

> struct JNIAMediaCodecListFields {
>  jclass mediacodec_list_class;
> @@ -345,6 +347,11 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  static const int MPEG4ProfileAdvancedScalable = 0x4000;
>  static const int MPEG4ProfileAdvancedSimple   = 0x8000;

Missing an empty line between MPEG4 and AV1.

> +static const int AV1ProfileMain8  = 0x1;
> +static const int AV1ProfileMain10 = 0x2;
> +static const int AV1ProfileMain10HDR10 = 0x1000;
> +static const int AV1ProfileMain10HDR10Plus = 0x2000;
> +
>  // Unused yet.
>  (void)AVCProfileConstrainedHigh;
>  (void)HEVCProfileMain10HDR10;
> @@ -353,6 +360,8 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  (void)VP9Profile3HDR;
>  (void)VP9Profile2HDR10Plus;
>  (void)VP9Profile3HDR10Plus;
> +(void)AV1ProfileMain10HDR10;
> +(void)AV1ProfileMain10HDR10Plus;
>  if (avctx->codec_id == AV_CODEC_ID_H264) {
>  switch(avctx->profile) {
> @@ -436,6 +445,9 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  default:
>  break;
>  }
> +} else if(avctx->codec_id == AV_CODEC_ID_AV1) {
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
> +return desc != NULL && desc->comp[0].depth == 8? AV1ProfileMain8 : 
> AV1ProfileMain10;
>  }

I'm not sure about how mediacodec handles 10bit encoding and
need some tests. Let's keep the function simple first by just
map avctx->profile to MediaCodec profile.

>  return -1;
> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
> index e4b583a542..10da43c3e7 100644
> --- a/libavcodec/mediacodecenc.c
> +++ b/libavcodec/mediacodecenc.c
> @@ -170,6 +170,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
>  case AV_CODEC_ID_MPEG4:
>  codec_mime = "video/mp4v-es";
>  break;
> +case AV_CODEC_ID_AV1:
> +codec_mime = "video/av01";
> +break;
>  default:
>  av_assert0(0);
>  }
> @@ -779,16 +782,16 @@ DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", 
> AV_CODEC_ID_HEVC)
>  enum MediaCodecVP9Level {
>  VP9Level1  = 0x1,
> -VP9Level11  = 0x2,
> +VP9Level11 = 0x2,
>  VP9Level2  = 0x4,
> -VP9Level21  = 0x8,
> -VP9Level3 = 0x10,
> +VP9Level21 = 0x8,
> +VP9Level3  = 0x10,
>  VP9Level31 = 0x20,
>  VP9Level4  = 0x40,
> -VP9Level41  = 0x80,
> -VP9Level5 = 0x100,
> +VP9Level41 = 0x80,
> +VP9Level5  = 0x100,
>  VP9Level51 = 0x200,
> -VP9Level52  = 0x400,
> +VP9Level52 = 0x400,
>  VP9Level6  = 0x800,
>  VP9Level61 = 0x1000,
>  VP9Level62 = 0x2000,
> @@ -837,15 +840,15 @@ DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9)
>  enum MediaCodecMpeg4Level {
>  MPEG4Level0  = 0x01,
> -MPEG4Level0b  = 0x02,
> -MPEG4Level1 = 0x04,
> +MPEG4Level0b = 0x02,
> +MPEG4Level1  = 0x04,
>  MPEG4Level2  = 0x08,
> -MPEG4Level3 = 0x10,
> +MPEG4Level3  = 0x10,
>  MPEG4Level3b = 0x18,
> -MPEG4Level4 = 0x20,
> -MPEG4Level4a  = 0x40,
> +MPEG4Level4  = 0x20,
> +MPEG4Level4a = 0x40,
>  MPEG4Level5  = 0x80,
> -MPEG4Level6 = 0x100,
> +MPEG4Level6  = 0x100,
> };

Don't do unrelated code format in this patch.


By the way, which hardware did you use to run the test?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder

2023-05-07 Thread Zhao Zhili
On Tue, 2023-05-02 at 12:22 +, Samuel Raposo Vieira Mira wrote:
> @@ -3162,6 +3162,7 @@ aac_mf_encoder_deps="mediafoundation"
> ac3_mf_encoder_deps="mediafoundation"
> av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
> av1_mediacodec_decoder_deps="mediacodec"
> +av1_mediacodec_encoder_deps="mediacodec"

This patch format is broken too.

> 
> diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
> index 1c29bb7406..015f275a0f 100644
> --- a/libavcodec/mediacodec_wrapper.c
> +++ b/libavcodec/mediacodec_wrapper.c
> @@ -35,6 +35,8 @@
> #include "ffjni.h"
> #include "mediacodec_wrapper.h"
> +#include "libavutil/pixdesc.h"
> +

Please keep the include in some order.

> struct JNIAMediaCodecListFields {
>  jclass mediacodec_list_class;
> @@ -345,6 +347,11 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  static const int MPEG4ProfileAdvancedScalable = 0x4000;
>  static const int MPEG4ProfileAdvancedSimple   = 0x8000;

Missing an empty line between MPEG4 and AV1.

> +static const int AV1ProfileMain8  = 0x1;
> +static const int AV1ProfileMain10 = 0x2;
> +static const int AV1ProfileMain10HDR10 = 0x1000;
> +static const int AV1ProfileMain10HDR10Plus = 0x2000;
> +
>  // Unused yet.
>  (void)AVCProfileConstrainedHigh;
>  (void)HEVCProfileMain10HDR10;
> @@ -353,6 +360,8 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  (void)VP9Profile3HDR;
>  (void)VP9Profile2HDR10Plus;
>  (void)VP9Profile3HDR10Plus;
> +(void)AV1ProfileMain10HDR10;
> +(void)AV1ProfileMain10HDR10Plus;
>  if (avctx->codec_id == AV_CODEC_ID_H264) {
>  switch(avctx->profile) {
> @@ -436,6 +445,9 @@ int 
> ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
>  default:
>  break;
>  }
> +} else if(avctx->codec_id == AV_CODEC_ID_AV1) {
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
> +return desc != NULL && desc->comp[0].depth == 8? AV1ProfileMain8 : 
> AV1ProfileMain10;
>  }

I'm not sure about how mediacodec handles 10bit encoding and
need some tests. Let's keep the function simple first by just
map avctx->profile to MediaCodec profile.

>  return -1;
> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
> index e4b583a542..10da43c3e7 100644
> --- a/libavcodec/mediacodecenc.c
> +++ b/libavcodec/mediacodecenc.c
> @@ -170,6 +170,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
>  case AV_CODEC_ID_MPEG4:
>  codec_mime = "video/mp4v-es";
>  break;
> +case AV_CODEC_ID_AV1:
> +codec_mime = "video/av01";
> +break;
>  default:
>  av_assert0(0);
>  }
> @@ -779,16 +782,16 @@ DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", 
> AV_CODEC_ID_HEVC)
>  enum MediaCodecVP9Level {
>  VP9Level1  = 0x1,
> -VP9Level11  = 0x2,
> +VP9Level11 = 0x2,
>  VP9Level2  = 0x4,
> -VP9Level21  = 0x8,
> -VP9Level3 = 0x10,
> +VP9Level21 = 0x8,
> +VP9Level3  = 0x10,
>  VP9Level31 = 0x20,
>  VP9Level4  = 0x40,
> -VP9Level41  = 0x80,
> -VP9Level5 = 0x100,
> +VP9Level41 = 0x80,
> +VP9Level5  = 0x100,
>  VP9Level51 = 0x200,
> -VP9Level52  = 0x400,
> +VP9Level52 = 0x400,
>  VP9Level6  = 0x800,
>  VP9Level61 = 0x1000,
>  VP9Level62 = 0x2000,
> @@ -837,15 +840,15 @@ DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9)
>  enum MediaCodecMpeg4Level {
>  MPEG4Level0  = 0x01,
> -MPEG4Level0b  = 0x02,
> -MPEG4Level1 = 0x04,
> +MPEG4Level0b = 0x02,
> +MPEG4Level1  = 0x04,
>  MPEG4Level2  = 0x08,
> -MPEG4Level3 = 0x10,
> +MPEG4Level3  = 0x10,
>  MPEG4Level3b = 0x18,
> -MPEG4Level4 = 0x20,
> -MPEG4Level4a  = 0x40,
> +MPEG4Level4  = 0x20,
> +MPEG4Level4a = 0x40,
>  MPEG4Level5  = 0x80,
> -MPEG4Level6 = 0x100,
> +MPEG4Level6  = 0x100,
> };

Don't do unrelated code format in this patch.


By the way, which hardware did you use to run the test?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avcodec/mediacodec: Add AV1 encoder

2023-05-02 Thread Samuel Raposo Vieira Mira
Connected FFmpeg to Mediacodec AV1 encoder
Minor version bump.
Minor whitespaces fix.

Signed-off-by: Samuel Mira samuel.m...@qt.io
---
configure   |   1 +
libavcodec/Makefile |   1 +
libavcodec/allcodecs.c  |   1 +
libavcodec/mediacodec_wrapper.c |  12 
libavcodec/mediacodecenc.c  | 115 
libavcodec/version.h|   2 +-
6 files changed, 119 insertions(+), 13 deletions(-)

diff --git a/configure b/configure
index bb7be67676..0a60deac65 100755
--- a/configure
+++ b/configure
@@ -3162,6 +3162,7 @@ aac_mf_encoder_deps="mediafoundation"
ac3_mf_encoder_deps="mediafoundation"
av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
av1_mediacodec_decoder_deps="mediacodec"
+av1_mediacodec_encoder_deps="mediacodec"
av1_nvenc_encoder_deps="nvenc NV_ENC_PIC_PARAMS_AV1"
av1_nvenc_encoder_select="atsc_a53"
h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b0971ce833..166f77f12a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -253,6 +253,7 @@ OBJS-$(CONFIG_AURA2_DECODER)   += aura.o
OBJS-$(CONFIG_AV1_DECODER) += av1dec.o
OBJS-$(CONFIG_AV1_CUVID_DECODER)   += cuviddec.o
OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER)  += mediacodecdec.o
+OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER)  += mediacodecenc.o
OBJS-$(CONFIG_AV1_NVENC_ENCODER)   += nvenc_av1.o nvenc.o
OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
OBJS-$(CONFIG_AVRN_DECODER)+= avrndec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8eeed34e57..f583aad860 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -836,6 +836,7 @@ extern const FFCodec ff_libaom_av1_decoder;
extern const FFCodec ff_av1_decoder;
extern const FFCodec ff_av1_cuvid_decoder;
extern const FFCodec ff_av1_mediacodec_decoder;
+extern const FFCodec ff_av1_mediacodec_encoder;
extern const FFCodec ff_av1_nvenc_encoder;
extern const FFCodec ff_av1_qsv_decoder;
extern const FFCodec ff_av1_qsv_encoder;
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 1c29bb7406..015f275a0f 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -35,6 +35,8 @@
#include "ffjni.h"
#include "mediacodec_wrapper.h"
+#include "libavutil/pixdesc.h"
+
struct JNIAMediaCodecListFields {
 jclass mediacodec_list_class;
@@ -345,6 +347,11 @@ int 
ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
 static const int MPEG4ProfileAdvancedScalable = 0x4000;
 static const int MPEG4ProfileAdvancedSimple   = 0x8000;
+static const int AV1ProfileMain8  = 0x1;
+static const int AV1ProfileMain10 = 0x2;
+static const int AV1ProfileMain10HDR10 = 0x1000;
+static const int AV1ProfileMain10HDR10Plus = 0x2000;
+
 // Unused yet.
 (void)AVCProfileConstrainedHigh;
 (void)HEVCProfileMain10HDR10;
@@ -353,6 +360,8 @@ int 
ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
 (void)VP9Profile3HDR;
 (void)VP9Profile2HDR10Plus;
 (void)VP9Profile3HDR10Plus;
+(void)AV1ProfileMain10HDR10;
+(void)AV1ProfileMain10HDR10Plus;
 if (avctx->codec_id == AV_CODEC_ID_H264) {
 switch(avctx->profile) {
@@ -436,6 +445,9 @@ int 
ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
 default:
 break;
 }
+} else if(avctx->codec_id == AV_CODEC_ID_AV1) {
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+return desc != NULL && desc->comp[0].depth == 8? AV1ProfileMain8 : 
AV1ProfileMain10;
 }
 return -1;
diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index e4b583a542..10da43c3e7 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -170,6 +170,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 case AV_CODEC_ID_MPEG4:
 codec_mime = "video/mp4v-es";
 break;
+case AV_CODEC_ID_AV1:
+codec_mime = "video/av01";
+break;
 default:
 av_assert0(0);
 }
@@ -779,16 +782,16 @@ DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", 
AV_CODEC_ID_HEVC)
 enum MediaCodecVP9Level {
 VP9Level1  = 0x1,
-VP9Level11  = 0x2,
+VP9Level11 = 0x2,
 VP9Level2  = 0x4,
-VP9Level21  = 0x8,
-VP9Level3 = 0x10,
+VP9Level21 = 0x8,
+VP9Level3  = 0x10,
 VP9Level31 = 0x20,
 VP9Level4  = 0x40,
-VP9Level41  = 0x80,
-VP9Level5 = 0x100,
+VP9Level41 = 0x80,
+VP9Level5  = 0x100,
 VP9Level51 = 0x200,
-VP9Level52  = 0x400,
+VP9Level52 = 0x400,
 VP9Level6  = 0x800,
 VP9Level61 = 0x1000,
 VP9Level62 = 0x2000,
@@ -837,15 +840,15 @@ DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9)
 enum MediaCodecMpeg4Level {
 MPEG4Level0  = 0x01,
-MPEG4Level0b  = 0x02,
-MPEG4Level1 = 0x04,
+MPEG4Level0b = 0x02,
+MPEG4Level1