[FFmpeg-devel] [PATCH v2 2/3] avcodec: estimate output bitrate for ffv1/huffyuv codecs

Michael Niedermayer michael at niedermayer.cc
Fri Mar 3 17:14:31 EET 2017


On Mon, Feb 06, 2017 at 01:33:19PM +0100, Tobias Rapp wrote:
> Allows to get a more realistic total bitrate (and estimated file size)
> in avi_write_header. Previously a static default value of 200k was
> assumed.
> 
> Signed-off-by: Tobias Rapp <t.rapp at noa-archive.com>
> ---
>  libavcodec/ffv1enc.c                           |  4 ++++
>  libavcodec/huffyuvenc.c                        |  4 ++++
>  libavcodec/internal.h                          |  6 ++++++
>  libavcodec/utils.c                             | 21 +++++++++++++++++++++
>  tests/ref/vsynth/vsynth1-ffv1                  |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v0               |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v3-bgr0          |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v3-rgb48         |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v3-yuv420p       |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v3-yuv422p10     |  2 +-
>  tests/ref/vsynth/vsynth1-ffv1-v3-yuv444p16     |  2 +-
>  tests/ref/vsynth/vsynth1-ffvhuff               |  2 +-
>  tests/ref/vsynth/vsynth1-ffvhuff420p12         |  2 +-
>  tests/ref/vsynth/vsynth1-ffvhuff422p10left     |  2 +-
>  tests/ref/vsynth/vsynth1-ffvhuff444            |  2 +-
>  tests/ref/vsynth/vsynth1-ffvhuff444p16         |  2 +-
>  tests/ref/vsynth/vsynth1-huffyuv               |  2 +-
>  tests/ref/vsynth/vsynth1-huffyuvbgr24          |  2 +-
>  tests/ref/vsynth/vsynth1-huffyuvbgra           |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1                  |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v0               |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v3-bgr0          |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v3-rgb48         |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v3-yuv420p       |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v3-yuv422p10     |  2 +-
>  tests/ref/vsynth/vsynth2-ffv1-v3-yuv444p16     |  2 +-
>  tests/ref/vsynth/vsynth2-ffvhuff               |  2 +-
>  tests/ref/vsynth/vsynth2-ffvhuff420p12         |  2 +-
>  tests/ref/vsynth/vsynth2-ffvhuff422p10left     |  2 +-
>  tests/ref/vsynth/vsynth2-ffvhuff444            |  2 +-
>  tests/ref/vsynth/vsynth2-ffvhuff444p16         |  2 +-
>  tests/ref/vsynth/vsynth2-huffyuv               |  2 +-
>  tests/ref/vsynth/vsynth2-huffyuvbgr24          |  2 +-
>  tests/ref/vsynth/vsynth2-huffyuvbgra           |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1                  |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v0               |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v3-bgr0          |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v3-rgb48         |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v3-yuv420p       |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v3-yuv422p10     |  2 +-
>  tests/ref/vsynth/vsynth3-ffv1-v3-yuv444p16     |  2 +-
>  tests/ref/vsynth/vsynth3-ffvhuff               |  2 +-
>  tests/ref/vsynth/vsynth3-ffvhuff420p12         |  2 +-
>  tests/ref/vsynth/vsynth3-ffvhuff422p10left     |  2 +-
>  tests/ref/vsynth/vsynth3-ffvhuff444            |  2 +-
>  tests/ref/vsynth/vsynth3-ffvhuff444p16         |  2 +-
>  tests/ref/vsynth/vsynth3-huffyuv               |  2 +-
>  tests/ref/vsynth/vsynth3-huffyuvbgr24          |  2 +-
>  tests/ref/vsynth/vsynth3-huffyuvbgra           |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1              |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v0           |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v3-bgr0      |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v3-rgb48     |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v3-yuv420p   |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v3-yuv422p10 |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffv1-v3-yuv444p16 |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffvhuff           |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffvhuff420p12     |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffvhuff422p10left |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffvhuff444        |  2 +-
>  tests/ref/vsynth/vsynth_lena-ffvhuff444p16     |  2 +-
>  tests/ref/vsynth/vsynth_lena-huffyuv           |  2 +-
>  tests/ref/vsynth/vsynth_lena-huffyuvbgr24      |  2 +-
>  tests/ref/vsynth/vsynth_lena-huffyuvbgra       |  2 +-
>  64 files changed, 95 insertions(+), 60 deletions(-)
> 
> diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
> index 35f54c6..7138cc0 100644
> --- a/libavcodec/ffv1enc.c
> +++ b/libavcodec/ffv1enc.c
> @@ -894,6 +894,10 @@ slices_ok:
>              }
>      }
>  
> +    // estimate bitrate assuming 40% compression
> +    avctx->bit_rate = ff_guess_coded_bitrate(avctx) * 2 / 5;
> +    avctx->bit_rate_tolerance = avctx->bit_rate;
> +
>      return 0;
>  }
>  
> diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
> index 89639b7..8911408 100644
> --- a/libavcodec/huffyuvenc.c
> +++ b/libavcodec/huffyuvenc.c
> @@ -446,6 +446,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  
>      s->picture_number=0;
>  
> +    // estimate bitrate assuming 60% compression
> +    avctx->bit_rate = ff_guess_coded_bitrate(avctx) * 3 / 5;
> +    avctx->bit_rate_tolerance = avctx->bit_rate;

these violate the API

See avcodec.h:
    /**
     * number of bits the bitstream is allowed to diverge from the reference.
     *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
     * - encoding: Set by user; unused for constant quantizer encoding.
     * - decoding: unused
     */
    int bit_rate_tolerance;

also the compression rate depends on the material these numbers are
basically random



[...]
-- 
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.
-------------- 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/20170303/a633d57c/attachment.sig>


More information about the ffmpeg-devel mailing list