Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

.Net Reading + writing bytes help

Back to Forum: Tech Off
  • User profile image
    Lee_Dale

    Ok so my application needs to merge .VOB files from a DVD into one big mpeg2 file, I have the following routine that does the merging, my first problem is am I reading and writing the bytes the fastest possible way? if not can anyone recommend and faster method. Secondly the resulting file doesnt seem to contain all the bytes, can anyone see a problem with what I am doing am I missing some bytes somewhere.  Am I right in what im doing, if I read all the bytes from the VOB files in order and copy them in sequence to another file will the resulting file be a combination of the VOB files? Im pretty sure it should be, but it seems to do the first VOB file correctly it then goes wrongs somewhere, when I open up the file its not a long as it should be. Am i right in saying VOB files are headerless and dont need anything else with them? Any help would be grateful, here my routine:


    Public Sub OpenDVD(ByVal path As String)

            Dim file As System.IO.FileInfo = New System.IO.FileInfo(path)

            If file.Exists Then
                StartPlayback(path)
            End If

            Dim videoFiles() As System.IO.FileInfo
            Dim fileExists As Boolean = True
            Dim index As Integer
            Dim convertEventArgs As ConvertDVDEventArgs = New ConvertDVDEventArgs
            Dim totalFileLengthKB As Long

            Do Until fileExists = False
                Dim fileName As String = path & "\VTS_01_" & (index + 1).ToString & ".VOB"
                Dim fileInfo As System.IO.FileInfo = New System.IO.FileInfo(fileName)
                fileExists = fileInfo.Exists
                If fileExists Then
                    ReDim Preserve videoFiles(index)
                    videoFiles(index) = fileInfo
                End If
                index = index + 1
            Loop

            index = 0

            Dim newFileInfo As System.IO.FileInfo = New System.IO.FileInfo(videoFiles(index).DirectoryName & "\game.mpg")

            If newFileInfo.Exists Then
                StartPlayback(newFileInfo.FullName)
            Else
                Dim wholeFile As System.IO.FileStream = New System.IO.FileStream(videoFiles(index).DirectoryName & "\game.mpg", IO.FileMode.CreateNew)
                Dim bytes(1023) As Byte
                Dim kbCount As Long
                Dim percentDone As Integer

                Do Until index = videoFiles.GetUpperBound(0)
                    totalFileLengthKB = totalFileLengthKB + (videoFiles(index).Length \ 1024)
                    index = index + 1
                Loop

                index = 0
                Do Until index = videoFiles.GetUpperBound(0)
                    Dim videoFile As System.IO.FileStream = New System.IO.FileStream(videoFiles(index).FullName, IO.FileMode.Open)

                    Do Until videoFile.Read(bytes, 0, bytes.Length) = 0
                        wholeFile.Write(bytes, 0, bytes.Length)
                        kbCount = kbCount + 1
                        percentDone = CType(((kbCount / totalFileLengthKB) * 100), Integer)
                        If convertEventArgs.PercentageDone <> percentDone Then
                            convertEventArgs.PercentageDone = percentDone
                            RaiseEvent ConvertDVDFeedback(Me, convertEventArgs)
                        End If
                    Loop

                    videoFile.Close()
                    index = index + 1
                Loop

                wholeFile.Close()

                StartPlayback(wholeFile.Name)
            End If

        End Sub


  • User profile image
    amotif

    Dim bytes(1023) As Byte is 1024 bytes, right? (This aspect of VB alone would drive me nuts.) You'd probably be better off with a larger chunk size, such as 4, 16, or 64 KB. Maybe even larger. A profiler or crude perf measuring code could help you figure that out.

  • User profile image
    Lee_Dale

    Yep your right I will be using larger chunks of bytes in the future, the only reason I used 1kb chunks is simply because I had to demo the application last week and I needed my status form working and it was easier for me to just increment it 1kb at a time instead of working it all out  (I need to knock it up in a short time frame).

    I've also found a 'out by one' error in the above code and a few other things that ive rectified. The weired thing is that the resulting 'merged' file is the exact amount of kb's as a combination of the 4 vob file, but when played back something is wrong with the file it misses chunks of video out? I can't find enough out about merging vob files on the web.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.