Import der DLL C:\Programme\Windows Media-Komponenten\Encoder\WME5ncEng.dll über Delphi oder besser EventSinkImp
www.techvanguards.co...roducts/eventsinkimp
Die nun zur Verfügunkstehende WMEncoderLib_TLB in einem neuen Projekt in der Uses Einbinden schon kann’s losgehen.
Das nun folgende Beispiel ist 1:1 aus der WME 9 SDK (Beispiele VB) von Microsoft übernommen worden und von mir in Delphi übersetzt.
Der Orginal VB Code ist als Kommentar ausgeklammert worden.
Eine Erweiterung sollte kein Problem darstellen. Zu beachten ist nur das der WME mit Threads arbeitet dies kann zu verwirrenden Ergebnissen
Führen wenn man's nicht weiss oder nicht beachtet.
Weiteres findet man in der WME9 SDK oder direkt bei MS.
procedure TForm1.btnStartClick(Sender: TObject); // Sub Main()
var Encoder : TWMEncoder ; // Dim Encoder As WMEncoder
SrcGrpColl : IWMEncSourceGroupCollection ; // Dim SrcGrpColl As IWMEncSourceGroupCollection
SrcGrp : IWMEncSourceGroup2 ; // Dim SrcGrp As IWMEncSourceGroup2
SrcVid : IWMEncVideoSource2 ; // Dim SrcVid As IWMEncVideoSource2
SrcAud : IWMEncAudioSource ; // Dim SrcAud As IWMEncAudioSource
ProColl : IWMEncProfileCollection ;// Dim ProColl As IWMEncProfileCollection
Pro : IWMEncProfile ; // Dim Pro As IWMEncProfile
i : Integer ; // Dim i As Integer
iLength : Integer ; // Dim lLength As Long
Descr : IWMEncDisplayInfo ; // Dim Descr As IWMEncDisplayInfo
Attr : IWMEncAttributes ; // Dim Attr As IWMEncAttributes
OutputFile : IWMEncFile ; // Dim File As IWMEncFile
begin
Encoder := TWMEncoder.Create(self) ; // Set Encoder = New WMEncoder, Create a WMEncoder object.
// Retrieve the source group collection and add a source group.
SrcGrpColl := Encoder.SourceGroupCollection ;// Set SrcGrpColl = Encoder.SourceGroupCollection
SrcGrp := IWMEncSourceGroup2(SrcGrpColl.Add('SG_1')) ; // Set SrcGrp = SrcGrpColl.Add("SG_1")
//Add a video and audio source to the source group.
SrcVid := IWMEncVideoSource2(SrcGrp.AddSource(WMENC_VIDEO)) ; // Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
SrcAud := IWMEncAudioSource(SrcGrp.AddSource(WMENC_AUDIO)) ; // Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
// Identify the source files to encode.
SrcVid.SetInput('C:\TMP\test.avi', '', '') ; // SrcVid.SetInput "C:\InputFile.mpg"
SrcAud.SetInput('C:\TMP\test.avi', '', '') ; // SrcAud.SetInput "C:\InputFile.mpg"
// Choose a profile from the collection.
ProColl := Encoder.ProfileCollection ; // Set ProColl = Encoder.ProfileCollection
iLength := ProColl.Count ; // lLength = ProColl.Count
for i := 0 to iLength -1 do // For i = 0 To lLength - 1
begin
Pro := ProColl.Item(i) ; // Set Pro = ProColl.Item(i)
if Pro.Name = txtProfileName.Text then // If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
begin
SrcGrp.Set_Profile(Pro) ; // SrcGrp.Profile = Pro
BREAK ; // Exit For
end ; // End If
end ; // Next
// Fill in the description object members.
Descr := Encoder.DisplayInfo ; // Set Descr = Encoder.DisplayInfo
Descr.Author := '' ; // Descr.Author = "Author name"
Descr.CopyRight := '' ; // Descr.Copyright = "Copyright information"
Descr.Description := '' ; // Descr.Description = "Text description of encoded content"
Descr.Rating := '' ; // Descr.Rating = "Rating information"
Descr.Title := '' ; // Descr.Title = "Title of encoded content"
// Add an attribute to the collection.
Attr := Encoder.Attributes ; // Set Attr = Encoder.Attributes
//Attr.Add('URL, 'IP adress') ; // Attr.Add "URL", "IP address"
// Specify a file object in which to save encoded content.
OutputFile := Encoder.File_ ; // Set File = Encoder.File
OutputFile.LocalFileName := 'C:\TMP\NewFile.wmv' ; // File.LocalFileName = "C:\OutputFile.wmv"
// Crop 2 pixels from each edge of the video image.
SrcVid.CroppingBottomMargin := 2 ; // SrcVid.CroppingBottomMargin = 2
SrcVid.CroppingTopMargin := 2 ; // SrcVid.CroppingTopMargin = 2
SrcVid.CroppingLeftMargin := 2 ; // SrcVid.CroppingLeftMargin = 2
SrcVid.CroppingRightMargin := 2 ; // SrcVid.CroppingRightMargin = 2
// Start the encoding process.
Encoder.PrepareToEncode(True) ;
Encoder.Start ; // Encoder.Start
// Wait until the encoding process stops before exiting the application.
// You can do this by using the WMEncoder object to create an event sink.
// For this example, simply monitor the size of the output file and
// use a message box to indicate when to close the application.
// showmessage('Fertig !')// MsgBox ("Click OK when encoding has stopped.")
end; // End Sub