[FFmpeg-user] FFMpeg - How to get the filesize in advance after encoding

Moritz Barsnick barsnick at gmx.net
Tue May 24 19:55:26 EEST 2022


On Tue, May 24, 2022 at 15:50:27 +0800, Sendex Six wrote:
> Thanks for your response,
>
> What is the formula, logic, or how to compute the file size from a video or
> audio file? after encoding?
> so that in the webpage we can set the content-length of video or audio

Only under very particular circumstances you can determine the file
size beforehand. I would say these are:
- raw formats/codecs with coonstant bitrates
- some containers with constant muxrates.

And in addition, it depends on the codec and the container.
Uncompressed WAV e.g. is extremely predictable. If you manage to get a
constant bitrate encoding and muximg, you might be able to determine
the size of MP4 or MPEG-TS, but you would have to know about the muxing
mechanisms and the overhead, and ffmpeg's settings influencing it.

As Harald said, the Content-Length isn't necessary, but the receiving
end (user/web browser) will not show the progress if it's missing. This
may or may not be okay.

For what you are trying to achieve, segmented streaming formats such as
HLS were made for: You can segment on the fly, and each finalized
segment's size is known to the receiving end. I guess you can also
indicate an average bitrate and a duration beforehand, but in my
experience it doesn't have to be corrent.

Cheers,
Moritz


More information about the ffmpeg-user mailing list