Digital Video Forums

Go Back   Digital Video Forums > Other > Archive (Closed) > General Discussions

 
 
LinkBack Thread Tools Rate Thread Display Modes
Old 20 Oct 2010, 01:16 PM   #1
Junior Member
Junior Member
 
Join Date: Oct 2010
Posts: 4
Default Reading MPEG files.

Hi!

I am writing a web application to read in MPEG-1, MPEG-2 and MPEG-4 files. I need to know the duration of the MPEG movie from the file itself.

I know the equation: Duration = file size / bit rate X 8

I am able to read the file size from my web application. Problem is: how do I know the bit rate of the MPEG file?

I have searched on the internet and I discovered that the bit rate is in the MPEG frame header.

But how do I decode the frame header? Can anyone point me in the right direction? Any websites? books that describes the frame header so that I can read in the binary data and determine the bit rate?

Anyone has a better idea to determine the duration of the MPEG movie? I am writing the web application in JSP/JAVA.

Any help is appreciated. Thanks.
firblazer is offline  
Old 20 Oct 2010, 02:13 PM   #2
Eclectician
 
MilesAhead's Avatar
 
Join Date: Nov 2006
Posts: 2,615
Default

I haven't dabbled in Java in quite awhile. Can you load and call functions in a Windows DLL using it? If so, I would look at MediaInfo DLL. If not, you may still want to look at the source code to see how the MediaInfo programmer gets the info:

http://mediainfo.sourceforge.net/en/Download/Source

Also there should be references to the various mpeg file formats on the web. Just keep searching.
MilesAhead is offline  
Old 20 Oct 2010, 03:11 PM   #3
Junior Member
Junior Member
 
Join Date: Oct 2010
Posts: 4
Default

Hi!

Thanks for your reply. I actually found ISO MPEG specification from www{dot}wotsit{dot}org/list.asp?fc=3

Look under ISO/IEC 13818-2 MPEG-2 Video. On page 55, it says:

Quote:
bit_rate_value -- The lower 18 bits of bit_rate.

bit_rate -- This is a 30-bit integer. The lower 18 bits of the integer are in bit_rate_value and the upper 12 bits are in bit_rate_extension. The 30-bit integer specifies the bitrate of the bitstream measured in units of 400 bits/second, rounded upwards. The value zero is forbidden.


If the bitstream is a constant bitrate stream, the bitrate specified is the actual rate of operation of the VBV specified in annex C. If the bitstream is a variable bitrate stream, the STD specifications in ISO/IEC 13818-1 supersede the VBV, and the bitrate specified here is used to dimension the transport stream STD (2.4.2 in ITU-T Rec. xxx | ISO/IEC 13818-1), or the program stream STD (2.4.5 in ITU-T Rec. xxx | ISO/IEC 13818-1).


If the bitstream is not a constant rate bitstream the vbv_delay field shall have the value FFFF in hexadecimal.


Given the value encoded in the bitrate field, the bitstream shall be generated so that the video encoding and the worst case multiplex jitter do not cause STD buffer overflow or underflow.
Problem is: I don't understand what is lower 18 bits bit_rate_value and upper 12 bits bit_rate_extension.

Is the 30-bit binary converted to decimal, I get the bit rate? I have a hex editor and when I decoded the 30-bit binary of the mpeg file and I converted it to decimal and multiply it with 400, I don't get the bit rate specified by Windows Explorer.

Can you help with the calculation? Any thoughts on the bit_rate_value and the bit_rate_extension?

Many thanks.
firblazer is offline  
Old 20 Oct 2010, 04:33 PM   #4
Eclectician
 
MilesAhead's Avatar
 
Join Date: Nov 2006
Posts: 2,615
Default

I'm not into it at the level you are trying to go. I use converters and burners to get what I want onto my TV. I just know that the MediaInfo .DLL is the easiest way to go if you can somehow use it. On another board one of the programmers wrote a utility for me called PlayTime. It was written in AutoHotKey. But he used the MediaInfo DLL to get all the info and just made it convenient to drag & drop files etc.. Here's a link to that utilty:

http://skwire.dcmembers.com/wb/pages...e/playtime.php

Also you may be able to get more info on this subforum:

http://forum.videohelp.com/forums/38-Programming
MilesAhead is offline  
Old 20 Oct 2010, 05:25 PM   #5
Junior Member
Junior Member
 
Join Date: Oct 2010
Posts: 4
Default

Hi! Thanks for your info.

I can't use an external DLL without having security concerns in my web application.

Anyway, I managed to read in the bits of the binary file header and extract the bit rate of the movie.

Problem is: I only got the bit rate correct for movies with frame rates of 30 frames per second. If the video has 25 frames per second, the calculation is wrong.

Any pointers? Formulas? Thanks.
firblazer is offline  
Old 20 Oct 2010, 05:41 PM   #6
Junior Member
Junior Member
 
Join Date: Oct 2010
Posts: 4
Default

Thanks for your links.
firblazer is offline  
Old 21 Oct 2010, 04:00 AM   #7
Eclectician
 
MilesAhead's Avatar
 
Join Date: Nov 2006
Posts: 2,615
Default

The best advice I can give is look through MediaInfo source. That's the standard everyone uses. It may be worth going to the site and trying to contact the author. He may be sympathetic if you explain what you are trying to figure out, and give you some tips or the best places in the code to look. Some of these programmer guys are actually surprised when somebody asks them an intelligent question about their code and will respond via email. I've had a few guys email me back, but they seem to get bored at one response.

Try to get all the info you can at the first contact.
MilesAhead is offline  
 

Bookmarks

Tags
files, mpeg


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading burned files Mgjkav DVD Blank Media, Burning, Recording Hardware 2 16 Jan 2005 01:30 PM
pb reading avi files compressed in VD NicolasduCaire General Discussions 1 19 Jul 2002 06:12 AM



All times are GMT +10. The time now is 06:15 PM.

Kirsch designed by Andrew & Austin


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0
Copyright © 1999 - 2011 Digital Digest

Visit DivXLand   Visit dvdloc8.com