How to calculate ffmpeg output file size?
I am using ffmpeg to convert home videos to DVD format and want to calculate the output file size before doing the conversion.
My input file has a bit rate of 7700 kbps and is 114 seconds long. The audio bitrate is 256 kbit (per second?) The input file is 77MB. To get this information I ran:
mplayer -vo null -ao null -frames 0 -identify input.MOD
So in theory, the input file should have (roughly) a file size of:
((7700 / 8) * 114) / 1024
That is, (7700 / 8) is kilobytes/second, multiplied by 114 seconds, and then converted to megabytes. This gives me 107MB, which is way 开发者_如何转开发beyond my 77. Thus I am skeptical of his formula.
That said, after converting the video:
ffmpeg -i input.MOD -y -target ntsc-dvd -sameq -aspect 4:3 output.mpg
The numbers seem to make more sense. Bitrate is 9000 kbps, and applying the above formula, I get 125MB, and my actual output file size is 126MB.
So, two questions:
How do I factor the audio bitrate into this calculation? Is it additive (video file size + audio file size)?
Do DVDs always have a 9000 kilobit/second rate? Is that the definition of a DVD? Or might that change depending on video quality of my input video? What does "-target ntsc-dvd" guarantee about my video?
Why does my input file not "match" the calculation, but the output file does? Is there some other variable I'm not accounting for?
What is the correct way to calculate filesize?
What you have to keep in mind, is that there are few different bitrate measurements to consider:
- maximum bitrate - the bitrate of the most action intensive fragment of the video
average (target) bitrate - the bitrate calculated precisely using your formula
rate control (how quickly encoder reacts to changes in complexity of the video)
Lossy video encoding works by eliminating features that are hard for human eye to see. This means, that a slow motion, a talking head, can be compressed further than a spinning full-screen zoom/panorama.
Why does it matter? Standards do specify a 'maximum' bitrate for a reason - this is how fast player needs to be in order to read and decode a standards-compliant video. DVD has it around 9000kbps.
Finally, since it's a lossy compression, one can specify the average bitrate. This is used if you need to fit the content in limited space or bandwidth (possibly permitting buffering for the more intense fragments).
For instance, you can have a video with maximum bitrate of 7000kbps and the average bitrate of 5500kbps. Finally, rate control, is the algorithm used to decide how much 'space' encoder should assign to different fragments. If you do multi-pass encoding, you are reusing this information from previous passes - improving the quality and bitrate distribution.
精彩评论