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

2017-03-07 Thread Tobias Rapp

On 03.03.2017 16:14, Michael Niedermayer wrote:

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 
---
 [...]
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


I agree that the bitrate can vary much depending on the type of video 
material (animation, film scanning, noise, etc) and my intent was to 
signal that with +/- bit_rate_tolerance. Anyway the 40%/60% compression 
numbers roughly match my experience with analogue ingest.


Will post version 3 of the patch-set without updates to bit_rate_tolerance.

Regards,
Tobias

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2017-03-03 Thread Michael Niedermayer
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 
> ---
>  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 

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

2017-03-02 Thread Tobias Rapp

On 06.02.2017 13:33, 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 
---
 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(-)

[...]


I'd like to apply this patch soon, if there are no objections.

Regards,
Tobias

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2017-02-06 Thread Tobias Rapp
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 
---
 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;
+
 return 0;
 }
 static int encode_422_bitstream(HYuvContext *s, int offset, int count)
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index c92dba4..a63793b 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -361,4 +361,10 @@ int ff_side_data_set_encoder_stats(AVPacket *pkt, int 
quality, int64_t *error, i
 int