LEADTOOLS Multimedia (Leadtools.MediaFoundation assembly)

Reset Method (TargetFormat)

Show in webframe
Example 



Resets the target format.
Syntax
'Declaration
 
Public Sub Reset() 
'Usage
 
Dim instance As TargetFormat
 
instance.Reset()
public void Reset()
public:
void Reset(); 
Remarks
This method will reset the target format properties to their default values. Users typically call this method to remove any values set on the video or audio attributes, also it will reset the container type. If the method fails, an error is raised.

For more information, refer to the Error Codes.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.MediaFoundation
Imports LeadtoolsMediaFoundationExamples.Fixtures

Public _result As Boolean = False
Public _form As ConvertCtrlForm = New ConvertCtrlForm()
Public _convertctrl As ConvertCtrl
Public Sub VideoFormatsExample()
   ' reference the convert control
   _convertctrl = _form.ConvertCtrl

   ' input and output files
   Dim inFile As String = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source.avi")
   Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_VideoFormatsExample.mp4")

   Try
      ' set the source for conversion
      _convertctrl.SourceFile = inFile

      ' get MP4 target format
           Dim tf As TargetFormat = _convertctrl.TargetFormats(TargetFormatType.MP4)

      ' reset MP4 target format
      tf.Reset()

      ' select MP4 target format
      tf.Selected = True

      ' select H264 video format
      Dim index As Integer = -1
      Dim trgvideoformats As TargetVideoFormats = _convertctrl.TargetFormats(_convertctrl.TargetFormat).VideoFormats
      index = trgvideoformats.IndexOf("{34363248-0000-0010-8000-00AA00389B71}") ' H264
      trgvideoformats.Selection = index

      ' select AAC audio format
      Dim trgaudioformats As TargetAudioFormats = _convertctrl.TargetFormats(_convertctrl.TargetFormat).AudioFormats
      index = trgaudioformats.IndexOf("{00001610-0000-0010-8000-00AA00389B71}") ' AAC
      trgaudioformats.Selection = index

      ' set audio properties
      tf.AudioAvgBytesPerSecond = 24000
      tf.AudioBitsPerSample = 16
      tf.AudioNumChannels = 2
      tf.AudioSamplesPerSecond = 44100

      ' set video properties
      tf.VideoEncodeQuality = 85
      tf.VideoFrameHeight = 240
      tf.VideoFrameRate = 29.26
      tf.VideoFrameWidth = 320

      ' set the target output file and format
      _convertctrl.TargetFile = outFile

      ' subscribe to the progress event
      AddHandler _convertctrl.Progress, AddressOf ConvertCtrl_Progress

      ' convert it now!
           _convertctrl.StartConvert()

   Catch e1 As Exception
      _result = False
   End Try

   ' 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.
       Do While _convertctrl.State = ConvertState.Running
           Application.DoEvents()
       Loop

End Sub

Private Sub ConvertCtrl_Progress(ByVal sender As Object, ByVal e As ProgressEventArgs)
   ' set the result to true if complete
   If e.percent = 100 Then
      _result = True
   End If
End Sub

Public NotInheritable Class LEAD_VARS
Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 18\Media"
End Class
using Leadtools;
using Leadtools.MediaFoundation;
using LeadtoolsMediaFoundationExamples.Fixtures;

public bool _result = false;
public ConvertCtrlForm _form = new ConvertCtrlForm();
public ConvertCtrl _convertctrl;
public void VideoFormatsExample()
{
   // reference the convert control
   _convertctrl = _form.ConvertCtrl;

   // input and output files
   string inFile = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_Source.avi");
   string outFile = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_VideoFormatsExample.MP4");

   try
   {
      // set the source for conversion
      _convertctrl.SourceFile = inFile;

      // get the MP4 target format
      TargetFormat tf = _convertctrl.TargetFormats[TargetFormatType.MP4];

      // reset the MP4 target format
      tf.Reset();

      // select the MP4 target format
      tf.Selected = true;

      // select H264 video format
      int index = -1;
      TargetVideoFormats targetvideoformats = tf.VideoFormats;
      index = targetvideoformats.IndexOf("{34363248-0000-0010-8000-00AA00389B71}");// H264
      targetvideoformats.Selection = index;

      // select AAC audio format
      TargetAudioFormats targetaudioformats = tf.AudioFormats;
      index = targetaudioformats.IndexOf("{00001610-0000-0010-8000-00AA00389B71}");// AAC
      targetaudioformats.Selection = index;

      // set audio properties
      tf.AudioAvgBytesPerSecond   = 24000;
      tf.AudioBitsPerSample = 16;
      tf.AudioNumChannels = 2;
      tf.AudioSamplesPerSecond = 44100;

      // set video properties
      tf.VideoEncodeQuality = 85;
      tf.VideoFrameHeight = 240;
      tf.VideoFrameRate = 29.26;
      tf.VideoFrameWidth = 320;

      // set the target output file and format
      _convertctrl.TargetFile = outFile;

      // set our progress event handler
      _convertctrl.Progress += new ProgressEventHandler(ConvertCtrl_Progress);

      // convert it now!
      _convertctrl.StartConvert();
   }
   catch (Exception)
   {
      _result = false;
   }

   // 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.
   while (_convertctrl.State == ConvertState.Running)
      Application.DoEvents();
}

void ConvertCtrl_Progress(object sender, ProgressEventArgs e)
{
   // set the result to true if complete
   if (e.percent == 100)
      _result = true;
}

static class LEAD_VARS
{
public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 18\Media";
}
Requirements

Target Platforms

See Also

Reference

TargetFormat Class
TargetFormat Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.MediaFoundation requires a Multimedia or Multimedia Suite license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features