[FFmpeg-devel] [PATCH] added support for hardware assist H264 video encoding for the Raspberry Pi

wm4 nfxjfg at googlemail.com
Wed Apr 6 10:29:36 CEST 2016


On Tue, 5 Apr 2016 16:09:42 -0700
Amancio Hasty <ahasty at gmail.com> wrote:

> > On Apr 5, 2016, at 3:57 PM, Michael Niedermayer <michael at niedermayer.cc> wrote:
> > 
> > On Tue, Apr 05, 2016 at 11:06:48PM +0200, Michael Niedermayer wrote:  
> >> On Tue, Apr 05, 2016 at 12:00:26PM -0700, Amancio Hasty wrote:  
> >>>   
> >>>> On Mar 31, 2016, at 7:27 PM, Amancio Hasty <ahasty at gmail.com> wrote:
> >>>> 
> >>>> I am not a lawyer…
> >>>> 
> >>>> 
> >>>> I updated the patch.  vc264.c now has a the copyright notice embedded in 
> >>>> a volatile global so if a binary is compiled against vc264.o , the copyright notice
> >>>> can be displayed by:
> >>>> strings ffmpeg | grep -i copyright
> >>>> 
> >>>> LICENSE.md has been updated to include Broadcom’s copyright notice.
> >>>> 
> >>>> A distribution of a  binary that includes vc264.o should include LICENSE.md and if 
> >>>> that is missing,  the copyright notice can be displayed via the shell
> >>>> command ‘strings’ .
> >>>> 
> >>>> Amancio
> >>>> <c-0001-added-support-for-hardware-assist-H264-video-encodin.patch>  
> >>>>> On Mar 22, 2016, at 12:12 PM, Lou Logan <lou at lrcd.com> wrote:
> >>>>> 
> >>>>> On Mon, 21 Mar 2016 20:07:01 -0700, Amancio Hasty wrote:
> >>>>>   
> >>>>>> From 874a72eec2a78f4935fea091003e534b5f8d5413 Mon Sep 17 00:00:00 2001
> >>>>>> From: Amancio Hasty <ahasty at gmail.com>
> >>>>>> Date: Mon, 21 Mar 2016 18:56:05 -0700
> >>>>>> Subject: [PATCH] added support for hardware assist H264  video encoding for
> >>>>>> the Raspberry Pi
> >>>>>> 
> >>>>>> ---
> >>>>>> configure              |  12 ++
> >>>>>> libavcodec/Makefile    |   1 +
> >>>>>> libavcodec/allcodecs.c |   2 +
> >>>>>> libavcodec/vc264.c     | 387 +++++++++++++++++++++++++++++++++++++++++++++++++
> >>>>>> 4 files changed, 402 insertions(+)
> >>>>>> create mode 100644 libavcodec/vc264.c
> >>>>>>   
> >>>>> [...]  
> >>>>>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> >>>>>> index 2a25d66..3c7bd9b 100644
> >>>>>> --- a/libavcodec/allcodecs.c
> >>>>>> +++ b/libavcodec/allcodecs.c
> >>>>>> @@ -74,6 +74,7 @@ void avcodec_register_all(void)
> >>>>>>   initialized = 1;
> >>>>>>   
> >>>>> 
> >>>>> Nit: Whitespace on the line above should be removed.
> >>>>> 
> >>>>> [...]  
> >>>>>> --- /dev/null
> >>>>>> +++ b/libavcodec/vc264.c
> >>>>>> @@ -0,0 +1,387 @@
> >>>>>> +/*  H.264 hardware assist video encoding code taken from
> >>>>>> + * raspberry's os :
> >>>>>> + *   /opt/vc/src/hello_pi/hello_encode/encode.c
> >>>>>> + */
> >>>>>> +
> >>>>>> +/*
> >>>>>> +Copyright (c) 2012, Broadcom Europe Ltd
> >>>>>> +Copyright (c) 2012, Kalle Vahlman <zuh at iki>
> >>>>>> +                    Tuomas Kulve <tuomas at kulve.fi>
> >>>>>> +All rights reserved.
> >>>>>> +
> >>>>>> +Redistribution and use in source and binary forms, with or without
> >>>>>> +modification, are permitted provided that the following conditions are met:
> >>>>>> +* Redistributions of source code must retain the above copyright
> >>>>>> +      notice, this list of conditions and the following disclaimer.
> >>>>>> +      * Redistributions in binary form must reproduce the above copyright
> >>>>>> +      notice, this list of conditions and the following disclaimer in the
> >>>>>> +      documentation and/or other materials provided with the distribution.
> >>>>>> +      * Neither the name of the copyright holder nor the
> >>>>>> +      names of its contributors may be used to endorse or promote products
> >>>>>> +      derived from this software without specific prior written permission.
> >>>>>> +
> >>>>>> +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> >>>>>> +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> >>>>>> +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >>>>>> +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
> >>>>>> +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> >>>>>> +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> >>>>>> +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >>>>>> +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> >>>>>> +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> >>>>>> +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
> >>>>> 
> >>>>> I wonder if any of the above legalese is compatible. Granted, I see a
> >>>>> similar paragraph in "libavformat/aadec.c".
> >>>>>   
> >>>>>> + * ffmpeg driver for hardware assist video H.264 encoding using Broadcom's GPU
> >>>>>> + * Copyright (C) 2016 Amancio Hasty ahasty at gmail.com
> >>>>>> + *
> >>>>>> + *
> >>>>>> + * This file is part of FFmpeg.
> >>>>>> + *
> >>>>>> + * FFmpeg is free software; you can redistribute it and/or
> >>>>>> + * modify it under the terms of the GNU Lesser General Public
> >>>>>> + * License as published by the Free Software Foundation; either
> >>>>>> + * version 2.1 of the License, or (at your option) any later version.
> >>>>>> + *
> >>>>>> + * FFmpeg is distributed in the hope that it will be useful,
> >>>>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >>>>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >>>>>> + * Lesser General Public License for more details.
> >>>>>> + *
> >>>>>> + * You should have received a copy of the GNU Lesser General Public
> >>>>>> + * License along with FFmpeg; if not, write to the Free Software
> >>>>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> >>>>>> + *
> >>>>>> + */
> >>>>>> +
> >>>>>> +
> >>>>>> +/**
> >>>>>> + * @ file vc264.c
> >>>>>> + * Broadcom bm2865's Visual Core hardware assist h264 using
> >>>>>> +   openMax interface to the GPU.
> >>>>>> +
> >>>>>> +*/
> >>>>>> +
> >>>>>> +#include <stdio.h>
> >>>>>> +#include <stdlib.h>
> >>>>>> +#include <string.h>
> >>>>>> +#define OMX_SKIP64BIT
> >>>>>> +#include "bcm_host.h"
> >>>>>> +#include "ilclient.h"
> >>>>>> +#include "avcodec.h"
> >>>>>> +#include "internal.h"
> >>>>>> +
> >>>>>> +typedef struct VC264Context {
> >>>>>> +  OMX_VIDEO_PARAM_PORTFORMATTYPE format;
> >>>>>> +  OMX_PARAM_PORTDEFINITIONTYPE def;
> >>>>>> +  COMPONENT_T *video_encode;
> >>>>>> +  COMPONENT_T *list[5];
> >>>>>> +  OMX_BUFFERHEADERTYPE *buf;
> >>>>>> +  OMX_BUFFERHEADERTYPE *out;
> >>>>>> +  ILCLIENT_T *client;
> >>>>>> +  OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
> >>>>>> +  int  width;
> >>>>>> +  int height;
> >>>>>> +  int bit_rate;
> >>>>>> +} VC264Context;
> >>>>>> +
> >>>>>> +
> >>>>>> +static int vc264_init(AVCodecContext *avctx) {
> >>>>>> +
> >>>>>> +
> >>>>>> +
> >>>>>> +   OMX_ERRORTYPE r;
> >>>>>> +   int error;
> >>>>>> +
> >>>>>> +
> >>>>>> +
> >>>>>> +   VC264Context *vc = avctx->priv_data;
> >>>>>> +
> >>>>>> +   vc->width = avctx->width;
> >>>>>> +   vc->height = avctx->height;
> >>>>>> +   vc->bit_rate = avctx->bit_rate;
> >>>>>> +   printf("vc264: bit rate %d \n", avctx->bit_rate);
> >>>>>> +#if FF_API_CODED_FRAME
> >>>>>> +FF_DISABLE_DEPRECATION_WARNINGS
> >>>>>> +
> >>>>>> +   avctx->coded_frame = av_frame_alloc();
> >>>>>> +   avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
> >>>>>> +FF_ENABLE_DEPRECATION_WARNINGS
> >>>>>> +#endif
> >>>>>> +
> >>>>>> +
> >>>>>> +   memset(&vc->list, 0, sizeof(vc->list));
> >>>>>> +   bcm_host_init();
> >>>>>> +   if ((vc->client = ilclient_init()) == NULL) {
> >>>>>> +      return -3;
> >>>>>> +   }
> >>>>>> +   error = OMX_Init();
> >>>>>> +
> >>>>>> +   if (error  != OMX_ErrorNone) {
> >>>>>> +      ilclient_destroy(vc->client);
> >>>>>> +      av_log(avctx,AV_LOG_ERROR,"in vc264_init OMX_Init failed ");
> >>>>>> +     return -4;
> >>>>>> +    }
> >>>>>> +
> >>>>>> +   // create video_encode
> >>>>>> +   r = ilclient_create_component(vc->client, &vc->video_encode, (char *) "video_encode",
> >>>>>> +				 ILCLIENT_DISABLE_ALL_PORTS |
> >>>>>> +				 ILCLIENT_ENABLE_INPUT_BUFFERS |
> >>>>>> +				 ILCLIENT_ENABLE_OUTPUT_BUFFERS);  
> >>>>> 
> >>>>> Tabs should be converted to spaces. There are many instances of tabs
> >>>>> being used in this patch.
> >>>>> 
> >>>>> Others will have to provide a more technical review (not to mention
> >>>>> possible additions docs, Changelog, MAINTAINERS, and
> >>>>> libavcodec/version.h).
> >>>>> _______________________________________________
> >>>>> ffmpeg-devel mailing list
> >>>>> ffmpeg-devel at ffmpeg.org
> >>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel  
> >>>>   
> >>> 
> >>> Well, ffmpeg is very popular in the Raspberry community. For example, motionpie uses it for 
> >>> video monitoring;however, the encoding is done in software which limits its performance.
> >>> 
> >>> So yes quite  a  bit number of users are waiting for hardware assist H264 encoding in ffmpeg.  
> >> 
> >> I see no harm in adding this, its a optional feature and apparently
> >> theres a user base who wants this
> >> 
> >> thus i intend to apply this patch and state so with this mail
> >> if someone objects please state that clearly in a reply  
> > 
> > from IRC:
> > 
> > <wm4> miI'm still against it
> > <wm4> s/mi/michaelni:/
> > 
> > so if you want this patch applied
> > talk with wm4
> > 
> > [...]
> > 
> > -- 
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> > 
> > Awnsering whenever a program halts or runs forever is
> > On a turing machine, in general impossible (turings halting problem).
> > On any real computer, always possible as a real computer has a finite number
> > of states N, and will either halt in less than N cycles or never halt.
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org <mailto:ffmpeg-devel at ffmpeg.org>
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>  
> If I provide the decoding and the encoding component will the patch be accepted?

There's also an older (but now rebased) attempt at supporting both OMX
decoding and encoding, and not only on RPI but other OMX providers too:

 https://github.com/mstorsjo/libav/commits/bcm-omx

(Looks better than this patch to me.)


More information about the ffmpeg-devel mailing list