Announcement

Collapse
No announcement yet.

Reading MPEG files.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firblazer
    Junior Member
    Junior Member
    • Oct 2010
    • 4

    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.
  • MilesAhead
    Eclectician
    • Nov 2006
    • 2615

    #2
    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:

    MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files


    Also there should be references to the various mpeg file formats on the web. Just keep searching.

    Comment

    • firblazer
      Junior Member
      Junior Member
      • Oct 2010
      • 4

      #3
      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:

      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.

      Comment

      • MilesAhead
        Eclectician
        • Nov 2006
        • 2615

        #4
        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:



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

        Everything about programming for Digital Video and multimedia applications (e.g. using Delphi/Java/VB/C/C++ etc.. to write apps for digital video).

        Comment

        • firblazer
          Junior Member
          Junior Member
          • Oct 2010
          • 4

          #5
          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.

          Comment

          • firblazer
            Junior Member
            Junior Member
            • Oct 2010
            • 4

            #6
            Thanks for your links.

            Comment

            • MilesAhead
              Eclectician
              • Nov 2006
              • 2615

              #7
              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.

              Comment

              Working...
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎