Log in

View Full Version : Formulars to calculate the availabe space for encoding


perilon
18th April 2005, 00:58
When I backup my movies with CCE I don't want to waste any space on my
DVD. So it would be nice if I could know exactly how much space I have
for encoding the video stream. Until last week I used the following
process:

1) Encoding the videos in CCE with an estimated bitrate.
2) Muxing video and audio, compare the results with DVD-size.
3) Correct the bitrate (exact to the kilobit) and encode again.

This process works well and my typical backup has a size around
4,705*10^9 bytes, but it is quite time consuming. And of course I was
always interested in how to calculate the muxing overhead and not in
this try and error stuff. I had some spare time, so here it goes (for
DVD-R):


*** Video_Size=(2025*Muxed_Video_Size - 6217992,5*GOP)/2048 ***

GOP = number of GOPs in encoded videostream
Muxed_Video_Size = 4,706*10^9 - Subs_Size - 64/63*(Audio_Size)
Audio_Size = sum of all AC3 audio files


These formulas work quite well, but there is one problem: how to
determine the number of GOPs? If you enable "Restrict auto I frame
insertion" in CCE, than each GOP is 15 frames (for PAL) and you can
calculate the GOPs as (Number_of_Frames/15). If you have variable GOP,
than you can either estimate the number of GOPs, or you count them
with a program called "bitrate" (but only AFTER encoding). IMHO
the value (Number_of_Frames/15) should suffice.



And now some explanations for the above formulas.

1) The size of a DVD: I am using DVD-R, which can hold 4707319808 bytes
of data. I am using mkisofs to create an ISO-image which creates an
overhead of roughly 1 MB, so my target size is 4,706*10^9 bytes.

2) I am using subtitles in my backups. As the size for the subtitles I
am using the size of what vobsub is extracting.

3) The calculation for the muxed audio is simple: the overhead for
AC3-audio is (audiosize/63) for each audio channel. Each DVD-sector
is 2048 bytes long, and the header of each audio-sector is 32 bytes
long. So the audio will be incrased by 2048/(2048-32)=64/63.

4) The overhead is included in each stream. There is no overhead when
you put those streams together. This gives the following space for
the muxed videostream:

Muxed_Video_Size = 4,706*10^9 - Subs_Size - 64/63*(Audio_Size)

5) In front of each GOP in the DVD-structure the a a so calld
Navigation-Pack, which is 2048 bytes long. Each GOP itself starts
with a 33 bytes header, and every following Video-Pack has an
header of 23 bytes. This gives the following overhead:
2048 + 33 + ((Size_of_GOP - 2015)/2025) * 23

Of course I don't know the size of each GOP, but I can calculate
the average size from the number of GOPs and the size of the video.

6) Each GOP is padded at the end to fill the sector. I don't know if
this is really random, but I estimate that each last sector of a
GOP is filled half with payload. This gives the following size for
padded data: GOPs * 2025/2

7) Now let's calculate the amount of overhead we are getting from
muxing:

Overhead=2081*GOPs + 2025/2*GOPs + 23*(Video_Size - 2015*GOPs)/2025

I am interested in the Video_Size and not in the overhead. With
some math I am getting

Video_Size=(2025*Muxed_Video_Size - 6217992,5*GOP)/2048

8) These calculations aren't fully exact. E.g. the first header has a
different size, but this doesn't really matter. I have also
observed that sometimes a whole sector is being padded, and I have
no idea why this is done. And if there is a short GOP, than the
next GOP sometimes does not have a Navigation-Pack in front of it.

9) I am using "ifoedit" for muxing. I have onced tried "muxman", and
there the result was nearly 1 MB smaller. I haven't checked the
reason for this, but maybe different muxing-programs use other
headers??


Any comments, or even some volunteers who check if it works for them?


Bye P.

knoertploert
1st October 2005, 11:28
A little bit late for a reply but I just want to confirm that the formulas above are pretty accurate. I've used the formulas to calculated the muxing overhead for 10 movies, ranging from 95 to 151 minutes. The calculated overhead is from 0.1 Mb to 2.9 Mb smaller than the real overhead, with a maximum deviation 2.6 percent. I'm using DVD Maestro to author the DVD's and I didn't enable "Restrict auto I frame insertion" in CCE.

By the way if I don't know the (vobsub)size of the subtitles I'm using 4kb per subtitle. This gives me pretty accurate results.

PhillipWyllie
3rd October 2005, 13:46
Here's another way File size(in MB)=Time(in seconds)*Average bitrate(in Mbps)*8. Obviously this is for VBR encodings. I've been doing some DVD's of Friday the 13th that I've had to denoise a bit so some detail is lost and I've struggled to get up to 4Gb. The final file size depends on source(detail,length), Qmatrix, GOP structure, average bitrate, whether you have adaptive Q switching on.