Problems with calculating bitrate for videofiles

The place for "I can't figure out how to..." questions.
Post Reply
eLucy
User
Posts: 8
Joined: Wed Nov 08, 2006 5:46 pm

Problems with calculating bitrate for videofiles

Post by eLucy » Wed Nov 08, 2006 6:12 pm

Hello togeather,

i'm quite new to programming in PHP, in fact i'm quite new to programming in genereal ;) But anyhow, i got getid3 working and it serves me pretty well. The only difficulty i have is as follows:

As you can probably imagine i use the scripts to write the data i retrieve from it to a database. Now i found the value telling me the bitrate for the audio portion of the file but the bitrate results given by the script is a very large number and i simple do not know how to convert them into my desired unit, means converting the value given"bitrate value: 1252293.86104" into kBit/s. I tried many things to derive a function from the wide variety of values given, but unfotunately i didn't find the right solution. Like in this special case, my OS tells me the file runs with 162KBit/s.Can anybody plaese help me i just can't figure it out.

Jan

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Wed Nov 08, 2006 7:18 pm

getID3() provides bitrate as bits per second (bps).

Divide bps value by 1000 and you kilobits per second.

Divide bps value by 8 and you get bytes per second
Divide bps value by (8x1024) and you get kilobytes per second.

In your case, the 1252293.86104 bps = 1252 kilobits per second, which is a rather high number, even for lossless compression. Are you sure you read the correct value?

eLucy
User
Posts: 8
Joined: Wed Nov 08, 2006 5:46 pm

Post by eLucy » Wed Nov 08, 2006 7:54 pm

Hello and thank you very much for your fast reply.

Yes i'm very positive about the value. I had quite a vaiety of movies tested and avi-files (divX or Xvid) always generate such large numbers. Like with another avi-file, the os-properties dialog states the video portion of the file to be 175 kBits/s. According to the video-class array delivered by getid3 the file has a bitrate of "1241085.07142bps". If i use what you told me I'd devide the value by 1000 to get kBit/s, don't i? But again this makes a complete different value, nothing near 175. I'm complete at a loss here. The audio portion of the same file is (according to xp) 192 kBit/s and i retrieve the same with your class. Only when it comes to videos it seems that there is something wrong.

I have no idea how you generate these values, but unless they are not part of some meta-information or file header it might be of interest to you that i use movie-files of about 700MB to 2.5GB. And like i said it happens on DIVX and XVID files alike.

Appart from that, i'm very curious, how do i retrieve the two seperate bitrate values for sound and video when it comes to mpeg files? As far as i can see it the delivered value on the base level of the output arrays derives from the files audio properties. They show the same bitrate that the windows property dialog does. So if i get this right windows only shows the audio bitrate in it's file property dialog whilst it doesn't explicitly say so.
Using getid3 for mpeg videos you see a value stating '['mpeg']['video']['raw']['bits_per_sample']-> 24' or another one which is '['mpeg']['video']['raw']['bitrate']-> 2875' and another one with ['mpeg']['video']['bitrate']->1150000. Maybe these could help but once again i don't know what to do with the values.

Thank's a lot and kind regards

Jan

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Thu Nov 09, 2006 10:25 am

Total bitrate of the file is approx the 175kB/s reported by your OS:

Code: Select all

1241085 / 1000 = 1241kbps / 8 = 155kB/s
                  192kbps / 8 =  24kB/s
                                -------
                                179kB/s
Values reported by getID3 for MPEG video files are approximate at best. I don't have enough documentation on the MPEG file structure to make any claims of great accuracy, so only use those values as a guideline.

Values for any format will have values in [bitrate] and/or [audio][bitrate] and/or [video][bitrate], these are the final calculated values that should be used for the file; any other reported values elsewhere in the returned data structure may be intermediate and/or unprocessed raw values.

eLucy
User
Posts: 8
Joined: Wed Nov 08, 2006 5:46 pm

Post by eLucy » Thu Nov 09, 2006 11:49 am

Hy again and once again thanks for your reply:)

And excuse me, what i wrote might have been a little confusing. So i'll try to explain once again, when lookin' up the files properties in the xp-properties dialog, the dialog returns 175 kBit/s (not kB/s), wich means there's no further division by eight and this means i end up here:

1241085.07142bps/1000 = 1241.058 kBit/s.

And this value is way to far from an aproximation isn't it? Sorry maybe i'm just getting it wrong somehow. And also you can not add the 192 kBit/s value anyway because it is returned seperately in the os-dialog. 175 for video 192 for audio. This is also refelected by the fact that the array returning the bitrate of 1241085.07142bps is the basic [video] array returned by getid3 while ['audio']['streams']['0']['bitrate'] returns 192000bps. So there must be another way of how to get to the proper value or am i mistaking somewhere?

Jan

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Thu Nov 09, 2006 2:15 pm

I don't generally trust Windows-provided info on media files.
Try using a tool like GSpot to see what the audio/video bitrates are, and how that compares to getID3 and your other reported values.

eLucy
User
Posts: 8
Joined: Wed Nov 08, 2006 5:46 pm

Post by eLucy » Thu Nov 09, 2006 3:29 pm

THanks a lot,

i'll try that and report as soon as possible. Meanwhile i have another small question, do you happen to know a way how to retrieve a disks burning-date by using php. Is it possibel at all? Or do you happen to know another workable solution? I searched quite a bit but all i found where some softwaresolutions like nero's info tool.

Post Reply