Re: [FFmpeg-devel] [PATCH v3 2/3] avcodec: estimate output bitrate for uncompressed video codecs
On 11.03.2017 16:28, Michael Niedermayer wrote: On Tue, Mar 07, 2017 at 03:39:18PM +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. Adds an internal helper function for bitrate guessing. Signed-off-by: Tobias Rapp--- libavcodec/internal.h| 6 ++ libavcodec/r210enc.c | 15 +++ libavcodec/rawenc.c | 2 ++ libavcodec/utils.c | 21 + libavcodec/v210enc.c | 3 +++ libavcodec/v308enc.c | 3 +++ libavcodec/v408enc.c | 2 ++ libavcodec/v410enc.c | 3 +++ libavcodec/y41penc.c | 1 + tests/ref/fate/v410enc | 2 +- tests/ref/vsynth/vsynth1-bpp1| 2 +- tests/ref/vsynth/vsynth1-bpp15 | 2 +- tests/ref/vsynth/vsynth1-r210| 2 +- tests/ref/vsynth/vsynth1-rgb | 2 +- tests/ref/vsynth/vsynth1-v210| 2 +- tests/ref/vsynth/vsynth1-v210-10 | 2 +- tests/ref/vsynth/vsynth1-v308| 2 +- tests/ref/vsynth/vsynth1-v408| 2 +- tests/ref/vsynth/vsynth1-y41p| 2 +- tests/ref/vsynth/vsynth1-yuv | 2 +- tests/ref/vsynth/vsynth2-bpp1| 2 +- tests/ref/vsynth/vsynth2-bpp15 | 2 +- tests/ref/vsynth/vsynth2-r210| 2 +- tests/ref/vsynth/vsynth2-rgb | 2 +- tests/ref/vsynth/vsynth2-v210| 2 +- tests/ref/vsynth/vsynth2-v210-10 | 2 +- tests/ref/vsynth/vsynth2-v308| 2 +- tests/ref/vsynth/vsynth2-v408| 2 +- tests/ref/vsynth/vsynth2-y41p| 2 +- tests/ref/vsynth/vsynth2-yuv | 2 +- tests/ref/vsynth/vsynth3-bpp1| 2 +- tests/ref/vsynth/vsynth3-bpp15 | 2 +- tests/ref/vsynth/vsynth3-r210| 2 +- tests/ref/vsynth/vsynth3-rgb | 2 +- tests/ref/vsynth/vsynth3-v210| 2 +- tests/ref/vsynth/vsynth3-v210-10 | 2 +- tests/ref/vsynth/vsynth3-v308| 2 +- tests/ref/vsynth/vsynth3-v408| 2 +- tests/ref/vsynth/vsynth3-yuv | 2 +- tests/ref/vsynth/vsynth_lena-bpp1| 2 +- tests/ref/vsynth/vsynth_lena-bpp15 | 2 +- tests/ref/vsynth/vsynth_lena-r210| 2 +- tests/ref/vsynth/vsynth_lena-rgb | 2 +- tests/ref/vsynth/vsynth_lena-v210| 2 +- tests/ref/vsynth/vsynth_lena-v210-10 | 2 +- tests/ref/vsynth/vsynth_lena-v308| 2 +- tests/ref/vsynth/vsynth_lena-v408| 2 +- tests/ref/vsynth/vsynth_lena-y41p| 2 +- tests/ref/vsynth/vsynth_lena-yuv | 2 +- 49 files changed, 96 insertions(+), 40 deletions(-) should be ok Pushed. Thanks, Tobias ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH v3 2/3] avcodec: estimate output bitrate for uncompressed video codecs
On Tue, Mar 07, 2017 at 03:39:18PM +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. > > Adds an internal helper function for bitrate guessing. > > Signed-off-by: Tobias Rapp> --- > libavcodec/internal.h| 6 ++ > libavcodec/r210enc.c | 15 +++ > libavcodec/rawenc.c | 2 ++ > libavcodec/utils.c | 21 + > libavcodec/v210enc.c | 3 +++ > libavcodec/v308enc.c | 3 +++ > libavcodec/v408enc.c | 2 ++ > libavcodec/v410enc.c | 3 +++ > libavcodec/y41penc.c | 1 + > tests/ref/fate/v410enc | 2 +- > tests/ref/vsynth/vsynth1-bpp1| 2 +- > tests/ref/vsynth/vsynth1-bpp15 | 2 +- > tests/ref/vsynth/vsynth1-r210| 2 +- > tests/ref/vsynth/vsynth1-rgb | 2 +- > tests/ref/vsynth/vsynth1-v210| 2 +- > tests/ref/vsynth/vsynth1-v210-10 | 2 +- > tests/ref/vsynth/vsynth1-v308| 2 +- > tests/ref/vsynth/vsynth1-v408| 2 +- > tests/ref/vsynth/vsynth1-y41p| 2 +- > tests/ref/vsynth/vsynth1-yuv | 2 +- > tests/ref/vsynth/vsynth2-bpp1| 2 +- > tests/ref/vsynth/vsynth2-bpp15 | 2 +- > tests/ref/vsynth/vsynth2-r210| 2 +- > tests/ref/vsynth/vsynth2-rgb | 2 +- > tests/ref/vsynth/vsynth2-v210| 2 +- > tests/ref/vsynth/vsynth2-v210-10 | 2 +- > tests/ref/vsynth/vsynth2-v308| 2 +- > tests/ref/vsynth/vsynth2-v408| 2 +- > tests/ref/vsynth/vsynth2-y41p| 2 +- > tests/ref/vsynth/vsynth2-yuv | 2 +- > tests/ref/vsynth/vsynth3-bpp1| 2 +- > tests/ref/vsynth/vsynth3-bpp15 | 2 +- > tests/ref/vsynth/vsynth3-r210| 2 +- > tests/ref/vsynth/vsynth3-rgb | 2 +- > tests/ref/vsynth/vsynth3-v210| 2 +- > tests/ref/vsynth/vsynth3-v210-10 | 2 +- > tests/ref/vsynth/vsynth3-v308| 2 +- > tests/ref/vsynth/vsynth3-v408| 2 +- > tests/ref/vsynth/vsynth3-yuv | 2 +- > tests/ref/vsynth/vsynth_lena-bpp1| 2 +- > tests/ref/vsynth/vsynth_lena-bpp15 | 2 +- > tests/ref/vsynth/vsynth_lena-r210| 2 +- > tests/ref/vsynth/vsynth_lena-rgb | 2 +- > tests/ref/vsynth/vsynth_lena-v210| 2 +- > tests/ref/vsynth/vsynth_lena-v210-10 | 2 +- > tests/ref/vsynth/vsynth_lena-v308| 2 +- > tests/ref/vsynth/vsynth_lena-v408| 2 +- > tests/ref/vsynth/vsynth_lena-y41p| 2 +- > tests/ref/vsynth/vsynth_lena-yuv | 2 +- > 49 files changed, 96 insertions(+), 40 deletions(-) should be ok [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No snowflake in an avalanche ever feels responsible. -- Voltaire signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH v3 2/3] avcodec: estimate output bitrate for uncompressed video codecs
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. Adds an internal helper function for bitrate guessing. Signed-off-by: Tobias Rapp--- libavcodec/internal.h| 6 ++ libavcodec/r210enc.c | 15 +++ libavcodec/rawenc.c | 2 ++ libavcodec/utils.c | 21 + libavcodec/v210enc.c | 3 +++ libavcodec/v308enc.c | 3 +++ libavcodec/v408enc.c | 2 ++ libavcodec/v410enc.c | 3 +++ libavcodec/y41penc.c | 1 + tests/ref/fate/v410enc | 2 +- tests/ref/vsynth/vsynth1-bpp1| 2 +- tests/ref/vsynth/vsynth1-bpp15 | 2 +- tests/ref/vsynth/vsynth1-r210| 2 +- tests/ref/vsynth/vsynth1-rgb | 2 +- tests/ref/vsynth/vsynth1-v210| 2 +- tests/ref/vsynth/vsynth1-v210-10 | 2 +- tests/ref/vsynth/vsynth1-v308| 2 +- tests/ref/vsynth/vsynth1-v408| 2 +- tests/ref/vsynth/vsynth1-y41p| 2 +- tests/ref/vsynth/vsynth1-yuv | 2 +- tests/ref/vsynth/vsynth2-bpp1| 2 +- tests/ref/vsynth/vsynth2-bpp15 | 2 +- tests/ref/vsynth/vsynth2-r210| 2 +- tests/ref/vsynth/vsynth2-rgb | 2 +- tests/ref/vsynth/vsynth2-v210| 2 +- tests/ref/vsynth/vsynth2-v210-10 | 2 +- tests/ref/vsynth/vsynth2-v308| 2 +- tests/ref/vsynth/vsynth2-v408| 2 +- tests/ref/vsynth/vsynth2-y41p| 2 +- tests/ref/vsynth/vsynth2-yuv | 2 +- tests/ref/vsynth/vsynth3-bpp1| 2 +- tests/ref/vsynth/vsynth3-bpp15 | 2 +- tests/ref/vsynth/vsynth3-r210| 2 +- tests/ref/vsynth/vsynth3-rgb | 2 +- tests/ref/vsynth/vsynth3-v210| 2 +- tests/ref/vsynth/vsynth3-v210-10 | 2 +- tests/ref/vsynth/vsynth3-v308| 2 +- tests/ref/vsynth/vsynth3-v408| 2 +- tests/ref/vsynth/vsynth3-yuv | 2 +- tests/ref/vsynth/vsynth_lena-bpp1| 2 +- tests/ref/vsynth/vsynth_lena-bpp15 | 2 +- tests/ref/vsynth/vsynth_lena-r210| 2 +- tests/ref/vsynth/vsynth_lena-rgb | 2 +- tests/ref/vsynth/vsynth_lena-v210| 2 +- tests/ref/vsynth/vsynth_lena-v210-10 | 2 +- tests/ref/vsynth/vsynth_lena-v308| 2 +- tests/ref/vsynth/vsynth_lena-v408| 2 +- tests/ref/vsynth/vsynth_lena-y41p| 2 +- tests/ref/vsynth/vsynth_lena-yuv | 2 +- 49 files changed, 96 insertions(+), 40 deletions(-) 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 ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size); +/** + * Get an estimated video bitrate based on frame size, frame rate and coded + * bits per pixel. + */ +int64_t ff_guess_coded_bitrate(AVCodecContext *avctx); + #endif /* AVCODEC_INTERNAL_H */ diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c index 65b3c06..a55e543 100644 --- a/libavcodec/r210enc.c +++ b/libavcodec/r210enc.c @@ -24,6 +24,18 @@ #include "internal.h" #include "bytestream.h" +static av_cold int encode_init(AVCodecContext *avctx) +{ +int aligned_width = FFALIGN(avctx->width, +avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64); + +avctx->bits_per_coded_sample = 32; +if (avctx->width > 0) +avctx->bit_rate = ff_guess_coded_bitrate(avctx) * aligned_width / avctx->width; + +return 0; +} + static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet) { @@ -73,6 +85,7 @@ AVCodec ff_r210_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_R210, +.init = encode_init, .encode2= encode_frame, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE }, .capabilities = AV_CODEC_CAP_INTRA_ONLY, @@ -84,6 +97,7 @@ AVCodec ff_r10k_encoder = { .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_R10K, +.init = encode_init, .encode2= encode_frame, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE }, .capabilities = AV_CODEC_CAP_INTRA_ONLY, @@ -95,6 +109,7 @@ AVCodec ff_avrp_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_AVRP, +.init = encode_init, .encode2= encode_frame,