From patchwork Thu Feb 11 21:10:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Batlle_i_Rossell?= X-Patchwork-Id: 25579 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 497F0448DD2 for ; Thu, 11 Feb 2021 23:11:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2391468AA98; Thu, 11 Feb 2021 23:11:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from o20.p25.mailjet.com (o20.p25.mailjet.com [185.189.236.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2EA7D6882F0 for ; Thu, 11 Feb 2021 23:11:03 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; q=dns/txt; d=viric.name; i=viric@viric.name; s=mailjet; h=message-id:mime-version:from:to:subject:date:list-unsubscribe:list-unsubscribe-post: feedback-id:x-accept-language:x-csa-complaints:x-mj-mid:x-mj-smtpguid: x-report-abuse-to:content-type:content-disposition:content-transfer-encoding; bh=YR+pBpROlFYGYu7FA6y8LMIT30Wui6oYM+SCMPxnv7k=; b=bd4Ne14SrI5VfjWLTNLVyY17y/mlyv1CTdtuSvai1dgLDx/BWJ+VIs6WH gXO7pPLx2b/8WNhCZsx5KAOeJcSP5bkhy0EV4usMU7KZHxjHG713V5LgRvrj IEtzilc/AesjlyHwebHLvt4QnXakahbT4Q4Md3untbaI2/68OQ+rcY= Message-Id: <9cd8bf7e.AVQAACIvYBoAAAAAAAAAALF60VUAARpcY_sAAAAAAAeRJgBgJZ1m@mailjet.com> MIME-Version: 1.0 From: =?utf-8?q?Llu=C3=ADs_Batlle_i_Rossell?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 Feb 2021 22:10:55 +0100 List-Unsubscribe-Post: List-Unsubscribe=One-Click Feedback-Id: 42.495910.472369:MJ X-Accept-Language: ca, es, eo, ru, en, jbo, tokipona X-CSA-Complaints: csa-complaints@eco.de X-MJ-Mid: AVQAACIvYBoAAAAAAAAAALF60VUAARpcY_sAAAAAAAeRJgBgJZ1m7qEQfQAvS2CO5d0rkFnMZgAHNTE X-MJ-SMTPGUID: eea1107d-002f-4b60-8ee5-dd2b9059cc66 X-REPORT-ABUSE-TO: Message sent by Mailjet please report to abuse@mailjet.com with a copy of the message Content-Disposition: inline Subject: [FFmpeg-devel] Avoid a decoded frame copy in mmaldec for raspberrypi X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --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)