[FFmpeg-devel] [PATCH] Implement optimal huffman encoding for (M)JPEG.

Michael Niedermayer michael at niedermayer.cc
Tue Dec 27 13:27:33 EET 2016


On Tue, Dec 27, 2016 at 07:37:09AM +0000, Jerry Jiang wrote:
> Hey everyone,
> 
> This is my first patch submitted to FFmpeg, so I'm sure that I missed
> something. Please bear with me. :P This patch implements the solution
> outlined here: https://guru.multimedia.cx/small-tasks-for-ffmpeg/
> 
> Activated by passing the flag "-huffman optimal" to the mjpeg encoder,
> otherwise the default huffman tables are used.
> ---
>  libavcodec/Makefile                          |   8 +-
>  libavcodec/mjpegenc.c                        | 265
> +++++++++++++++++++--------
>  libavcodec/mjpegenc.h                        |  60 +++++-
>  libavcodec/mjpegenc_common.c                 | 161 ++++++++++++++--
>  libavcodec/mjpegenc_common.h                 |   2 +
>  libavcodec/mjpegenc_huffman.c                | 198 ++++++++++++++++++++
>  libavcodec/mjpegenc_huffman.h                |  71 +++++++
>  libavcodec/mpegvideo.h                       |   1 +
>  libavcodec/mpegvideo_enc.c                   |   5 +-
>  libavcodec/tests/.gitignore                  |   1 +
>  libavcodec/tests/mjpegenc_huffman.c          | 130 +++++++++++++
>  tests/fate/libavcodec.mak                    |   6 +
>  tests/fate/vcodec.mak                        |   4 +-
>  tests/ref/vsynth/vsynth1-mjpeg-huffman       |   4 +
>  tests/ref/vsynth/vsynth1-mjpeg-trell-huffman |   4 +
>  tests/ref/vsynth/vsynth2-mjpeg-huffman       |   4 +
>  tests/ref/vsynth/vsynth2-mjpeg-trell-huffman |   4 +
>  tests/ref/vsynth/vsynth3-mjpeg-huffman       |   4 +
>  tests/ref/vsynth/vsynth3-mjpeg-trell-huffman |   4 +
>  19 files changed, 829 insertions(+), 107 deletions(-)
>  create mode 100644 libavcodec/mjpegenc_huffman.c
>  create mode 100644 libavcodec/mjpegenc_huffman.h
>  create mode 100644 libavcodec/tests/mjpegenc_huffman.c
>  create mode 100644 tests/ref/vsynth/vsynth1-mjpeg-huffman
>  create mode 100644 tests/ref/vsynth/vsynth1-mjpeg-trell-huffman
>  create mode 100644 tests/ref/vsynth/vsynth2-mjpeg-huffman
>  create mode 100644 tests/ref/vsynth/vsynth2-mjpeg-trell-huffman
>  create mode 100644 tests/ref/vsynth/vsynth3-mjpeg-huffman
>  create mode 100644 tests/ref/vsynth/vsynth3-mjpeg-trell-huffman
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index ec4f7fc..399eaf3 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -39,6 +39,7 @@ OBJS = allcodecs.o
>               \
>         mediacodec.o                                                     \
>         mpeg12framerate.o                                                \
>         options.o                                                        \
> +       mjpegenc_huffman.o                                               \
>         parser.o                                                         \
>         profiles.o                                                       \
>         qsv_api.o                                                        \
> @@ -177,7 +178,8 @@ OBJS-$(CONFIG_AMRWB_DECODER)           += amrwbdec.o
> celp_filters.o   \
>  OBJS-$(CONFIG_AMV_ENCODER)             += mjpegenc.o mjpegenc_common.o \
>                                            mpegvideo_enc.o motion_est.o \
>                                            ratecontrol.o mpeg12data.o   \
> -                                          mpegvideo.o
> +                                          mpegvideo.o                  \
> +                                          mjpegenc_huffman.o
>  OBJS-$(CONFIG_ANM_DECODER)             += anm.o
>  OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
>  OBJS-$(CONFIG_APE_DECODER)             += apedec.o
> @@ -379,7 +381,8 @@ OBJS-$(CONFIG_METASOUND_DECODER)       += metasound.o
> metasound_data.o \
>  OBJS-$(CONFIG_MICRODVD_DECODER)        += microdvddec.o ass.o
>  OBJS-$(CONFIG_MIMIC_DECODER)           += mimic.o
>  OBJS-$(CONFIG_MJPEG_DECODER)           += mjpegdec.o
> -OBJS-$(CONFIG_MJPEG_ENCODER)           += mjpegenc.o mjpegenc_common.o
> +OBJS-$(CONFIG_MJPEG_ENCODER)           += mjpegenc.o mjpegenc_common.o \
> +                                          mjpegenc_huffman.o
>  OBJS-$(CONFIG_MJPEGB_DECODER)          += mjpegbdec.o
>  OBJS-$(CONFIG_MJPEG_VAAPI_ENCODER)     += vaapi_encode_mjpeg.o
>  OBJS-$(CONFIG_MLP_DECODER)             += mlpdec.o mlpdsp.o
> @@ -1012,6 +1015,7 @@ TESTPROGS = avpacket
>                   \
>              jpeg2000dwt                                                 \
>              mathops                                                    \
>              options                                                     \
> +            mjpegenc_huffman
>                                      \
>              utils                                                       \
> 
>  TESTPROGS-$(CONFIG_CABAC)                 += cabac
> diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
> index 3d11377..d443183 100644
> --- a/libavcodec/mjpegenc.c
> +++ b/libavcodec/mjpegenc.c
> @@ -39,35 +39,6 @@
>  #include "mjpeg.h"
>  #include "mjpegenc.h"
> 
> -static uint8_t uni_ac_vlc_len[64 * 64 * 2];
> -static uint8_t uni_chroma_ac_vlc_len[64 * 64 * 2];
> -
> -static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256],
> uint8_t *uni_ac_vlc_len)
> -{

This patch is corrupted by newlines

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are best at talking, realize last or never when they are wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161227/a5a76328/attachment.sig>


More information about the ffmpeg-devel mailing list