01-30-2008, 10:59
|
justinpdavis
Joined on 01-25-2008
Posts 4
|
A Time-out has expired error on avi merge.
Attachment: error.JPG
|
 
 
|
|
|
I have a simple project that takes two avi files and merges them. However, i am getting a "A time-out has expired" on the convertfile function at SampleStream = SampleTarget.WaitForSample(10000) line of code.
Public Function Merge(ByVal pFirst As String, ByVal pSecond As String, ByVal pFinal As String) As Boolean
Dim r As Boolean = True
Try
Dim StartHi As Long ' start time high
Dim StartLo As Long ' start time low
Dim SampleTarget As ltmmMultiStreamTarget ' sample target for ltmmConvertCtrl1
Dim SampleSource As ltmmMultiStreamSource ' sample target for ltmmConvertCtrl1
Dim mt As ltmmMediaType
Dim InsertedMediaType As ltmmMediaType
' set the start time to be 0
StartHi = 0
StartLo = 0
' INITIALIZE ltmmConvertCtrl1
' set the input filename
ltmmConvertCtrl1.sourcefile = pFirst
' set the output sample to a target object
SampleTarget = New ltmmMultiStreamTarget
SampleTarget.StreamCount = 2
mt = New ltmmMediaType
mt.Type = ltmmMEDIATYPE_Video
SampleTarget.SetAcceptedMediaType(0, mt)
mt.ResetMediaType()
mt.Type = ltmmMEDIATYPE_Audio
SampleTarget.SetAcceptedMediaType(1, mt)
' get the inserted media type for the first stream
InsertedMediaType = SampleTarget.GetAcceptedMediaType(0)
InsertedMediaType = Nothing
ltmmConvertCtrl1.TargetObject = SampleTarget
' START the source conversion, so we can get the media sample format
ltmmConvertCtrl1.StartConvert()
' INITIALIZE ltmmConvertCtrl2
' create a source object
SampleSource = New ltmmMultiStreamSource
' get the output media sample format and put it into the source object
SampleSource.StreamCount = 2
SampleSource.SetMediaType(0, SampleTarget.GetConnectedMediaType(0))
SampleSource.SetMediaType(1, SampleTarget.GetConnectedMediaType(1))
' get the inserted media type for the first stream
InsertedMediaType = SampleSource.GetMediaType(0)
InsertedMediaType = Nothing
' set the output filename
ltmmConvertCtrl2.TargetFile = pFinal
ltmmConvertCtrl2.SourceObject = SampleSource
' start the dest conversion
ltmmConvertCtrl2.StartConvert()
'Form1.Caption = "Converting file1..."
' convert first file
ConvertFile(SampleTarget, SampleSource, StartHi, StartLo)
' Restrict the output format to the media type of the source for the first file
' That is because the two files must have the same media type for both video and audio
' With video, you have to make sure the files have the same frame rate! Minor changes in
' the frame rate might make the connection fail!
' The control will tolerate differences in frame rate if you comment the next line
SampleTarget.SetAcceptedMediaType(0, SampleTarget.GetConnectedMediaType(0))
SampleTarget.SetAcceptedMediaType(1, SampleTarget.GetConnectedMediaType(1))
' change the source file to second file
ltmmConvertCtrl1.sourcefile = pSecond
' start converting again
ltmmConvertCtrl1.StartConvert()
'Form1.Caption = "Converting file2..."
' convert second file
ConvertFile(SampleTarget, SampleSource, StartHi, StartLo)
' deliver end of sample to stop the conversion
SampleSource.DeliverEndOfStream(0, 1000)
SampleSource.DeliverEndOfStream(1, 1000)
Do While (ltmmConvertCtrl2.State = ltmmConvert_State_Running)
Application.DoEvents()
Loop
'Form1.Caption = "Done"
' free the source and target objects
ltmmConvertCtrl1.ResetTarget()
ltmmConvertCtrl2.ResetSource()
Catch ex As Exception
r = False
End Try
Return r
End Function
Private Sub ConvertFile(ByVal SampleTarget As ltmmMultiStreamTarget, ByVal SampleSource As ltmmMultiStreamSource, ByRef StartHi As Long, ByRef StartLo As Long)
Dim msSrc As ltmmMediaSample
Dim msDst As ltmmMediaSample
Dim LastStartHi As Long
Dim LastStartLo As Long
Dim LastStopHi As Long
Dim LastStopLo As Long
Dim SampleStream As Long
Dim nFrames As Long
LastStopHi = 0
LastStopLo = 0
nFrames = 0
Do
nFrames = nFrames + 1
Debug.Print("nFrames=", nFrames)
' get the sample, allowing 10 s for the operation to complete
On Error GoTo EndConvert
SampleStream = SampleTarget.WaitForSample(10000)
msSrc = SampleTarget.GetSample(SampleStream, 0)
Debug.Print("Stream=", SampleStream)
msDst = SampleSource.GetSampleBuffer(SampleStream, 1000)
' copy the sample time
On Error GoTo ResetTime
' set the sample time
msSrc.GetTime(LastStartHi, LastStartLo, LastStopHi, LastStopLo)
' get the sample time
msDst.SetTime(StartHi + LastStartHi, StartLo + LastStartLo, StartHi + LastStopHi, StartLo + LastStopLo)
GoTo NoResetTime
ResetTime:
msDst.ResetTime()
NoResetTime:
' copy the data
On Error GoTo EndConvert
msDst.SetData(msSrc.ActualDataLength, msSrc.GetData(msSrc.ActualDataLength))
' copy the other flags
msDst.Discontinuity = msSrc.Discontinuity
msDst.Preroll = msSrc.Preroll
msDst.SyncPoint = msSrc.SyncPoint
' release the source sample
msSrc = Nothing
' deliver the destination sample
SampleSource.DeliverSample(SampleStream, 1000, msDst)
' release the destination sample
msDst = Nothing
Loop While (1)
ltmmConvertCtrl1.StopConvert()
StartHi = LastStopHi
StartLo = LastStopLo
Exit Sub
EndConvert:
ltmmConvertCtrl1.StopConvert()
StartHi = LastStopHi
StartLo = LastStopLo
Exit Sub
End Sub
|
|
|
|
|
Report
|
|
|
|