My Second Convert (Delphi 6.0)

The ltmmConvertCtrl object allows the user to recompress multimedia files or convert from one multimedia format to another. Using the following steps:

1.

Start with the project that you created in My First Convert.

2.

Add a Main Menu control to your form.

3.

Add two menu items to your main menu, and name them as follows:

 

Name

Caption

 

menuVideoCompressor

&Video Compressor

 

menuAudioCompressor

&Audio Compressor

4.

Add the following declarations to the private section of Form1.

Procedure BuildCompressorMenu ( ) ; 
Procedure menuVideoCompressorAllClick(Sender: TObject); 
Procedure menuAudioCompressorAllClick(Sender: TObject); 

5.

Update the FormCreate procedure to be as follows:

procedure TForm1.FormCreate(Sender: TObject); 
begin
 // Define the source file. 
 ltmmConvertCtrl1.SourceFile:= 'c:\source.avi'; 
   //Define the Target or output file. 
   ltmmConvertCtrl1.TargetFile:= 'c:\target.avi'; 
   // Enumerate the Video\Audio Compressors. 
 BuildCompressorMenu ( ); 
end; 

6.

Handle the menuVideoCompressor menu item OnClick event, and code menuVideoCompressorClick procedure as follows:

procedure TForm1.menuVideoCompressorClick(Sender: TObject); 
var
 i: Integer; 
 state: Boolean ; 
 index: Integer ;   
 compressors: IltmmCompressors ; 
begin

 state := ( ltmmConvertCtrl1.State <> ltmmCapture_State_Running ) ; 

 for i:= 0 to menuVideoCompressor.Count -1 do
   begin
  menuVideoCompressor.Items [ i ].Enabled := state ; 
   end; 

 compressors:= ltmmConvertCtrl1.VideoCompressors ; 
 index:= compressors.Selection ; 

 for i:= 0 to menuVideoCompressor.Count -1 do
   begin
   if ( menuVideoCompressor.Items [ i ].Tag = index ) then
   menuVideoCompressor.Items [ i ].Checked := True
      else
      menuVideoCompressor.Items [ i ].Checked := False ; 
   end; 
end;

7.

Handle the menuAudioCompressor menu item OnClick event, and code menuAudioCompressorClick procedure as follows:

procedure TForm1.menuAudioCompressorClick(Sender: TObject); 
var
 i: Integer; 
 state: Boolean ; 
 index: Integer ; 
 compressors: IltmmCompressors ; 
begin

 state := ( ltmmConvertCtrl1.State <> ltmmCapture_State_Running ) ; 

 for i:= 0 to menuAudioCompressor.Count -1 do
   begin
  menuAudioCompressor.Items [ i ].Enabled := state ; 
   end; 

 compressors:= ltmmConvertCtrl1.AudioCompressors ; 
 index:= compressors.Selection ; 

 for i:= 0 to menuAudioCompressor.Count -1 do
   begin
   if ( menuAudioCompressor.Items [ i ].Tag = index ) then
   menuAudioCompressor.Items [ i ].Checked := True
      else
      menuAudioCompressor.Items [ i ].Checked := False ; 
   end; 

end; 

8.

Add the body of BuildCompressorMenu, menuVideoCompressorAllClick, and menuAudioCompressorAllClick procedures to your Unit1 file.

Procedure TForm1.BuildCompressorMenu ( ) ; 
var
 count, i: Integer; 
   name: String; 
   tmpMenuItem: TMenuItem; 
 compressors: IltmmCompressors ; 
   compressor: IltmmCompressor ; 
begin
 // Remove the Old Video Compressors
 for i:= menuVideoCompressor.Count - 1 downto 0 do
   begin
   menuVideoCompressor.Remove ( menuVideoCompressor.Items[i] ); 
   end; 

 compressors:= ltmmConvertCtrl1.VideoCompressors; 
 count:= compressors.Count
 tmpMenuItem:= TMenuItem.Create ( Self ) ; 
 tmpMenuItem.Caption := 'No Recompression' ; 
 tmpMenuItem.Tag:= -1; 
   tmpMenuItem.OnClick := menuVideoCompressorAllClick ; 
 menuVideoCompressor.Add ( tmpMenuItem ) ; 

 if ( count > 0 ) then
 begin
  for i := 0 to count -1 do
  begin
   compressor:= compressors.Item (i); 
   name:= compressor.FriendlyName
   tmpMenuItem:= TMenuItem.Create ( Self ) ; 
   tmpMenuItem.Caption := name ; 
   tmpMenuItem.Tag:= i ; 
     tmpMenuItem.OnClick := menuVideoCompressorAllClick ; 
   menuVideoCompressor.Add ( tmpMenuItem ) ; 
  end; 
 end; 

  // Remove the Old Audio Compressors
 for i:= menuAudioCompressor.Count - 1 downto 0 do
   begin
   menuAudioCompressor.Remove ( menuAudioCompressor.Items[i] ); 
   end; 

 compressors:= ltmmConvertCtrl1.AudioCompressors
 count:= compressors.Count
 tmpMenuItem:= TMenuItem.Create ( Self ) ; 
 tmpMenuItem.Caption := 'No Recompression' ; 
   tmpMenuItem.Tag := -1 ; 
   tmpMenuItem.OnClick := menuAudioCompressorAllClick ; 
 menuAudioCompressor.Add ( tmpMenuItem ) ; 

 if ( count > 0 ) then
 begin
  for i := 0 to count - 1 do
  begin
   compressor:= compressors.Item (i); 
   name:= compressor.FriendlyName
   tmpMenuItem:= TMenuItem.Create ( Self ) ; 
   tmpMenuItem.Caption := name ; 
     tmpMenuItem.Tag := i ; 
     tmpMenuItem.OnClick := menuAudioCompressorAllClick ; 
   menuAudioCompressor.Add ( tmpMenuItem ) ; 
  end; 
 end; 
end; 

Procedure TForm1.menuVideoCompressorAllClick(Sender: TObject); 
var
 compressors: IltmmCompressors ; 
begin
 Cursor:= crHourGlass ; 
 compressors:= ltmmConvertCtrl1.VideoCompressors ; 
 compressors.Selection := TMenuItem(Sender).Tag ; 
 Cursor:= crDefault ; 
end; 

Procedure TForm1.menuAudioCompressorAllClick(Sender: TObject); 
var
 compressors: IltmmCompressors ; 
begin
 Cursor:= crHourGlass ; 
 compressors:= ltmmConvertCtrl1.AudioCompressors ; 
 compressors.Selection := TMenuItem(Sender).Tag ; 
 Cursor:= crDefault ; 
end; 

9.

Handle the ltmmConvertCtrl1 OnComplete event, and code the ltmmConvertCtrl1Complete procedure as follows:

procedure TForm1.ltmmConvertCtrl1Complete(Sender: TObject); 
begin
 //indicate that the conversion has completed
 Caption:= 'Conversion completed.'; 
end; 

10.

Handle the ltmmConvertCtrl1 OnErrorAbort event, and code the ltmmConvertCtrl1ErrorAbort procedure as follows:

procedure TForm1.ltmmConvertCtrl1ErrorAbort(Sender: TObject; 
  ErrorCode: Integer); 
begin
 //indicate that a conversion error has occurred
 Caption:= 'Error ' + IntToStr(ErrorCode) + '. Conversion aborted.'; 
end;

11.

Handle the ltmmConvertCtrl1 OnProgress event, and code the ltmmConvertCtrl1Progress procedure as follows:

procedure TForm1.ltmmConvertCtrl1Progress(Sender: TObject; 
  Percent: Integer); 
begin
 //update the percentage text
   Caption:= IntToStr(Percent) + '%'; 
end; 

12.

Handle the ltmmConvertCtrl1 OnStarted event, and code the ltmmConvertCtrl1Started procedure as follows:

procedure TForm1.ltmmConvertCtrl1Started(Sender: TObject); 
begin
 Caption:= 'Started'; 
end;

13.

Run your program to test it.