MP4 cutting without re-enconding

My wish was to cut MP4 files without re-enconding them. So that should be fast and lossless.

For this part I found a nice software that does it for me: Smart Cutter

But one problem of this software is the usability. So i downloaded a trial version of Adobe Premiere Pro CC and tried following. I cutted my video with Premiere and exported an EDL file that contains all cut-points of this video.

Smart Cutter doesn’t support the exported format of Premiere Pro, so it is necessary to adapt the data in the EDL file. To do this automatically I wrote an AutoIT script that you can find here:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <File.au3>

; ======================================================
; This script converts the EDL file that was exported by Adobe Premiere Pro
; to a EDL file that can be read by Smart Cutter
; 											by PS
; ======================================================

; Check the commandline
If $CmdLine[0] = "" Then
   MsgBox($MB_SYSTEMMODAL, "Missing file", "No file given. Please start with a file as argument.")
   Exit
EndIf

; read the given file, convert them and write the result file
Func convert()
   Local $sDrive, $sDir, $sFileName, $sExtension
   _PathSplit ( $CmdLine[1], $sDrive, $sDir, $sFileName, $sExtension )

   ToolTip("Converting file: " & $sFileName & $sExtension)

   ; Open the file for reading and store the handle to a variable.
   Local $hFileOpen = FileOpen($CmdLine[1], $FO_READ)
   If $hFileOpen = -1 Then
	  MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
	  Return False
   EndIf

   ; Read the contents of the file using the handle returned by FileOpen.
   Local $sFileRead = FileRead($hFileOpen)

   ; Close the handle returned by FileOpen.
   FileClose($hFileOpen)

   ; Remove all unnecessary strings from the file
   $sFileRead = StringRegExpReplace($sFileRead, "TITLE: .*\r\n", "")
   $sFileRead = StringRegExpReplace($sFileRead, "\* FROM CLIP NAME:.*(\r\n)?", "")
   $sFileRead = StringRegExpReplace($sFileRead, "\d{3}\W*AX\W* AA/V\W*C\W*", "")
   $sFileRead = StringRegExpReplace($sFileRead, "\r\n\r\n", @CRLF)


   ; prepare timestamps
   $timestampsstr = "00:00:00:00 "
   $timestamps = StringSplit($sFileRead, @CRLF, $STR_ENTIRESPLIT)
   For $i = 1 to $timestamps[0]
	  $timestampParts = StringSplit($timestamps[$i], " ")
	  If @error = 1 Then ContinueLoop
	  $timestampsstr = $timestampsstr & $timestampParts[1] & @CRLF & $timestampParts[2] & " "
   Next
   $timestampsstr = $timestampsstr & "999999:99:99:99"

   ; parse the timestamps
   $result = ""
   $timestamps = StringSplit($timestampsstr, @CRLF, $STR_ENTIRESPLIT)
   For $i = 1 to $timestamps[0]
	  $timestampParts = StringSplit($timestamps[$i], " ")
	  If @error = 1 Then ContinueLoop

	  ;MsgBox($MB_SYSTEMMODAL, "Missing file", "jo: " & $timestamps[$i])
	  $part1 = timestampToSecondsString($timestampParts[1])
	  $part2 = timestampToSecondsString($timestampParts[2])
	  If $part1 = $part2 Then ContinueLoop

	  $timestampFormated = $part1 & " " & $part2 & " 0"
	  $result = $result & $timestampFormated & @CR & @LF
   Next

   ; Write new file
   Local $hFileOpen = FileOpen(_PathMake($sDrive, $sDir, $sFileName & "_SmartCutter", $sExtension), $FO_OVERWRITE)
   FileWrite($hFileOpen, $result)
   FileClose($hFileOpen)
   Sleep(1000)
EndFunc

; Timestamp format have to be: 00:02:35:35
Func timestampToSecondsString($timestamp)
   $times = StringSplit($timestamp, ":")
   If $times[0] <> 4 Then
	  MsgBox($MB_SYSTEMMODAL, "", "Wrong timestamp:" & $timestamp)
	  Return ""
   EndIf
   $hours 	 = Number($times[1])
   $minutes  = Number($times[2])
   $seconds  = Number($times[3])
   $mseconds = Number($times[4])

   Return $hours * 3600 + $minutes * 60 + $seconds & "." & $mseconds
EndFunc

convert()

Put this script in a AU3 file and compile this to a EXE file.

Now you can drop your Premiere Pro EDL files to this EXE file and you will get new EDL files that are supported by Smart Cutter.