[FFmpeg-devel] A64 encoder

Michael Niedermayer michaelni
Sun Jul 11 04:32:52 CEST 2010


On Tue, Jul 06, 2010 at 03:07:56PM +0200, Tobias Bindhammer wrote:
>> please split muxer and codec into seperate patches so patches are smaller
>
> Here we go.
>
>> breaks ABI
>
> fixed.
>
>> i think this is not the correct terminology for C
>
> using a 'neutral' name now ;-P
>
>> this heuristic is simply poor
>> if you had no success in implemening some error diffusion dither that 
>> considers
>> neighboring blocks and previous frames than i would suggest you at least 
>> try
>> some kind of a refinement pass after above
>
> i worked on this issue already some time ago, but did not find a suitable 
> solution on this so far. If i reduce too bright or too dark colors already 
> before doing the elbg, the elbg might still lift or lower some pixels again 
> what would then make them appear in the opposite color and will of course 
> look rather ugly in result. That is why i cut off the luminances after the 
> elbg yet and assume that usually no too harsh contrast appears in such a 
> small area like a 8x8 block. Over all this assumption is the only way on 
> how i can at all display 5 colors instead of 4. I know that this assumption 
> fails in very small details with strong contrast, like white font on black 
> background for example. In normal movie situation however it is not much of 
> a problem and the wider luminance range adds more to the quality, by adding 
> more depth and detail, than this (indeed poor) tradeoff destroys 
> qualitywise. In fact, taking the surrounding blocks into regard might also 
> help on avoiding a blocky result (imagine the white font on black 
> background again, reducing the white to a light grey will give a better 
> visual result than changing the surrounding black to a dark grey, and such 
> creating very visible blocks), but so far i have no idea on how to 
> implement that. So seems, like we have to stick to the poor variant so far. 
> The good thing: the format of a encoded frame can in any case stay the 
> same, and it is just about the codec to improve quality further in this 
> issue.
>
> Also i did some other changes to enhance quality but did not merge those 
> changes into this version yet, as i wanted to get the basic codec into 
> ffmpeg first. Those enhancements inklude things like interlace, taking care 

ok, lets try to get the basic stuff in first


> of correct luma distance between the 5 colors (as distances are not linear) 
> and so on. Also i implemented your suggestions of using a LUT for the 
> colorram to save some bytes in the encoded frames.
>
>> {} also try patcheck please
>
> fixed for the if/else cases.
>
>> the encoders private struct belongs in the .c file unless the encoder is
>> split accross several files
>
> Here, as well as in the muxer i prepared things already for expansion, as 
> the plan is to have several a64-formats and encodings.
>
>> the encoders private context is off limits for the muxer
>> it breaks stream copy but thats not the only reason
>
> Fixed to a static value so far, as it is not used yet. But i'd be happy if 
> you can give me a hint on how to access such a value like the lifetime, as 
> i plan to use it somewhen for the c64-videoplayer.

things that are constant throughout a movie can be transfered through
extradata, things that change through AVPacket.data. And no structs
may be used in there because their layout is platform dependant


[...]
> Index: libavcodec/a64multienc.c
> ===================================================================
> --- libavcodec/a64multienc.c	(Revision 0)
> +++ libavcodec/a64multienc.c	(Revision 0)
> @@ -0,0 +1,251 @@
> +/*
> + * a64 video encoder - multicolor modes
> + * Copyright (c) 2009 Tobias Bindhammer
> + *
> + * 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
> + * a64 video encoder - multicolor modes
> + */
> +
> +#include "a64enc.h"
> +#include "a64tables.h"
> +#include "elbg.h"
> +
> +#define DITHERSTEPS 8
> +
> +/* own stuff */
> +static void to_meta_with_crop(AVCodecContext *avctx, AVFrame *p, int *dest)
> +{
> +    int blockx, blocky, x, y;
> +    int luma = 0;
> +    int height = FFMIN(avctx->height,C64YRES);
> +    int width  = FFMIN(avctx->width ,C64XRES);
> +    uint8_t *src = p->data[0];
> +
> +    for (blocky = 0; blocky<height; blocky += 8) {
> +        for (blockx = 0; blockx<C64XRES; blockx += 8) {
> +            for (y = blocky; y < blocky+8 && y<height; y++) {
> +                for (x = blockx; x < blockx+8 && x<C64XRES; x += 2) {
> +                    if(x<width) {
> +                        /* build average over 2 pixels */
> +                        luma = (src[(x + 0 + y * p->linesize[0])] +
> +                                src[(x + 1 + y * p->linesize[0])]) / 2;
> +                        //farben < 1 als 1-val auf low_diff aufadieren je block
> +                        //farben > 4 als val-4 aufaddieren auf highdiff
> +                        //wenn highdiff<lowdiff: hohe werte limitieren auf max: 4
> +                        //sonst kleine werte limitieren auf 1
> +                        /* write blocks as linear data now so they are suitable for elbg */

ffmpeg ist ein internationales projekt, du solltest auch ein paar
schwedische, ungarische und japanische komentare einf?gen das ist
ja fast schon diskriminierend


[...]
>  Makefile     |    1 
>  a64.c        |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  allformats.c |    1 
>  3 files changed, 74 insertions(+)
> d2d9999420275561170605969fd2397bff150188  a64_10_muxer.diff

muxer ok

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100711/e4282fc7/attachment.pgp>



More information about the ffmpeg-devel mailing list