Convert DVD With Subtitles Example For Visual Basic
Private Const LEAD_MPEG2_ENCODER = "@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\LEAD MPEG2 Encoder (3.0)"
Private Const LEAD_MPEG_AUDIO_ENCODER = "@device:sw:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\LEAD MPEG Audio Encoder (2.0)"
' convert one chapter with subtitles (close captioning)
Private Sub Command1_Click()
Dim pCompressors As IltmmCompressors
ltmmConvertCtrl1.UseDVDSource = True
ltmmConvertCtrl1.SourceFile = "e:\video_ts\video_ts.ifo"
ltmmConvertCtrl1.TargetFormat = ltmmConvert_TargetFormat_MPEG2_PROGRAM
' select mpeg2 encoder
Set pCompressors = ltmmConvertCtrl1.VideoCompressors
pCompressors.Selection = pCompressors.Find(LEAD_MPEG2_ENCODER)
' select mpeg audio encoder
Set pCompressors = ltmmConvertCtrl1.AudioCompressors
pCompressors.Selection = pCompressors.Find(LEAD_MPEG_AUDIO_ENCODER)
ltmmConvertCtrl1.TargetFile = "c:\i\1.mpg"
SelectOneChapterAndSubtitles ltmmConvertCtrl1
ltmmConvertCtrl1.StartConvert
' wait for conversion to finish...
End Sub
' This function will select one chapter in a certain title
Private Sub SelectChapter(ByVal pTitle As IltmmDVDTitle, nChapterIndex As Integer)
Dim nCount As Long
Dim i As Long
nCount = pTitle.ChapterCount
For i = 0 To nCount - 1
Dim pChapter As IltmmDVDChapter
On Error GoTo NextChapter
Set pChapter = pTitle.GetChapter(i)
pChapter.Selected = (i = nChapterIndex)
NextChapter:
Next i
End Sub
' This function will select the main title for conversion.
' Within the main title, it will select only the second chapter.
' It will also select the first subtitle stream.
Private Sub SelectOneChapterAndSubtitles(ByVal pConvert As IltmmConvertCtrl)
Dim pDVDSource As IltmmDVDSource
Dim pTitle As IltmmDVDTitle
Dim lCount As Long
Dim lVal As Long
Dim i As Long
' Get the DVD source interface
Set pDVDSource = pConvert.GetSubObject(ltmmConvert_Object_SourceFilter)
' Select the main title
pDVDSource.Selected = ltmmDVDSource_Main_Selected
' We now need to select one chapter and enable subtitles for this title
' For that, we will loop through the titles and find out which one was selected above
' Get the title count in the disc
lCount = pDVDSource.TitleCount
For i = 0 To lCount - 1
' Get the title interface
Set pTitle = pDVDSource.GetTitle(i)
If Not pTitle Is Nothing Then
Dim bSelected As Long
bSelected = pTitle.Selected
If bSelected Then
' we found the main title
' (Optional step). We will convert only one chapter to speed up the conversion.
' We will select the 2nd chapte, because the first chapter will sometimes have movie credits and little dialogue
' Chapters are 0-based, so the second chapter has index 1
SelectChapter pTitle, 1
' Get the subpicture stream count
lVal = pTitle.SubpictureStreamCount
' Select the first subpicture stream
If lVal > 0 Then pTitle.SelectedSubpictureStream = 0
End If
End If
Next
End Sub
Private Sub ltmmConvertCtrl1_Complete()
Label1.Caption = "Conversion complete!"
End Sub
Private Sub ltmmConvertCtrl1_Progress(ByVal Percent As Long)
Label1.Caption = "Converting... " + CStr(Percent) + " complete..."
End Sub