Log in

View Full Version : Ogm Info Viewer in Visual Basic


Movie ManiacŪ
19th August 2003, 19:37
Hi everybody

I'm trying to write an Info viewer for Ogm files, like the Avi Info viewer I've written, and which is capable of showing a lot of details.

Well, the problem is that while for Avi structure there's plenty of informations, for Ogm files the informations are not so huge, and mostly they're not always clear for newbyes like me.

Whith a help of an Hex Editor, I as able to write down this piece of code, and I'd like to share my results whith you, hoping that You'll find this interesting, and would like to help me in continuing my project and gathering more informations from this container.
Here's the code:


Dim BitDepth As Integer
Dim Fcc As String * 4
Dim FccHandler As String * 5
Dim FileToOpen As String
Dim MicroSec As Long
Dim nBlockSize As Integer
Dim nChannels As Integer
Dim nHeight As Integer
Dim nOffset As Byte
Dim nTrackNumber As Integer
Dim nWidth As Integer
Dim OgmFile As Integer
Dim Offset As Long
Dim SamplingRate As Long
Dim StreamType As Byte
Dim wAvgBytesPerSec As Long

Private Function chkOggFile(FileName As String)

Dim Signature As String * 4
OgmFile = FreeFile

Open FileName For Binary Access Read Lock Write As OgmFile

Seek OgmFile, 1
Get OgmFile, , Signature

If Signature <> "OggS" Then
MsgBox "Il file aperto non č un file Ogg", vbInformation
GoTo Err:
End If

Do While Not LCase(FccHandler) = "vorbi" 'I hadn't the time to think of a better solution, sorry :(
Seek OgmFile, 4 + 2 + Offset
Get OgmFile, , StreamType
Seek OgmFile, 4 + 11 + Offset
Get OgmFile, , nTrackNumber

Seek OgmFile, 4 + 24 + Offset
Get OgmFile, , nOffset

Seek OgmFile, 4 + 26 + Offset
Get OgmFile, , FccHandler

Seek OgmFile, 4 + 34 + Offset
Get OgmFile, , Fcc

If FccHandler = "video" Then
Seek OgmFile, 4 + 34 + Offset
Get OgmFile, , Fcc
Seek OgmFile, 4 + 42 + Offset
Get OgmFile, , MicroSec
Seek OgmFile, 4 + 66 + Offset
Get OgmFile, , BitDepth
Seek OgmFile, 4 + 70 + Offset
Get OgmFile, , nWidth
Seek OgmFile, 4 + 74 + Offset
Get OgmFile, , nHeight
ElseIf FccHandler = "audio" Then
Seek OgmFile, 4 + 50 + Offset
Get OgmFile, , SamplingRate
Seek OgmFile, 4 + 70 + Offset
Get OgmFile, , nChannels
Seek OgmFile, 4 + 74 + Offset
Get OgmFile, , wAvgBytesPerSec
Seek OgmFile, 4 + 88 + Offset
Get OgmFile, , nBlockSize
End If

Offset = Offset + nOffset + 28
Loop
Close OgmFile
Err:
End Function

At the beginning of each Ogm file, there are some basic information about each stream.

First of all, I'm not sure about that StreamType that I read, but it seems to be 2 when the chunk carryes Infos about an audio or video stream, while it is set to 0 when the Infos are about somethingelse (see this picture for an example (http://moviemaniac.altervista.org/ogm.gif)).

The Microsec is helpful in finding the framerate, since you can obtain it by dividing 10000000/Microsec

This is all I could retrieve by reading in Binary mode the file, 'couse there's no dll for Visual Basic afaik.

I haven't had enough time to go deeper through this work, but it seems that with a loop you can read each frame and by doin' this it is possible to gather also the video Bitrate, the lenght, and some other Infos like the number of keyframe, the overhead etc.
If someoneelse is interested in doing this, or has any precious informations, please let me know.

that's all
'till I have some more news :D

Bye
and have a good summer
here it's too damn hot :@

Movie ManiacŪ

fccHandler
20th August 2003, 03:39
Originally posted by Movie ManiacŪ

Seek OgmFile, 4 + 34 + Offset
Get OgmFile, , Fcc
Seek OgmFile, 4 + 42 + Offset
Get OgmFile, , MicroSec
Seek OgmFile, 4 + 66 + Offset
Get OgmFile, , BitDepth
Seek OgmFile, 4 + 70 + Offset
Get OgmFile, , nWidth
Seek OgmFile, 4 + 74 + Offset
Get OgmFile, , nHeight
Um, I don't know anything about OGM, but I have a Visual Basic tip for you. The "Get" command accepts a "Seek" position as its second parameter. Why don't you take advantage of it?

For example:
Get OgmFile, 4 + 34 + Offset, Fcc
Get OgmFile, 4 + 42 + Offset, MicroSec
Get OgmFile, 4 + 66 + Offset, BitDepth
Get OgmFile, 4 + 70 + Offset, nWidth
Get OgmFile, 4 + 74 + Offset, nHeight
;)

Movie ManiacŪ
20th August 2003, 10:39
Originally posted by fccHandler
Um, I don't know anything about OGM, but I have a Visual Basic tip for you. The "Get" command accepts a "Seek" position as its second parameter. Why don't you take advantage of it?


Damn

this allow me to dramatically reduce the number of lines of my code :D

Thanx really a lot fccHandler ;)

P.S. I'll post any news asap. I'm studyin' hard today. Hope I'll be able to put hands on my prog tonight. Bye