[FFmpeg-devel] [PATCH 1/4] zmbvenc: don't sum the entropy when blocks are equal

Tomas Härdin tjoppen at acc.umu.se
Thu Dec 20 18:29:53 EET 2018


ons 2018-12-19 klockan 22:00 +0000 skrev matthew.w.fearnley at gmail.com:
> > From: Matthew Fearnley <matthew.w.fearnley at gmail.com>
> 
> If *xored is 0, then histogram[0]==bw*bh and histogram[1..255]==0.
> 
> Because histogram[0] is skipped over for the entropy calculation, the
> return value is always 0 when *xored==0, so we don't need to waste time
> calculating it.
> 
> This addition both clarifies the behaviour of the code and improves
> the speed when the block matches.
> ---
>  libavcodec/zmbvenc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
> index 4d9147657d..2f041dae32 100644
> --- a/libavcodec/zmbvenc.c
> +++ b/libavcodec/zmbvenc.c
> @@ -71,6 +71,7 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t *src, int stride,
>      int i, j;
>      uint8_t histogram[256] = {0};
>  
> +    /* build frequency histogram of byte values for src[] ^ src2[] */
>      *xored = 0;
>      for(j = 0; j < bh; j++){
>          for(i = 0; i < bw; i++){
> @@ -82,6 +83,10 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t *src, int stride,
>          src2 += stride2;
>      }
>  
> +    /* early out if src and src2 are equal */
> +    if (!*xored) return 0;

I have a feeling this could be sped up further by just doing *xored =
histogram[0] == ZMBV_BLOCK*ZMBV_BLOCK after the loops, if [PATCH 3/4]
is applied before this. Computing both histogram and xored in the loop
seems pointless.

Beyond that this looks good

/Tomas


More information about the ffmpeg-devel mailing list