diff mbox series

[FFmpeg-devel,1/3] libavcodec/mmaldec: enable MJPEG decoding

Message ID fd567c75.AUoAACIcJusAAAAAAAAAALF60VUAARpcY_sAAAAAAAeRJgBgJaZe@mailjet.com
State New
Headers show
Series mjpeg_mmal and avoid a frame copy in mmaldec
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lluís Batlle i Rossell Feb. 11, 2021, 9:48 p.m. UTC
From: Lluís Batlle i Rossell <viric@viric.name>

From: Cosmin Gorgovan <cosmin@linux-geek.org>

---
 configure              | 1 +
 libavcodec/allcodecs.c | 1 +
 libavcodec/mmaldec.c   | 4 ++++
 3 files changed, 6 insertions(+)

Comments

Mark Thompson Feb. 11, 2021, 10:19 p.m. UTC | #1
On 11/02/2021 21:48, Lluís Batlle i Rossel wrote:
> From: Lluís Batlle i Rossell <viric@viric.name>
> 
> From: Cosmin Gorgovan <cosmin@linux-geek.org>
> 
> ---
>   configure              | 1 +
>   libavcodec/allcodecs.c | 1 +
>   libavcodec/mmaldec.c   | 4 ++++
>   3 files changed, 6 insertions(+)
> 
> diff --git a/configure b/configure
> index a76c2ec4ae..048bedb589 100755
> --- a/configure
> +++ b/configure
> @@ -3105,6 +3105,7 @@ hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
>   hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
>   hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
>   mjpeg_cuvid_decoder_deps="cuvid"
> +mjpeg_mmal_decoder_deps="mmal"
>   mjpeg_qsv_decoder_select="qsvdec"
>   mjpeg_qsv_encoder_deps="libmfx"
>   mjpeg_qsv_encoder_select="qsvenc"
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 16ec182a52..8d1908c6d5 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -187,6 +187,7 @@ extern AVCodec ff_mdec_decoder;
>   extern AVCodec ff_mimic_decoder;
>   extern AVCodec ff_mjpeg_encoder;
>   extern AVCodec ff_mjpeg_decoder;
> +extern AVCodec ff_mjpeg_mmal_decoder;
>   extern AVCodec ff_mjpegb_decoder;
>   extern AVCodec ff_mmvideo_decoder;
>   extern AVCodec ff_mobiclip_decoder;
> diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
> index cb15ac072a..df14b9fc95 100644
> --- a/libavcodec/mmaldec.c
> +++ b/libavcodec/mmaldec.c
> @@ -375,6 +375,9 @@ static av_cold int ffmmal_init_decoder(AVCodecContext *avctx)
>       format_in = decoder->input[0]->format;
>       format_in->type = MMAL_ES_TYPE_VIDEO;
>       switch (avctx->codec_id) {
> +    case AV_CODEC_ID_MJPEG:
> +        format_in->encoding = MMAL_ENCODING_MJPEG;
> +        break;
>       case AV_CODEC_ID_MPEG2VIDEO:
>           format_in->encoding = MMAL_ENCODING_MP2V;
>           break;
> @@ -851,6 +854,7 @@ static const AVOption options[]={
>       };
>   
>   FFMMAL_DEC(h264, AV_CODEC_ID_H264)
> +FFMMAL_DEC(mjpeg, AV_CODEC_ID_MJPEG)
>   FFMMAL_DEC(mpeg2, AV_CODEC_ID_MPEG2VIDEO)
>   FFMMAL_DEC(mpeg4, AV_CODEC_ID_MPEG4)
>   FFMMAL_DEC(vc1, AV_CODEC_ID_VC1)
> 

This seems reasonable.  But, what does it do with non-4:2:0 JPEGs?  Does it fail; convert them to 4:2:0 (like downsampling 4:2:2); have a different non-yuv420p output format?

- Mark
Lluís Batlle i Rossell Feb. 11, 2021, 10:47 p.m. UTC | #2
On Thu, Feb 11, 2021 at 10:19:01PM +0000, Mark Thompson wrote:
> On 11/02/2021 21:48, Lluís Batlle i Rossel wrote:
> > From: Lluís Batlle i Rossell <viric@viric.name>
> > 
> > From: Cosmin Gorgovan <cosmin@linux-geek.org>
> > 
> > ---
> >   configure              | 1 +
> >   libavcodec/allcodecs.c | 1 +
> >   libavcodec/mmaldec.c   | 4 ++++
> >   3 files changed, 6 insertions(+)
> 
> This seems reasonable.  But, what does it do with non-4:2:0 JPEGs?  Does it fail; convert them to 4:2:0 (like downsampling 4:2:2); have a different non-yuv420p output format?

It works fine here in the Pi:
ffprobe says for a file I created:
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)

And I can decode it fine with mjpeg_mmal.

I tried to do the same with "-hwaccel vaapi" in intel, and the mjpeg
decoder failed for me.

$ ffmpeg -hwaccel vaapi -i mjpeg422.mkv -y  -f null -
....
[AVHWFramesContext @ 0x192ec40] Failed to read image from surface
0x4000005: 20 (the requested function is not implemented).

while the command above works with the regular yuvj420p mjpeg input.
diff mbox series

Patch

diff --git a/configure b/configure
index a76c2ec4ae..048bedb589 100755
--- a/configure
+++ b/configure
@@ -3105,6 +3105,7 @@  hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
 mjpeg_cuvid_decoder_deps="cuvid"
+mjpeg_mmal_decoder_deps="mmal"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 16ec182a52..8d1908c6d5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -187,6 +187,7 @@  extern AVCodec ff_mdec_decoder;
 extern AVCodec ff_mimic_decoder;
 extern AVCodec ff_mjpeg_encoder;
 extern AVCodec ff_mjpeg_decoder;
+extern AVCodec ff_mjpeg_mmal_decoder;
 extern AVCodec ff_mjpegb_decoder;
 extern AVCodec ff_mmvideo_decoder;
 extern AVCodec ff_mobiclip_decoder;
diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index cb15ac072a..df14b9fc95 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -375,6 +375,9 @@  static av_cold int ffmmal_init_decoder(AVCodecContext *avctx)
     format_in = decoder->input[0]->format;
     format_in->type = MMAL_ES_TYPE_VIDEO;
     switch (avctx->codec_id) {
+    case AV_CODEC_ID_MJPEG:
+        format_in->encoding = MMAL_ENCODING_MJPEG;
+        break;
     case AV_CODEC_ID_MPEG2VIDEO:
         format_in->encoding = MMAL_ENCODING_MP2V;
         break;
@@ -851,6 +854,7 @@  static const AVOption options[]={
     };
 
 FFMMAL_DEC(h264, AV_CODEC_ID_H264)
+FFMMAL_DEC(mjpeg, AV_CODEC_ID_MJPEG)
 FFMMAL_DEC(mpeg2, AV_CODEC_ID_MPEG2VIDEO)
 FFMMAL_DEC(mpeg4, AV_CODEC_ID_MPEG4)
 FFMMAL_DEC(vc1, AV_CODEC_ID_VC1)