[FFmpeg-devel] [PATCH] avcodec/dnxhdenc: DNxHR 444 and HQX support

Rostislav Pehlivanov atomnuker at gmail.com
Mon Mar 27 21:41:15 EEST 2017


On 27 March 2017 at 19:08, Paul B Mahol <onemda at gmail.com> wrote:

> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  libavcodec/dnxhdenc.c | 227 ++++++++++++++++++++++++++++++
> +++++---------------
>  libavcodec/dnxhdenc.h |   6 +-
>  2 files changed, 163 insertions(+), 70 deletions(-)
>
> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
> index 33f25fb..6716b74 100644
> --- a/libavcodec/dnxhdenc.c
> +++ b/libavcodec/dnxhdenc.c
> @@ -23,6 +23,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
>   */
>
> +#define ASSERT_LEVEL 10
>

Debug code?


> +
>  #include "libavutil/attributes.h"
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
> @@ -112,6 +114,37 @@ void dnxhd_10bit_get_pixels_8x4_sym(int16_t
> *av_restrict block,
>      memcpy(block + 4 * 8, pixels + 3 * line_size, 8 * sizeof(*block));
>  }
>
> +static int dnxhd_10bit_dct_quantize_444(MpegEncContext *ctx, int16_t
> *block,
> +                                        int n, int qscale, int *overflow)
> +{
> +    const uint8_t *scantable= ctx->intra_scantable.scantable;
> +    const int *qmat = n<4 ? ctx->q_intra_matrix[qscale] :
> ctx->q_chroma_intra_matrix[qscale];
> +    int last_non_zero = 0;
> +    int i;
> +
> +    ctx->fdsp.fdct(block);
> +
> +    // Divide by 4 with rounding, to compensate scaling of DCT
> coefficients
> +    block[0] = (block[0] + 2) >> 2;
> +
> +    for (i = 1; i < 64; ++i) {
> +        int j = scantable[i];
> +        int sign = FF_SIGNBIT(block[j]);
> +        int level = (block[j] ^ sign) - sign;
>

Wait, what? This just makes level == block[j].


> +        level = level * qmat[j] >> 16;
> +        block[j] = (level ^ sign) - sign;
>

Don't use this to sign-ify something, compilers have long been smart enough
to optimize sign * value.

Just do
block[j] = (block[j] * qmat[j] >> 16);
Right shifting signed stuff is defined


More information about the ffmpeg-devel mailing list