Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Automated DVD authoring of Mpeg2Schnitt files with IfoEdit


  • Please log in to reply
3 replies to this topic
Cerdan
  • Members
  • 11 posts
  • Last active: May 03 2006 09:03 PM
  • Joined: 04 Oct 2005
Hi,

for all people out there who record DVB streams, pass them through Project X or PVAStrumento, cut them with Mpeg2Schnitt and finally want to author a dvd with IfoEdit out of it, this script might help to save some time.

Attention: you must replace "Öffnen" with "Open" or however the file dialog window is called on your machine if it opens!

SetTitleMatchMode, 2

video_input_folder =
video_output_folder =
ifo_edit_path =
extension := ".m2v"

; *******************************************************
; Check if the video.ini file exists
; *******************************************************
IfNotExist, %A_ScriptDir%\video.ini
{
  ; get video input folder
  FileSelectFolder, video_input_folder,,1, Please select the input folder with your video files
  
  if video_input_folder =
  {
    ExitApp
  }
  else
  {
    FileAppend, video_input_folder = %video_input_folder%`n, %A_ScriptDir%\video.ini
  }
  
  ; get video output folder
  FileSelectFolder, video_output_folder,,1, Please select an output folder
  
  if video_output_folder =
  {
    FileDelete, %A_ScriptDir%\video.ini
    ExitApp
  }
  else
  {
    FileAppend, video_output_folder = %video_output_folder%`n, %A_ScriptDir%\video.ini
  }
  
  ; get path to IfoEdit.exe file
  FileSelectFile, ifo_edit_path,,,Select your IfoEdit.exe file,Executables(*.exe)
  
  if ifo_edit_path =
  {
    FileDelete, %A_ScriptDir%\video.ini
    ExitApp
  }
  else
  {
    FileAppend, ifo_edit_path = %ifo_edit_path%`n, %A_ScriptDir%\video.ini
  }
}
Else
{
  ; *******************************************************
  ; Read variables out of the video.ini file
  ; *******************************************************
  Loop, read, %A_ScriptDir%\video.ini
  {
    IfInString, A_LoopReadLine, =
    {
      StringGetPos, position, A_LoopReadLine, =
      
      position := position
      StringLeft, attribute, A_LoopReadLine, %position%
      
      position := position + 1
      StringTrimLeft, value, A_LoopReadLine, %position%
      
      ; Trim operation
      attribute = %attribute%
      value = %value%
      
      if attribute = video_input_folder
      {
        video_input_folder = %value%
      }
      else if attribute = video_output_folder
      {
        video_output_folder = %value%
      }
      else if attribute = ifo_edit_path
      {
        ifo_edit_path = %value%
      }
    }
  }
}

Loop
{
  retval := StartIfoEdit(video_input_folder, video_output_folder, ifo_edit_path, extension)
  if retval =
  {
    break
  }
}

MsgBox, Finished processing files!


; *******************************************************
; Function StartIfoEdit
; Starts IfoEdit and sets the necessary stuff for file conversion. 
; *******************************************************
StartIfoEdit(video_input_folder, video_output_folder, ifo_edit_path, extension)
{

  ; Get the oldest file out of the input folder
  oldestFile := GetOldestFile(video_input_folder, extension)

  if oldestFile <>
  {
    
    ; Get the output folder name
    folderName := RemoveExtension(oldestFile, extension)

    ; Check if the output folder already exists. If not, create it
    IfNotExist, %video_output_folder%\%folderName%
    {
      FileCreateDir, %video_output_folder%\%folderName%
    }

    ; Start IfoEdit
    Run, %ifo_edit_path%
    
    Sleep, 500

    WinActivate, IfoEdit
    WinWaitActive, IfoEdit
    
    Sleep, 300

    Loop
    {
      WinMenuSelectItem, IfoEdit, , DVD Author, Author new DVD
      WinWaitActive, DVD Author / Multiplex,,2
      if ErrorLevel = 0
      {
        break
      }
    }

    ; Set output directory
    video_output_path = %video_output_folder%\%folderName%
    ControlSetText, Edit1, %video_output_path%, DVD Author / Multiplex

    ; Set video input file
    video_input_file = %video_input_folder%\%oldestFile%
    SetFileOrPathInDialog(video_input_file, "Button4", "DVD Author / Multiplex")

    ; set audio files
    SetAudioFiles(video_input_folder, folderName)

    ; start conversion
    WinActivate, DVD Author / Multiplex
    ControlFocus, Button1, DVD Author / Multiplex
    Sleep, 300
    ControlClick, Button1, DVD Author / Multiplex

    WinWait, Changing VOB navigation packs
    WinWaitClose, Changing VOB navigation packs
        
    WinActivate, Log Window
    WinClose, Log Window
    
    WinActivate, IfoEdit
    WinWaitActive, IfoEdit
    
    ; Click the Quit button
    ControlFocus, Button1, IfoEdit
    Sleep, 300
    ControlClick, Button1, IfoEdit
    Sleep, 500
    
    FileMove, %video_input_file%, %video_input_file%.converted
  }
  
  return %oldestFile%
}


; *******************************************************
; Function GetOldestFile(filePath)
; Retrieve the oldest file within a given path.
; If an extension is given, only files with the given file
; extension will be considered.
; *******************************************************
GetOldestFile(filePath, extension)
{
  oldestFile =
  oldestTime = %A_Now%
  FileList =
  
  ; *******************************************************
  ; Loop, FilePattern [, IncludeFolders?, Recurse?]
  ;
  ; IncludeFolders?
  ; One of the following digits, or blank to use the default:
  ;   0 (default) Folders are not retrieved (only files).
  ;   1 All files and folders that match the wildcard pattern are retrieved.
  ;   2 Only folders are retrieved (no files).
  ;
  ; Recurse? 	One of the following digits, or blank to use the default:
  ;   0 (default) Subfolders are not recursed into.
  ;   1 Subfolders are recursed into so that files and folders contained therein are retrieved if
  ;     they match FilePattern. All subfolders will be recursed into, not just those whose names
  ;     match FilePattern.
  ; *******************************************************
  Loop, %filePath%\*.*, 0
  {
    FileList = %FileList%%A_LoopFileTimeModified%`t%A_LoopFileName%`n
  }
  Sort, FileList  ; Sort by date.
  
  Loop, parse, FileList, `n
  {
  	if A_LoopField =  ; Omit the last linefeed (blank item) at the end of the list.
  	 continue
  	StringSplit, FileItem, A_LoopField, %A_Tab%  ; Split into two parts at the tab char.
  	
  	difference := oldestTime - FileItem1
  	
  	if difference > 0
  	{
  	 
     index := InStr(FileItem2, extension, False, 1)
     
     ; check if any file extension has to be checked, too
  	 StringTrimLeft, fileExt, FileItem2, InStr(FileItem2, extension, False, 1)
  	 fileExt = .%fileExt%

  	 if (extension = "") or (extension = fileExt)
  	 {
     	 oldestTime := FileItem1
    	 oldestFile := FileItem2
     }
    }
  }
  
  return oldestFile
}


; *******************************************************
; Function RemoveExtension
; removes the file extension from a given file name
; *******************************************************
RemoveExtension(fileName, extension)
{
  index := InStr(fileName, extension)
  
  if index > 0
  {
    StringLeft, folderName , fileName, index - 1
  }
  
  return folderName
}


; *******************************************************
; Function SetFileOrPathInDialog
; sets a file or path within an open dialog
; *******************************************************
SetFileOrPathInDialog(fileName, dialogButton, dialogWindowName)
{
  ; open dialog
  WinWaitActive, %dialogWindowName%
  Sleep, 300
    
  ControlFocus, %dialogButton%, %dialogWindowName%
  Sleep, 1000
  ControlClick, %dialogButton%, %dialogWindowName%
  
  Sleep, 200
  WinWaitActive, Öffnen
  
  ControlFocus, Edit1, Öffnen
  ControlSetText, Edit1, %fileName%, Öffnen

  ControlFocus, Button2, Öffnen
  ControlClick, Button2, Öffnen
}


; *******************************************************
; Function SetAudioFiles
; sets all possible audio files for the conversion
; *******************************************************
SetAudioFiles(video_input_folder, folderName)
{

  extensions = mp2,ac3,m2a,mpa,dts,wav
  
  Loop, parse, extensions, `,
  {
    audio = %video_input_folder%\%folderName%.%A_LoopField%
    
    IfExist, %audio%
    {
      ; open dialog
      SetFileOrPathInDialog(audio, "Button7", "DVD Author / Multiplex")
    }
  }  
}


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Interesting. Thanks.

Cerdan
  • Members
  • 11 posts
  • Last active: May 03 2006 09:03 PM
  • Joined: 04 Oct 2005
I wonder if anyone already tried to use my script and could tell me how it works for him.

Greetings,

Cerdan

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
I haven't tried it. Sorry. I found the process interesting but I'm currently not doing any recording of DVB streams. I may be able to put something together to test with a bit later though :) .