mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-13 10:30:05 +01:00
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 <t.rapp@noa-archive.com> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@@ -4343,3 +4343,24 @@ int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
|
||||
{
|
||||
AVRational framerate = avctx->framerate;
|
||||
int bits_per_coded_sample = avctx->bits_per_coded_sample;
|
||||
int64_t bitrate;
|
||||
|
||||
if (!(framerate.num && framerate.den))
|
||||
framerate = av_inv_q(avctx->time_base);
|
||||
if (!(framerate.num && framerate.den))
|
||||
return 0;
|
||||
|
||||
if (!bits_per_coded_sample) {
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
|
||||
bits_per_coded_sample = av_get_bits_per_pixel(desc);
|
||||
}
|
||||
bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
|
||||
framerate.num / framerate.den;
|
||||
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user