Invalidates the stream time.
public void ResetTime() Public Sub ResetTime() public:void ResetTime();
If the method fails, an error is raised. For more information, refer to the Error Codes. This will cause the GetTime method to raise a VFW_E_SAMPLE_TIME_NOT_SET error. Please note: that VFW_E_SAMPLE_TIME_NOT_SET is a DirectShow error code.
using Leadtools;using Leadtools.Multimedia;using LeadtoolsMultimediaExamples.Fixtures;public bool _result = false;public ConvertCtrlForm _form = new ConvertCtrlForm();public ConvertCtrl _convertctrl;// input files and output filestring inFile1 = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source1.avi");string inFile2 = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source2.avi");string outFile = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_ConcatAVIFilesExample.avi");public void ConcatAVIFilesExample(){ConvertCtrl pConvert1;ConvertCtrl pConvert2;MultiStreamSource pMSSource;MultiStreamTarget pMSTarget;Int64 lStart;MediaType pmt;MediaType pInsertedMediaType;pConvert1 = new ConvertCtrl(true);pConvert2 = new ConvertCtrl(true);pMSSource = new MultiStreamSource();pMSTarget = new MultiStreamTarget();// set the start time to be 0lStart = 0;// set the input filenamepConvert1.SourceFile = inFile1;// set the output sample to a target objectpMSTarget.StreamCount = 2;// set the target media types for video and audio streamspmt = new MediaType();pmt.Type = Constants.MEDIATYPE_Video;pMSTarget.SetAcceptedMediaType(0, pmt);pmt.Type = Constants.MEDIATYPE_Audio;pMSTarget.SetAcceptedMediaType(1, pmt);pmt = null;// get the inserted media type for the first streampInsertedMediaType = pMSTarget.GetAcceptedMediaType(0);pInsertedMediaType = null;// set convert 1 target objectpConvert1.TargetObject = pMSTarget;// start the source conversion, so we can get the media sample formatpConvert1.StartConvert();// initialize convert 2// get the output media sample format and put it into the source objectpMSSource.StreamCount = 2;pmt = pMSTarget.GetConnectedMediaType(0);pMSSource.SetMediaType(0, pmt);pmt = null;pmt = pMSTarget.GetConnectedMediaType(1);pMSSource.SetMediaType(1, pmt);pmt = null;// get the inserted media type for the first streampInsertedMediaType = pMSSource.GetMediaType(0);pInsertedMediaType = null;// set the output filenamepConvert2.TargetFile = outFile;// set the source for convert 2pConvert2.SourceObject = pMSSource;// start the dest conversionpConvert2.StartConvert();// convert first fileConcateFile(pConvert1, pMSTarget, pMSSource, ref lStart);/*Restrict the output format to the media type of the source for the first fileThat is because the two files must have the same media type for both video and audioWith video, you have to make sure the files have the same frame rate! Minor changes inthe frame rate might make the connection fail!The control will tolerate differences in frame rate if you comment the next line*/pmt = pMSTarget.GetConnectedMediaType(0);pMSTarget.SetAcceptedMediaType(0, pmt);pmt = null;pmt = pMSTarget.GetConnectedMediaType(1);pMSTarget.SetAcceptedMediaType(1, pmt);pmt = null;// change the source file to second filepConvert1.SourceFile = inFile2;// start converting againpConvert1.StartConvert();// convert second fileConcateFile(pConvert1, pMSTarget, pMSSource, ref lStart);// deliver end of sample to stop the conversionpMSSource.DeliverEndOfStream(0, 1000);pMSSource.DeliverEndOfStream(1, 1000);if (pConvert2.State == ConvertState.Running)pConvert2.StopConvert();// free the source and target objectspConvert2.ResetSource();pConvert1.ResetTarget();pConvert1.Dispose();pConvert2.Dispose();pMSSource.Dispose();pMSTarget.Dispose();_result = File.Exists(outFile);}void ConcateFile(ConvertCtrl pConvert1,MultiStreamTarget pMSTarget,MultiStreamSource pMSSource,ref long lStart){MediaSample pmsSrc = null;MediaSample pmsDst = null;long MediaTimeStart;long MediaTimeStop;long LastStart;long LastStop;int lSampleStream;int lActualDataLength;LastStop = 0;do{// get the sample, allowing 10 s for the operation to completetry{lSampleStream = pMSTarget.WaitForSample(1000);}catch (COMException cex){if (cex.ErrorCode == (int)ErrorCode.VFW_E_TIMEOUT){// end of the streambreak;}_result = false;break;}try{// get the target samplepmsSrc = pMSTarget.GetSample(lSampleStream, 0);// get the source bufferpmsDst = pMSSource.GetSampleBuffer(lSampleStream, 2000);}catch (Exception){_result = false;break;}// get the media timepmsSrc.GetMediaTime(out MediaTimeStart, out MediaTimeStop);// get the source sample timepmsSrc.GetTime(out LastStart, out LastStop);// set the destination sample timepmsDst.SetTime(lStart + LastStart, lStart + LastStop);// copy the datalActualDataLength = pmsSrc.ActualDataLength;// set the destination buffer// we could Marshal the unmanaged buffer here, but no need since we are mearly// setting the destination to the source buffer contents (unaltered data)pmsDst.SetData(lActualDataLength, pmsSrc.GetData(lActualDataLength));// copy the other flagspmsDst.Discontinuity = pmsSrc.Discontinuity;pmsDst.Preroll = pmsSrc.Preroll;pmsDst.SyncPoint = pmsSrc.SyncPoint;// release the source samplepmsSrc = null;// deliver the destination samplepMSSource.DeliverSample(lSampleStream, 1000, pmsDst);// release the destination samplepmsDst = null;}while (true);pConvert1.StopConvert();lStart = LastStop;}static class LEAD_VARS{public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media";}
Imports LeadtoolsImports Leadtools.MultimediaImports LeadtoolsMultimediaExamples.FixturesPublic _result As Boolean = FalsePublic _form As ConvertCtrlForm = New ConvertCtrlForm()Public _convertctrl As ConvertCtrl' input files and output filePrivate inFile1 As String = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source1.avi")Private inFile2 As String = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source2.avi")Private outFile As String = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_ConcatAVIFilesExample.avi")Public Sub ConcatAVIFilesExample()Dim pConvert1 As ConvertCtrlDim pConvert2 As ConvertCtrlDim pMSSource As MultiStreamSourceDim pMSTarget As MultiStreamTargetDim lStart As Int64Dim pmt As MediaTypeDim pInsertedMediaType As MediaTypepConvert1 = New ConvertCtrl(True)pConvert2 = New ConvertCtrl(True)pMSSource = New MultiStreamSource()pMSTarget = New MultiStreamTarget()' set the start time to be 0lStart = 0' set the input filenamepConvert1.SourceFile = inFile1' set the output sample to a target objectpMSTarget.StreamCount = 2' set the target media types for video and audio streamspmt = New MediaType()pmt.Type = Leadtools.Multimedia.Constants.MEDIATYPE_VideopMSTarget.SetAcceptedMediaType(0, pmt)pmt.Type = Leadtools.Multimedia.Constants.MEDIATYPE_AudiopMSTarget.SetAcceptedMediaType(1, pmt)pmt = Nothing' get the inserted media type for the first streampInsertedMediaType = pMSTarget.GetAcceptedMediaType(0)pInsertedMediaType = Nothing' set convert 1 target objectpConvert1.TargetObject = pMSTarget' start the source conversion, so we can get the media sample formatpConvert1.StartConvert()' initialize convert 2' get the output media sample format and put it into the source objectpMSSource.StreamCount = 2pmt = pMSTarget.GetConnectedMediaType(0)pMSSource.SetMediaType(0, pmt)pmt = Nothingpmt = pMSTarget.GetConnectedMediaType(1)pMSSource.SetMediaType(1, pmt)pmt = Nothing' get the inserted media type for the first streampInsertedMediaType = pMSSource.GetMediaType(0)pInsertedMediaType = Nothing' set the output filenamepConvert2.TargetFile = outFile' set the source for convert 2pConvert2.SourceObject = pMSSource' start the dest conversionpConvert2.StartConvert()' convert first fileConcateFile(pConvert1, pMSTarget, pMSSource, lStart)''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'pmt = pMSTarget.GetConnectedMediaType(0)pMSTarget.SetAcceptedMediaType(0, pmt)pmt = Nothingpmt = pMSTarget.GetConnectedMediaType(1)pMSTarget.SetAcceptedMediaType(1, pmt)pmt = Nothing' change the source file to second filepConvert1.SourceFile = inFile2' start converting againpConvert1.StartConvert()' convert second fileConcateFile(pConvert1, pMSTarget, pMSSource, lStart)' deliver end of sample to stop the conversionpMSSource.DeliverEndOfStream(0, 1000)pMSSource.DeliverEndOfStream(1, 1000)If pConvert2.State = ConvertState.Running ThenpConvert2.StopConvert()End If' free the source and target objectspConvert2.ResetSource()pConvert1.ResetTarget()pConvert1.Dispose()pConvert2.Dispose()pMSSource.Dispose()pMSTarget.Dispose()_result = File.Exists(outFile)End SubPrivate Sub ConcateFile(ByVal pConvert1 As ConvertCtrl,ByVal pMSTarget As MultiStreamTarget,ByVal pMSSource As MultiStreamSource,ByRef lStart As Long)Dim pmsSrc As MediaSample = NothingDim pmsDst As MediaSample = NothingDim MediaTimeStart As LongDim MediaTimeStop As LongDim LastStart As LongDim LastStop As LongDim lSampleStream As IntegerDim lActualDataLength As IntegerLastStop = 0Do' get the sample, allowing 10 s for the operation to completeTrylSampleStream = pMSTarget.WaitForSample(1000)Catch cex As COMExceptionIf cex.ErrorCode = CInt(ErrorCode.VFW_E_TIMEOUT) Then' end of the streamExit DoEnd If_result = FalseExit DoEnd TryTry' get the target samplepmsSrc = pMSTarget.GetSample(lSampleStream, 0)' get the source bufferpmsDst = pMSSource.GetSampleBuffer(lSampleStream, 2000)Catch e1 As Exception_result = FalseExit DoEnd Try' get the media timepmsSrc.GetMediaTime(MediaTimeStart, MediaTimeStop)' get the source sample timepmsSrc.GetTime(LastStart, LastStop)' set the destination sample timepmsDst.SetTime(lStart + LastStart, lStart + LastStop)' copy the datalActualDataLength = pmsSrc.ActualDataLength' set the destination buffer' we could Marshal the unmanaged buffer here, but no need since we are mearly' setting the destination to the source buffer contents (unaltered data)pmsDst.SetData(lActualDataLength, pmsSrc.GetData(lActualDataLength))' copy the other flagspmsDst.Discontinuity = pmsSrc.DiscontinuitypmsDst.Preroll = pmsSrc.PrerollpmsDst.SyncPoint = pmsSrc.SyncPoint' release the source samplepmsSrc = Nothing' deliver the destination samplepMSSource.DeliverSample(lSampleStream, 1000, pmsDst)' release the destination samplepmsDst = NothingLoop While TruepConvert1.StopConvert()lStart = LastStopEnd SubPublic NotInheritable Class LEAD_VARSPublic Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
