diff mbox series

[FFmpeg-devel] Avoid a decoded frame copy in mmaldec for raspberrypi

Message ID 9cd8bf7e.AVQAACIvYBoAAAAAAAAAALF60VUAARpcY_sAAAAAAAeRJgBgJZ1m@mailjet.com
State New
Headers show
Series [FFmpeg-devel] Avoid a decoded frame copy in mmaldec for raspberrypi
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:10 p.m. UTC
Hello,

I needed to acquire mjpeg from a v4l2 uvc webcam in a Raspberry pi,
and I saw mmaldec lacked mjpeg and also was doing an unnecessary copy.

I used two patches I found in the mailing list archives to enable mjpeg
mmaldec and then wrote one that avoids the copy. It works fine for me but
I have not run 'fate' yet. I'm in a cross-building situation and I have
yet to learn how that works.

In a Raspberry Pi 1 Model B now it can 640x480 30fps mjpeg->h264_omx with
25% of cpu (as "top" shows).
Before these three patches, 640x480 YUY2->h264_omx could do only 20fps and
"top" showed 50% of cpu.

A Raspberry Pi 2 can do easily 30fps 1280x720 mjpeg->h264_omx as well.

It'd be a lot easier for me if these patches were upstream so I'm
interested in the code getting in. I'm new in ffmpeg so I may have missed
customary details. I also thank the help #ffmpeg-devel that made my patch
(3rd) simpler than I originally thought.

Regards,
Lluís.
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)