[FFmpeg-user] Get the file size in advance when encoding from one another format
a.nielsen at shikadi.net
Wed Jun 15 06:03:10 EEST 2022
> I've created a simple wrapper for FFmpeg using java and use this in a
> spring boot web application, and everything works fine. But the problem is
> I have this requirement that I need to get the file size of any media
> format in advance from encoding to another format because I need to set the
> Header Content-Length.
Yes this is easy. Simply transcode to a temporary file, get its file
size, then stream the temporary file over the HTTP connection.
Because the output file size depends on the complete set of input data,
the formula to calculate the file size in advance is the same as the
formula to do the transcode. So you could transcode it once (there is
your formula to calculate the file size), get the file size, delete it,
then transcode the video a second time, but that would waste CPU time.
So if you save the results of the file-size calculation formula, then
your transcode is already done, and you can stream that over the HTTP
As Reindl and Moritz said last time, HTTP chunked transfer encoding
would be better as you wouldn't need to store a temporary file, but I
understand sometimes you are working with a restrictive set of
requirements and dodgy workarounds are the best you can do.
More information about the ffmpeg-user