Sign in to follow this  
Followers 0
iamtheky

Easy Video Trimmer

1 post in this topic

This ffmpeg snippet has proven useful more than once, so figured I would share.

$file = FileOpenDialog("Select Video" , @ScriptDir , "ALL(*.*)")

$start = inputbox( "Start Time" , "Enter Capture Start Time in Seconds - 0 is the beginning")
$length = inputbox ("Length of Capture" , "Enter the desired duration (in seconds) of the output video")

run("ffmpeg -sameq -ss " & $start & " -t " & $length & " -i " & $file & " " & stringtrimright($file , 4) & "_output.mp4")

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • dynamitemedia
      By dynamitemedia
      i love using ffplay but would like to skin it to look like rest of my gui's

      is it possible to do this?  like a parent and Child  possibly?
    • cyanidemonkey
      By cyanidemonkey
      This is a small app I wrote awhile back to batch FFMPEG commands of videos. I have a camcorder that saves to a file type .mts and I wanted to convert them to .mp4 but was too lazy to write out the commands one at a time in the CMD window.
       

      NOTES:
      You will need to download ffmpeg, as it is the application doing the actual conversions (http://ffmpeg.org/). It can only do one directory at a time, it will not do recursive directories. The defaults are set up to convert .mts files to .mp4, if you want to change the input, output and command line options you can, however, you may need to read the documentation at the ffmpeg website. If you want to change the input file type, do this before opening the input browse button. The software will steal focus to communicate with the command line interface, It is best to set up a conversion job and leave the computer alone until it is done (hence the option to shutdown after converting files). If you try to use the computer while it is running chances are it will fail to convert one or more videos. Video processing can be PCU intensive, this application was designed to be set and forget. If you don't want to scale down to 720p remove " -s 1280x720 " from command line, remove " -r 30 " if you don't want the frame rate set to 30fps, if you do not require deinterlacing remove " - vf yadif=1 " from the command line options. You can choose to delete the original video files after they are converted to save disc space, but it pays to test one file first to make sure they convert correctly before batch deleting the original files (they are sent to the recycle bin, so you can restore them until you empty the recycle bin).  
      AutoIt Code:
      ; Build by Marc Rosewarne 2012 ; Works with ffmpeg to automate commandline inputs and converts all files in a selected folder. ;--------------------------------- REQUIRED INCLUDES & GLOBAL VARS -------------------------------------; Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiConstants.au3> #include <GuiListView.au3> #include <Array.au3> ;----------------------------------------------- MAIN GUI ---------------------------------------------------; $mainWin = GuiCreate("ffmpeg batch convertion automator", 650, 400) ;VID FILES LOCATION GuiCtrlCreateGroup("Input Video File Type and Location", 15, 15, 620, 180) $vidFileType = GuiCtrlCreateInput(".mts", 25, 35, 30, 20) $vidSourceDir = GuiCtrlCreateInput("Set Input File(s) Location", 60, 35, 500, 20) $vidSetSourceDir = GuiCtrlCreateButton("Browse", 565, 34, 60, 22) $vidSourceList = GuiCtrlCreateEdit("Video Files: ", 25, 65, 600, 105) $vidSourceNum = GUICtrlCreateLabel("Files Found: 0", 25, 173, 110, 15) $vidFilesConverted = GUICtrlCreateLabel("Files Converted: 0", 260, 173, 110, 15) $vidFilesDeleted = GUICtrlCreateLabel("Files Deleted: 0", 500, 173, 110, 15) GUICtrlCreateGroup ("",-99,-99,1,1) ;close group ; CONVERTION OPTIONS GuiCtrlCreateGroup(" ffmpeg.exe Location and Commands ", 15, 200, 620, 100) $ffmpegExeLocation = GuiCtrlCreateInput("Set ffmpeg.exe Location", 25, 218, 535, 20) $ffmpegBrowseBtn = GuiCtrlCreateButton("Browse", 565, 217, 60, 22) GUICtrlCreateLabel("Set ffmpeg commandline: ", 25, 250, 160, 15) GUICtrlCreateLabel(" ffmpeg -i [input] ", 25, 270, 80, 15) $ffmpegCommand = GuiCtrlCreateInput("-vf yadif=1 -s 1280x720 -r 30 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k", 105, 268, 450, 20) GUICtrlCreateLabel("[output].", 560, 270, 40, 15) $convertedFileType = GuiCtrlCreateInput("mp4", 600, 268, 30, 20) GUICtrlCreateGroup ("",-99,-99,1,1) ;close group ; EXTRA OPTIONS GuiCtrlCreateGroup(" Post Convertion Options ", 15, 310, 620, 40) $deleteInput = GUICtrlCreateCheckbox( "Delete original video files", 25, 325) GUICtrlCreateLabel("Computer:", 360, 327, 80, 15) $o1 = GuiCtrlCreateRadio("Reboot", 420, 323, 50) $o2 = GuiCtrlCreateRadio("Shutdown", 485, 323, 65) $o3 = GuiCtrlCreateRadio("Nothing", 560, 323, 60) GuiCtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateGroup ("",-99,-99,1,1) ;close group ; GO! BUTTON $startVidExport = GUICtrlCreateButton(">>> Convert Video Files >>>", 15, 363, 620, 22) GUICtrlSetState(-1, $GUI_DISABLE) $proggy = GuiCtrlCreateProgress(15, 363, 620, 22) GUICtrlSetState($proggy, $GUI_HIDE) GUISetState(@SW_SHOW) ;---------------------------------------------- FUNCTIONS -------------------------------------------------------; Func vidSourceDir() ;---SET SOURCE FILE LOCATION $message = "Select folder/drive location to find " & StringUpper(StringTrimLeft(GUICtrlRead($vidFileType), 1)) & " files." $var = FileSelectFolder($message, "") If @error Then MsgBox(4096,"","No Folder Selected!") Return Else GUICtrlSetData($vidSourceDir, $var) GUICtrlSetData($vidSourceList, GUICtrlRead($vidSourceList) & @CRLF & " > Analysing directory structure - please wait...") EndIf ;---ERROR CHK REQUIRED FIELDS B4 MOVING ON If GUICtrlRead($vidSourceDir) = "" OR GUICtrlRead($vidSourceDir) = "Set Input File(s) Location" Then MsgBox(64, "User Error", "No Source Location Set." & @LF & "Requested action will now terminate.") Return Else If NOT FileExists(GUICtrlRead($vidSourceDir)) Then MsgBox(64, "User Error", "The Source Location Does Not Exsist." & @LF & "Requested action will now terminate.") Return EndIf EndIf ;---SEARCH FOR FILES IN SELECTED DIRECTORY $fileTotal = DirGetSize( $var,1) Global $fileCount = 0 Global $vidSourceFiles[$fileTotal[1]][2] $search = FileFindFirstFile(GUICtrlRead($vidSourceDir) & "\*" & GUICtrlRead($vidFileType)) $var = GUICtrlRead($vidSourceDir) GUICtrlSetData($vidSourceList , StringUpper(StringTrimLeft(GUICtrlRead($vidFileType), 1)) & " Files: ") findvidFiles($search, $var) If $fileCount <> 0 Then ReDim $vidSourceFiles[$fileCount][2] EndIf FileClose($search) If $fileCount <> 0 Then GUICtrlSetState($startVidExport, $GUI_ENABLE) EndIf EndFunc Func ffmpegExeLoc() ;---SET FFMPEG.exe LOCATION $message2 = "Select ffmpeg.exe location." $var2 = FileOpenDialog($message2, @ProgramFilesDir & "\", "(ffmpeg.exe)") If @error Then MsgBox(4096,"","No Folder Selected!") Return Else GUICtrlSetData($ffmpegExeLocation, $var2) EndIf ;---ERROR CHK REQUIRED FIELDS B4 MOVING ON If GUICtrlRead($ffmpegExeLocation) = "" OR GUICtrlRead($ffmpegExeLocation) = "Set ffmpeg.exe Location" Then MsgBox(64, "User Error", "No FFMPEG.exe Set." & @LF & "Requested action will now terminate.") Return Else If NOT FileExists(GUICtrlRead($ffmpegExeLocation)) Then MsgBox(64, "User Error", "The FFMPEG.exe Location Does Not Exsist." & @LF & "Requested action will now terminate.") Return EndIf EndIf EndFunc Func findvidFiles($search, $var) ;---FIND FILES & ADD TO ARRAY CALLED BY vidSourceDir() While (True) $file = FileFindNextFile($search) If @error Then ExitLoop EndIf $vidSourceFiles[$fileCount][0] = $file $vidSourceFiles[$fileCount][1] = $var GUICtrlSetData($vidSourceNum , "Files Found: " & $fileCount+1) GUICtrlSetData($vidSourceList , GUICtrlRead($vidSourceList) & @CRLF & " > Video File Found: " & $var & "\" & $file) $fileCount += 1 WEnd EndFunc Func batchFFMPEGConverts() ;---ERROR CHK REQUIRED FIELDS B4 MOVING ON If GUICtrlRead($ffmpegExeLocation) = "" OR GUICtrlRead($ffmpegExeLocation) = "Set ffmpeg.exe Location" Then MsgBox(64, "User Error", "No FFMPEG.exe Set." & @LF & "Requested action will now terminate.") Return Else If NOT FileExists(GUICtrlRead($ffmpegExeLocation)) Then MsgBox(64, "User Error", "The FFMPEG.exe Location Does Not Exsist." & @LF & "Requested action will now terminate.") Return EndIf EndIf GUICtrlSetState($startVidExport, $GUI_DISABLE) GUICtrlSetState($startVidExport, $GUI_HIDE) GUICtrlSetState($proggy, $GUI_SHOW) Global $xmlFile Global $count = 100/$fileCount If NOT WinExists("C:\Windows\system32\cmd.exe") Then Run("C:\Windows\system32\cmd.exe", "", @SW_MAXIMIZE) EndIf WinActivate("C:\Windows\system32\cmd.exe") WinWaitActive("C:\Windows\system32\cmd.exe") ;create _converted directory DirCreate(GUICtrlRead($vidSourceDir) & "\_converted") ;---LOOP THROUGH VIDEO FILES AND SEND FFMPEG COMMAND TO CONVERT IT. FOR $i = 0 to UBound($vidSourceFiles)-1 $file = $vidSourceFiles[$i][0] $source = $vidSourceFiles[$i][1] $xmlFile = $source & "\" & $file ;write out ffmpeg commandline here WinActivate("C:\Windows\system32\cmd.exe") WinWaitActive("C:\Windows\system32\cmd.exe") Send(GUICtrlRead($ffmpegExeLocation) & " -i """ & $xmlFile & """ " & GUICtrlRead($ffmpegCommand) & " """ & $source & "\_converted\" & StringTrimRight($file, 3) & GUICtrlRead($convertedFileType) & """{ENTER}") ;update progress bar If $count*($i+1) = 100 Then GUICtrlSetData($proggy, 99) Else GUICtrlSetData($proggy, ($count*($i+1))) EndIf WinWait("C:\Windows\system32\cmd.exe") ;change converted number. GUICtrlSetData($vidFilesConverted, "Files Converted: " & $i+1) NEXT GUICtrlSetData($proggy, 100) WinClose("C:\Windows\system32\cmd.exe") ;delete original video files If GUICtrlRead($deleteInput) = 1 Then $msg = MsgBox(65, "Delete Original Video Files", "'Delete original video files after convertion' has been selected. This will happen in 10 seconds. Click 'Cancel' to cancel file deletion. (Files will be moved to recycle bin, they can be restored from there untill you empty the recycle bin.)", 10) If $msg <> 2 Then FOR $i = 0 to UBound($vidSourceFiles)-1 $vidFile = $vidSourceFiles[$i][1] & "\" & $vidSourceFiles[$i][0] ; if file exsist, delete it If FileExists($vidFile) Then FileRecycle($vidFile) EndIf ;change deleted number. GUICtrlSetData($vidFilesDeleted, "Files Deleted: " & $i+1) GUICtrlSetData($proggy, (100-$count*($i+1))) NEXT EndIf EndIf ;shutdown/reboot If GUICtrlRead($o1) = 1 Then $msg = MsgBox(65, "Automated Reboot", "Computer will reboot in 10 seconds. Click 'Cancel' to cancel reboot.", 10) If $msg <> 2 Then Shutdown(6) Exit EndIf EndIf If GUICtrlRead($o2) = 1 Then $msg = MsgBox(65, "Automated Shutdown", "Computer will shutdown in 10 seconds. Click 'Cancel' to cancel shutdown.", 10) If $msg <> 2 Then Shutdown(5) Exit EndIf EndIf GUICtrlSetState($proggy, $GUI_HIDE) GUICtrlSetData($proggy, 0) GUICtrlSetState($startVidExport, $GUI_SHOW) GUICtrlSetState($startVidExport, $GUI_ENABLE) EndFunc ;------------------------------------------------ LOOP -------------------------------------------------------; While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $vidSetSourceDir vidSourceDir() Case $msg[0] = $startVidExport batchFFMPEGConverts() Case $msg[0] = $ffmpegBrowseBtn ffmpegExeLoc() Case $msg[0] = $GUI_EVENT_CLOSE Exit EndSelect WEnd Hopefully someone may find it usefull? Enjoy.
    • iamtheky
      By iamtheky
      many sites will not permit the uploading of a video container that only contains an audio stream. And one in particular has all of their customizable music players broken. This simple script loops a single jpg as the video stream over the audio of your choosing and outputs an .avi.

      *requires ffmpeg


      $pic = "picture.jpg" $song = "song.mp3" $result = "result.avi" runwait ("ffmpeg -loop_input -f image2 -i " & $pic & " -r 1 -vcodec flv -i " & $song & " -acodec copy -qscale 2 -g 5 -cmp 3 -subcmp 3 -mbd 2 " & $result & " -shortest", @ScriptDir)
    • steipal
      By steipal
      Hi guys!

      I'm a new member of this forum and I've been a AutoIt-"programmer" for 3 years now. I've desided to share one of my projects with you. It's called "FFAStrans" and it's a FlipFactory/EpisodeEngine inspired automated transcoding system based on FFmpeg and AviSynth. Now, this is not your average ffmpeg frontend, nor you general utility for converting 3 hour movies. It's off course possible but it's more aimed at production facilities, maybe run on a server, or where ever there is a need for automatically convert incoming mediafiles with decent control and feedback if something goes wrong. You can dynamically build several projects with different settings for monitoring and treating all kinds of mediafiles.

      The documentation for this project is none but if you like to take a look please visit the project page at code.google.com/p/ffastrans

      It's created with a bunch of help from this forum so thank you guys!


      PS: It's very beta but it kinda works as it's actually been used in production facilities.
      PS2: It's lots of code and it may seem ugly....which it is! Hey, I'm really not a great programmer but I usually get the functionality I want....;-)
      PS3: For various legal reasons the software dependencies is NOT included in the archives, but there are links to where to find them.


      -steipal