2

I run a web service which muxes multiple elementary streams (e.g., H.264 + FLAC) into a single matroska container/wrapper/file. There is no transcoding as I only copy the streams, using a process like ffmpeg -i i.mkv -i i.flac -map 0:0 -c:0 copy -map 1:0 -c:1 copy out.mkv.

The problem is that the service must provide the total file size (in bytes) of the file (out.mkv) resulting from the mux up front (i.e., before the actual muxing completes). Is it possible to calculate it?

0

No, since different containers have a different overhead over actual data. But you can predict size, if you calculate average difference of source and destination files on actual files.

Other way - calculate size, using actual data, but it may be very slow, as you must walk throw all your data and calculate every chunk size. For this, you can use tool ffprobe to get size of every frame or chunk.

| improve this answer | |
3

The only exact approach is to simulate the muxing. On a *nix system this would be

ffmpeg -i i.mkv -i i.flac -c copy -map 0:0 -map 1:0 -f matroska /dev/null

At the bottom of console readout, there's this line:

frame=152217 fps=71723 q=-1.0 Lsize=  551301kB time=01:41:28.66 ...

The Lsize is what you want. This operation is pretty quick as there's nothing written to disk.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.