Gets or sets a value that indicates whether samples are compressed using temporal (interframe) compression.
public bool TemporalCompression { get; set; } Public Property TemporalCompression As Boolean
true if the samples are compressed using temporal (interframe) compression; false, otherwise.
using Leadtools;using Leadtools.Multimedia;using LeadtoolsMultimediaExamples.Fixtures;public bool _result = false;public ConvertCtrlForm _form = new ConvertCtrlForm();public void GetFormatDataExample(){// reference the convert controlConvertCtrl convertctrl = _form.ConvertCtrl;// input file and output filesstring inFile = Path.Combine(LEAD_VARS.MediaDir, "MediaType_ShortSource.avi");string outFilePfx = Path.Combine(LEAD_VARS.MediaDir, "MediaType_GetFormatDataExample");string sampleFileName;// This example demonstrates how to use SampleTarget and MediaSample// objects to directly access sample frames from a conversion graph.try{// set the source and target filesconvertctrl.SourceFile = inFile;// set the previewconvertctrl.Preview = true;// create a new sample targetSampleTarget st = new SampleTarget();// set the target media type for the video streamMediaType mtTarget = new MediaType();mtTarget.Type = Constants.MEDIATYPE_Video;mtTarget.SubType = Constants.MEDIASUBTYPE_RGB24;// set the sample target's accepted media typest.SetAcceptedMediaType(mtTarget);// assign the sample target to the capture controlconvertctrl.TargetObject = st;convertctrl.TargetFormat = TargetFormatType.StillImage;// run the convertconvertctrl.StartConvert();MediaSample msFrame = st.GetSample(1000);long sampleStart, sampleStop;while (msFrame != null){// get the sample target's connected media typeMediaType mtSample = st.GetConnectedMediaType();// demonstrate media type properties copyMediaType mtCopy = new MediaType();CopyMediaTypeAttributes(mtSample, mtCopy);// get the sample timesmsFrame.GetTime(out sampleStart, out sampleStop);// create the file name for this frame bitmapsampleFileName = string.Format("{0}_{1}-{2}.bmp", outFilePfx, sampleStart, sampleStop);// create the bitmap for this frameWriteSampleBitmap(sampleFileName, msFrame, mtSample); // mtCopy);try{// create a media sample using the captured sample from abovemsFrame = st.GetSample(1000);}catch (COMException cex){// if we have reached the end of stream we are finishedif (cex.ErrorCode == (int)ErrorCode.VFW_E_SAMPLE_REJECTED_EOS|| cex.ErrorCode == (int)ErrorCode.VFW_E_WRONG_STATE)break;else if (cex.ErrorCode == (int)ErrorCode.VFW_E_TIMEOUT)continue;elsethrow cex;}// set the result_result = true;// we'll loop on the state and pump messages for this example.// but you should not need to if running from a Windows Forms application.if (convertctrl.State == ConvertState.Running)Application.DoEvents();}}catch (Exception){_result = false;}}private bool CopyMediaTypeAttributes(MediaType pSource, MediaType pDest){int fmtDataSize;// return error if either source or dest is nullif (pSource == null || pDest == null)return false;// get the format data sizefmtDataSize = pSource.FormatSize;// any format dataif (fmtDataSize > 0)pDest.SetFormatData(fmtDataSize,pSource.GetFormatData(fmtDataSize)); // yes, then copy itelsepDest.FormatSize = 0; // no, just set the dest size to zero// copy type, subtype, formattypepDest.Type = pSource.Type;pDest.SubType = pSource.SubType;pDest.FormatType = pSource.FormatType;// set dest fixed size samples and temporal compressionpDest.FixedSizeSamples = pSource.FixedSizeSamples;pDest.TemporalCompression = pSource.TemporalCompression;// copy samplesizepDest.SampleSize = pSource.SampleSize;return true;}private Bitmap WriteSampleBitmap(string outFile, MediaSample ms, MediaType mt){// get the video informationVideoInfoHeader vih = mt.GetVideoFormatData();// create a bitmap to hold the sample and copy itBitmap bmp = new Bitmap(vih.bmiHeader.biWidth, vih.bmiHeader.biHeight, FormatFromBitCount(vih.bmiHeader.biBitCount));BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);Marshal.Copy(ms.Buffer, 0, bmpData.Scan0, GetBitmapSize(bmp, vih.bmiHeader.biBitCount));bmp.UnlockBits(bmpData);// flip the upside down bufferbmp.RotateFlip(RotateFlipType.Rotate180FlipX);// save the imagebmp.Save(outFile, ImageFormat.Bmp);return bmp;}private PixelFormat FormatFromBitCount(int bitCount){switch (bitCount){case 8:return PixelFormat.Format8bppIndexed;case 16:return PixelFormat.Format16bppRgb555;case 32:return PixelFormat.Format32bppRgb;case 48:return PixelFormat.Format48bppRgb;case 24:return PixelFormat.Format24bppRgb;}throw new Exception("Unrecognized bit count");}private int GetBitmapSize(Bitmap bmp, int bitCount){int pixelSize = (int)Math.Log((double)bitCount);return (bmp.Width * pixelSize + pixelSize & ~3) * bmp.Height;}private int GetBitmapScanRowSize(int bmpSize, int stride, int width){return bmpSize / (stride / width);}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 Sub GetFormatDataExample()' reference the convert controlDim convertctrl As ConvertCtrl = _form.ConvertCtrl' input file and output filesDim inFile As String = Path.Combine(LEAD_VARS.MediaDir, "MediaType_ShortSource.avi")Dim outFilePfx As String = Path.Combine(LEAD_VARS.MediaDir, "MediaType_GetFormatDataExample")Dim sampleFileName As String' This example demonstrates how to use SampleTarget and MediaSample' objects to directly access sample frames from a conversion graph.Try' set the source and target filesconvertctrl.SourceFile = inFile' set the previewconvertctrl.Preview = True' create a new sample targetDim st As SampleTarget = New SampleTarget()' set the target media type for the video streamDim mtTarget As MediaType = New MediaType()mtTarget.Type = Leadtools.Multimedia.Constants.MEDIATYPE_VideomtTarget.SubType = Leadtools.Multimedia.Constants.MEDIASUBTYPE_RGB24' set the sample target's accepted media typest.SetAcceptedMediaType(mtTarget)' assign the sample target to the capture controlconvertctrl.TargetObject = stconvertctrl.TargetFormat = TargetFormatType.StillImage' run the convertconvertctrl.StartConvert()Dim msFrame As MediaSample = st.GetSample(1000)Dim sampleStart, sampleStop As LongDo While Not msFrame Is Nothing' get the sample target's connected media typeDim mtSample As MediaType = st.GetConnectedMediaType()' demonstrate media type properties copyDim mtCopy As MediaType = New MediaType()CopyMediaTypeAttributes(mtSample, mtCopy)' get the sample timesmsFrame.GetTime(sampleStart, sampleStop)' create the file name for this frame bitmapsampleFileName = String.Format("{0}_{1}-{2}.bmp", outFilePfx, sampleStart, sampleStop)' create the bitmap for this frameWriteSampleBitmap(sampleFileName, msFrame, mtSample) ' mtCopy);Try' create a media sample using the captured sample from abovemsFrame = st.GetSample(1000)Catch cex As COMException' if we have reached the end of stream we are finishedIf cex.ErrorCode = CInt(ErrorCode.VFW_E_SAMPLE_REJECTED_EOS) _OrElse cex.ErrorCode = CInt(ErrorCode.VFW_E_WRONG_STATE) ThenExit DoElseIf cex.ErrorCode = CInt(ErrorCode.VFW_E_TIMEOUT) ThenContinue DoElseThrow cexEnd IfEnd Try' set the result_result = True' we'll loop on the state and pump messages for this example.' but you should not need to if running from a Windows Forms application.If convertctrl.State = ConvertState.Running ThenApplication.DoEvents()End IfLoopCatch e1 As Exception_result = FalseEnd TryEnd SubPrivate Function CopyMediaTypeAttributes(ByVal pSource As MediaType, ByVal pDest As MediaType) As BooleanDim fmtDataSize As Integer' return error if either source or dest is nullIf pSource Is Nothing OrElse pDest Is Nothing ThenReturn FalseEnd If' get the format data sizefmtDataSize = pSource.FormatSize' any format dataIf fmtDataSize > 0 ThenpDest.SetFormatData(fmtDataSize, pSource.GetFormatData(fmtDataSize)) ' yes, then copy itElsepDest.FormatSize = 0 ' no, just set the dest size to zeroEnd If' copy type, subtype, formattypepDest.Type = pSource.TypepDest.SubType = pSource.SubTypepDest.FormatType = pSource.FormatType' set dest fixed size samples and temporal compressionpDest.FixedSizeSamples = pSource.FixedSizeSamplespDest.TemporalCompression = pSource.TemporalCompression' copy samplesizepDest.SampleSize = pSource.SampleSizeReturn TrueEnd FunctionPrivate Function WriteSampleBitmap(ByVal outFile As String, ByVal ms As MediaSample, ByVal mt As MediaType) As Bitmap' get the video informationDim vih As VideoInfoHeader = mt.GetVideoFormatData()' create a bitmap to hold the sample and copy itDim bmp As Bitmap = New Bitmap(vih.bmiHeader.biWidth, vih.bmiHeader.biHeight, FormatFromBitCount(vih.bmiHeader.biBitCount))Dim bmpData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat)Marshal.Copy(ms.Buffer, 0, bmpData.Scan0, GetBitmapSize(bmp, vih.bmiHeader.biBitCount))bmp.UnlockBits(bmpData)' flip the upside down bufferbmp.RotateFlip(RotateFlipType.Rotate180FlipX)' save the imagebmp.Save(outFile, ImageFormat.Bmp)Return bmpEnd FunctionPrivate Function FormatFromBitCount(ByVal bitCount As Integer) As PixelFormatSelect Case bitCountCase 8Return PixelFormat.Format8bppIndexedCase 16Return PixelFormat.Format16bppRgb555Case 32Return PixelFormat.Format32bppRgbCase 48Return PixelFormat.Format48bppRgbCase 24Return PixelFormat.Format24bppRgbEnd SelectThrow New Exception("Unrecognized bit count")End FunctionPrivate Function GetBitmapSize(ByVal bmp As Bitmap, ByVal bitCount As Integer) As IntegerDim pixelSize As Integer = CInt(Math.Log(CDbl(bitCount)))Return (bmp.Width * pixelSize + pixelSize And (Not 3)) * bmp.HeightEnd FunctionPrivate Function GetBitmapScanRowSize(ByVal bmpSize As Integer, ByVal stride As Integer, ByVal width As Integer) As IntegerReturn CInt(bmpSize / (stride / width))End FunctionPublic 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
