Log in

View Full Version : how can i get the LBA from DVD episodes?


mrdutchie
19th June 2008, 02:58
writing a program in vb.net and i am able to read the dvd
but I am only getting the beginning and the end sector/lba from a dvd.
but i need to have the begin/end positions from a episode/chapter. (like you can see in smartripper)

how can i get that info?

basicly i used the clsdvd.vb file for vb.net

Private ParsedIFOFile() As struct_IFO_VST_Parse
Private intNbOfIFOFile As Byte
Private oEncoder As New System.Text.ASCIIEncoding
Private oEnc As System.Text.Encoding = oEncoder.GetEncoding(1252)
Private Const ifo_SECTOR_SIZE As Short = 2048
Private Const ifo_CellInfoSize As Short = 24




Public Function fctOpenIFOFile(ByVal strPath As String) As Byte
Dim objDI As New DirectoryInfo(strPath & "VIDEO_TS\")
Dim objIFOFile As FileInfo

For Each objIFOFile In objDI.GetFiles("VTS*.IFO")
'Chargement du fichier IFO en mmoire
ReDim Preserve ParsedIFOFile(intNbOfIFOFile)
ParsedIFOFile(intNbOfIFOFile) = fctParseIFO_VSTFile(intNbOfIFOFile, strPath & "VIDEO_TS\" & objIFOFile.Name)
intNbOfIFOFile = intNbOfIFOFile + 1
Next

objIFOFile = Nothing
objDI = Nothing
End Function


Private Structure struct_IFO_VST_Parse
Dim IFO_FileName As String
Dim FileType_Header As String
Dim LastSectorOfTitle As Long
Dim LastSectorOfIFO As Long
Dim VSTCategory As Long
Dim VersionNumber As Long
Dim EndByteAddress_VTS_MAT As Long
Dim StartSector_MenuVOB As Long
Dim StartSector_TitleVOB As Long
Dim SectorPointer_VTS_PTT_SRPT As Long
Dim SectorPointer_VTS_PGCI As Long
Dim SectorPointer_VTSM_PGCI_UT As Long
Dim SectorPointer_VTS_TMAPTI As Long
Dim SectorPointer_VSTM_C_ADT As Long
Dim SectorPointer_VSTM_VOBU_ADMAP As Long
Dim SectorPointer_VST_C_ADT As Long
Dim SectorPointer_VTS_VOBU_ADMAP As Long
Dim NumberOfProgramChains As Long
Dim ProgramChainInformation() As struct_Program_Chain_Type
Dim VideoAtt_VSTM_VOBS As struct_VideoAttributes_VTS_VOBS
Dim NumOfAudioStreamsIn_VTSM_VOBS As Long
Dim AudioAtt_VTSM_VOBS() As struct_AudioAttributes_VTSM_VTS
Dim NumSubPictureStreams_VTSM_VOBS As Long
Dim SubPictureAtt_VTSM_VOBS As SubPictureAtt_VTSM_VTS_Type
Dim VideoAtt_VTS_VOBS As struct_VideoAttributes_VTS_VOBS
Dim NumAudioStreams_VTS_VOBS As Long
Dim AudioAtt_VTS_VOBS() As struct_AudioAttributes_VTSM_VTS
Dim NumSubPictureStreams_VTS_VOBS As Long
Dim SubPictureAtt_VTS_VOBS() As SubPictureAtt_VTSM_VTS_Type
End Structure




Private Structure struct_VideoAttributes_VTS_VOBS
Dim No_Auto_Letterbox As Boolean
Dim No_Auto_pan_scan As Boolean
Dim Aspect_Ratio As Byte
Dim Video_Standard As Byte
Dim Coding_Mode As Byte
Dim Film As Boolean
Dim LetterBoxed As Boolean
Dim Resolution As Byte
Dim Bitrate As Boolean
Dim Foo As Byte
End Structure

Private Structure struct_Program_Chain_Type
Dim NumberOfPrograms As Byte
Dim NumberOfCells As Byte
Dim PlayBackTime As DVD_TIME_TYPE
'Up to 64 Chapters
Dim PChainInformation() As PGC_Cell_Info_Type
'Currently only implamenting basic useful information
End Structure

Private Structure PGC_Cell_Info_Type
Dim Interleaved As Boolean
Dim CellPlayBackTime As DVD_TIME_TYPE
End Structure

Private Function fctParseIFO_VSTFile(ByVal iIndexFile As Integer, ByVal strFileName As String) As struct_IFO_VST_Parse
Dim strTmpIFOFileIn As String
Dim tmpIFO As New struct_IFO_VST_Parse

Dim intFileLength As Integer
Dim i As Integer

'Read in the Info file name
Dim objFS As FileStream
objFS = File.Open(strFileName, FileMode.Open, FileAccess.Read)
Dim objBR As New BinaryReader(objFS)
strTmpIFOFileIn = System.Text.Encoding.Default.GetString(objBR.ReadBytes(objFS.Length))
intFileLength = strTmpIFOFileIn.Length
objBR.Close()
objBR = Nothing
objFS.Close()
objFS = Nothing

'Used to Check that the file read correctly
'FileOpen(2, "c:\tmp.ifo", OpenMode.Binary)
'FilePut(2, tmpIFOFileIn)
'FileClose(2)

'Save the Ifo File name
tmpIFO.IFO_FileName = strFileName

'See MPUcoder (http://www.mpucoder.com/DVD/ifo.html)
'Parse the File in tmpIFOFileIn
tmpIFO.FileType_Header = (strTmpIFOFileIn).Substring(fctHexOffset("0"), 12)
tmpIFO.LastSectorOfTitle = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("C"), 4))
tmpIFO.LastSectorOfIFO = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("1C"), 4))
tmpIFO.VersionNumber = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("20"), 2))
tmpIFO.VSTCategory = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("22"), 4))

tmpIFO.EndByteAddress_VTS_MAT = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("80"), 4))

tmpIFO.StartSector_MenuVOB = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("C0"), 4))
tmpIFO.StartSector_TitleVOB = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("C4"), 4))

tmpIFO.SectorPointer_VTS_PTT_SRPT = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("C8"), 4))
tmpIFO.SectorPointer_VTS_PGCI = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("CC"), 4))
tmpIFO.SectorPointer_VTSM_PGCI_UT = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("D0"), 4))
tmpIFO.SectorPointer_VTS_TMAPTI = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("D4"), 4))
tmpIFO.SectorPointer_VSTM_C_ADT = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("D8"), 4))
tmpIFO.SectorPointer_VSTM_VOBU_ADMAP = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("DC"), 4))
tmpIFO.SectorPointer_VST_C_ADT = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("E0"), 4))
tmpIFO.SectorPointer_VTS_VOBU_ADMAP = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("E4"), 4))

'VTSM
'Get Video of Main Information
tmpIFO.VideoAtt_VSTM_VOBS = fctVideoAtt_VTS_VOBS((strTmpIFOFileIn).Substring(fctHexOffset("100"), 2))
tmpIFO.NumOfAudioStreamsIn_VTSM_VOBS = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("102"), 2))
'Read in all Audio Track Information
For intFileLength = 0 To tmpIFO.NumOfAudioStreamsIn_VTSM_VOBS - 1
ReDim Preserve tmpIFO.AudioAtt_VTSM_VOBS(intFileLength)
tmpIFO.AudioAtt_VTSM_VOBS(intFileLength) = fctAudioAttVTSM_VTS((strTmpIFOFileIn).Substring(fctHexOffset("104") + (intFileLength * 8), 8))
Next

'Get SubPicture Main info
tmpIFO.NumSubPictureStreams_VTSM_VOBS = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("154"), 2))
tmpIFO.SubPictureAtt_VTSM_VOBS = fctSubPictureAttVTSM_VTS((strTmpIFOFileIn).Substring(fctHexOffset("156"), 6))

'VTS
'Get Video Information
tmpIFO.VideoAtt_VTS_VOBS = fctVideoAtt_VTS_VOBS((strTmpIFOFileIn).Substring(fctHexOffset("200"), 2))

'Get Audio Information
tmpIFO.NumAudioStreams_VTS_VOBS = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("203"), 1))
For intFileLength = 0 To tmpIFO.NumAudioStreams_VTS_VOBS - 1
ReDim Preserve tmpIFO.AudioAtt_VTS_VOBS(intFileLength)
tmpIFO.AudioAtt_VTS_VOBS(intFileLength) = fctAudioAttVTSM_VTS((strTmpIFOFileIn).Substring(fctHexOffset("204") + (intFileLength * 8), 8))
Next

'Get SubPicture info
tmpIFO.NumSubPictureStreams_VTS_VOBS = fctStrByteToHex((strTmpIFOFileIn).Substring(fctHexOffset("255"), 1))
For intFileLength = 0 To tmpIFO.NumSubPictureStreams_VTS_VOBS - 1
ReDim Preserve tmpIFO.SubPictureAtt_VTS_VOBS(intFileLength)
tmpIFO.SubPictureAtt_VTS_VOBS(intFileLength) = fctSubPictureAttVTSM_VTS((strTmpIFOFileIn).Substring(fctHexOffset("256") + (intFileLength * 6), 6))
Next

'Get Program Chain Information
tmpIFO.NumberOfProgramChains = fctStrByteToHex((strTmpIFOFileIn).Substring(tmpIFO.SectorPointer_VTS_PGCI * ifo_SECTOR_SIZE, 2))
For intFileLength = 0 To tmpIFO.NumberOfProgramChains - 1
ReDim Preserve tmpIFO.ProgramChainInformation(intFileLength)
tmpIFO.ProgramChainInformation(intFileLength) = fctProgramChainInformation(intFileLength, strTmpIFOFileIn, tmpIFO)
For i = 0 To tmpIFO.ProgramChainInformation(intFileLength).NumberOfPrograms
ReDim Preserve tmpIFO.ProgramChainInformation(intFileLength).PChainInformation(i)
tmpIFO.ProgramChainInformation(intFileLength).PChainInformation(i) = fctPChainInformation(intFileLength, i, strTmpIFOFileIn, tmpIFO)
Next
Next

'Setup the Return Value
fctParseIFO_VSTFile = tmpIFO

'Manually Release Memory
strTmpIFOFileIn = ""
End Function

Private Function fctVideoAtt_VTS_VOBS(ByVal VideoInfo As String) As struct_VideoAttributes_VTS_VOBS
Dim byte1 As Byte
Dim byte2 As Byte
Dim bytTmpValue As Byte

'Split String for logic AND checks
byte1 = Convert.ToInt32(oEnc.GetBytes(((VideoInfo).Substring(0, 1)).Chars(0))(0))
byte2 = Convert.ToInt32(oEnc.GetBytes(((VideoInfo).Substring(1, 1)).Chars(0))(0))

'BYTE 1
'Using Logic AND's to check if bits are set dec 176 -> bin 10110000
fctVideoAtt_VTS_VOBS.No_Auto_Letterbox = (byte1 And 1)
fctVideoAtt_VTS_VOBS.No_Auto_pan_scan = (byte1 And 2)

'Revers bits
bytTmpValue = 0
If (byte1 And 4) = 4 Then bytTmpValue = 1
If (byte1 And 8) = 8 Then bytTmpValue = bytTmpValue + 2
fctVideoAtt_VTS_VOBS.Aspect_Ratio = bytTmpValue

bytTmpValue = 0
If (byte1 And 16) = 16 Then bytTmpValue = 1
If (byte1 And 32) = 32 Then bytTmpValue = bytTmpValue + 2
fctVideoAtt_VTS_VOBS.Video_Standard = bytTmpValue

bytTmpValue = 0
If (byte1 And 64) = 64 Then bytTmpValue = 1
If (byte1 And 128) = 128 Then bytTmpValue = bytTmpValue + 2
fctVideoAtt_VTS_VOBS.Coding_Mode = bytTmpValue

'BYTE 2
fctVideoAtt_VTS_VOBS.Film = (byte2 And 1)
fctVideoAtt_VTS_VOBS.LetterBoxed = (byte2 And 2)
fctVideoAtt_VTS_VOBS.Bitrate = (byte2 And 16)

bytTmpValue = 0
If (byte2 And 4) = 4 Then bytTmpValue = 1
If (byte2 And 8) = 8 Then bytTmpValue = bytTmpValue + 2
fctVideoAtt_VTS_VOBS.Resolution = bytTmpValue

bytTmpValue = 0
If (byte2 And 32) = 32 Then bytTmpValue = 1
If (byte2 And 64) = 64 Then bytTmpValue = bytTmpValue + 2
If (byte2 And 128) = 128 Then bytTmpValue = bytTmpValue + 4
fctVideoAtt_VTS_VOBS.Foo = bytTmpValue 'Je ne sais pas quoi sert ...
End Function

Private Function fctPChainInformation(ByVal shoProgramChainNumber As Short, ByVal shoCellNumber As Short, ByRef strIFOFileBuffer As String, ByRef tmpIFO As struct_IFO_VST_Parse) As PGC_Cell_Info_Type
Dim ChainLoc As Integer

'Setup the Start loc for the File
ChainLoc = (tmpIFO.SectorPointer_VTS_PGCI * ifo_SECTOR_SIZE) + fctStrByteToHex((strIFOFileBuffer).Substring(tmpIFO.SectorPointer_VTS_PGCI * ifo_SECTOR_SIZE + 12 + (shoProgramChainNumber) * 8, 4))
ChainLoc = ChainLoc + fctStrByteToHex((strIFOFileBuffer).Substring(ChainLoc + 232, 2)) + 1 + (ifo_CellInfoSize * (shoCellNumber - 1))

fctPChainInformation.Interleaved = (fctStrByteToHex((strIFOFileBuffer).Substring(ChainLoc, 1)) And 8)
fctPChainInformation.CellPlayBackTime.hours = fctHexTimeToDecTime(Convert.ToInt32(oEnc.GetBytes(((strIFOFileBuffer).Substring(ChainLoc + 3, 1)).Chars(0))(0)))
fctPChainInformation.CellPlayBackTime.minutes = fctHexTimeToDecTime(Convert.ToInt32(oEnc.GetBytes(((strIFOFileBuffer).Substring(ChainLoc + 4, 1)).Chars(0))(0)))
fctPChainInformation.CellPlayBackTime.seconds = fctHexTimeToDecTime(Convert.ToInt32(oEnc.GetBytes(((strIFOFileBuffer).Substring(ChainLoc + 5, 1)).Chars(0))(0)))
End Function

Private Function fctSubPictureAttVTSM_VTS(ByVal strSubPictureInfo As String) As SubPictureAtt_VTSM_VTS_Type
fctSubPictureAttVTSM_VTS.LanguageCode = (strSubPictureInfo).Substring(2, 1) & (strSubPictureInfo).Substring(3, 1)
fctSubPictureAttVTSM_VTS.CodeExtention = Convert.ToInt32(oEnc.GetBytes((((strSubPictureInfo).Substring(5, 1)).Chars(0)))(0))
End Function

Private Function fctProgramChainInformation(ByVal shoProgramChainNumber As Short, ByRef strIFOFileBuffer As String, ByRef tmpIFO As struct_IFO_VST_Parse) As struct_Program_Chain_Type
Dim ChainLoc As Integer

'Setup the Start loc for the File
ChainLoc = (tmpIFO.SectorPointer_VTS_PGCI * ifo_SECTOR_SIZE) + fctStrByteToHex((strIFOFileBuffer).Substring(tmpIFO.SectorPointer_VTS_PGCI * ifo_SECTOR_SIZE + 12 + (shoProgramChainNumber) * 8, 4))

'The Program Number
fctProgramChainInformation.NumberOfPrograms = fctStrByteToHex((strIFOFileBuffer).Substring(ChainLoc + 2, 1))

'Number of Cells in Program Chain
fctProgramChainInformation.NumberOfCells = fctStrByteToHex((strIFOFileBuffer).Substring(ChainLoc + 3, 1))

'Get DVD Chain Type Info
fctProgramChainInformation.PlayBackTime.hours = fctHexTimeToDecTime(Convert.ToInt32(((strIFOFileBuffer).Substring(ChainLoc + 4, 1)).Chars(0)))
fctProgramChainInformation.PlayBackTime.minutes = fctHexTimeToDecTime(Convert.ToInt32(((strIFOFileBuffer).Substring(ChainLoc + 5, 1)).Chars(0)))
fctProgramChainInformation.PlayBackTime.seconds = fctHexTimeToDecTime(Convert.ToInt32(((strIFOFileBuffer).Substring(ChainLoc + 6, 1)).Chars(0)))
End Function

Private Function fctStrByteToHex(ByVal strHexString As String) As Integer
Dim i As Long
Dim HexTotal As Double
Dim HexMod As Double
Dim CharNum As Long

HexTotal = 0
For i = 0 To (strHexString).Length - 1
CharNum = Convert.ToInt32(oEnc.GetBytes(strHexString.Substring(i, 1).Chars(0))(0))
If i <> (strHexString).Length Then
HexMod = 256 ^ (((strHexString).Length - 1) - i)
HexTotal = HexTotal + CharNum * HexMod
Else
HexTotal = HexTotal + CharNum
End If
Next
fctStrByteToHex = HexTotal
End Function

Private Function fctHexTimeToDecTime(ByVal bytAmountHex As Byte) As Byte
Select Case bytAmountHex
Case Is < 9
fctHexTimeToDecTime = bytAmountHex
Case Is < fctHexStrToHex("19")
fctHexTimeToDecTime = bytAmountHex - 6
Case Is < fctHexStrToHex("29")
fctHexTimeToDecTime = bytAmountHex - 12
Case Is < fctHexStrToHex("39")
fctHexTimeToDecTime = bytAmountHex - 18
Case Is < fctHexStrToHex("49")
fctHexTimeToDecTime = bytAmountHex - 24
Case Is < fctHexStrToHex("59")
fctHexTimeToDecTime = bytAmountHex - 30
End Select
End Function