Search code examples
ffmpegmp3filesizefile-conversionwebm

ffmpeg how to calculate size from webm to mp3 without conversion


Im using the Linux command "ffmpeg", and i was wondering if there is a solution to calculate theoretically (simulate the conversion) the size without making the conversion from .webm file into .mp3 160k.

Is there a formula or something like that, that I follow to get the size ?

Thank you.


Solution

  • If you encode your MP3 with a constant bitrate (CBR) then it's very easy:

    file_size = bitrate * audio_track_duration
    

    Let's say your audio track's duration is 1 minute:

    160 Kb/s * 60 s = 9600 Kb
    9600 Kb / 8 = 1200 KB = 1.2 MB
    

    You can get the audio stream durations with ffprobe (they may be inaccurate in some cases):

    ffprobe -i <input> -select_streams a -show_entries stream=duration -of default=nk=1:nw=1 -v quiet