Sign in to follow this  
Followers 0
Datenshi

Simple batch convert any video to avi(xvid) using ffmpeg

3 posts in this topic

#1 ·  Posted (edited)

I used this very simple script to batch convert a couple of folders i had with .flv and .mpg videos, I'm not gonna develop this further as it works fine already and its a simple task.

  • Fill in what extension to scan the folder for first, if you want to convert flash videos type, .flv
  • Select folder to scan.
  • [sit back and relax.
  • Make sure everything got converted.
  • Remove old files.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.2.0
 Author:         Emanuel "Datenshi" Lindgren

 Script Function:
    Batch convert .ext to avi using ffmpeg.

#ce ----------------------------------------------------------------------------

#Include <Array.au3>
$ffmpegpath = @ScriptDir & "\ffmpeg.exe"
$tempdirpath = @ScriptDir&"\temp"
Dim $ScanFilePaths[1] = [""]
DirCreate($tempdirpath)
$filext = InputBox("FileExtention","Choose file extension",".flv"," M")
If $filext = "" Then Exit
$Selectedfolder = FileSelectFolder("Select Folder Scanned For .ext","")
If $Selectedfolder = "" Then Exit
_ScanFolder($Selectedfolder,$filext)
_ArrayDelete($ScanFilePaths,0)
If IsArray($ScanFilePaths) = 0 Then
MsgBox(0,"error","no "&$filext&" video found.")
Exit
Endif
ProgressOn("Initializing","","",1,1)
FileWriteLine($tempdirpath&"\ffinst.bat","chcp 1252")
$totalfiles = Ubound($ScanFilePaths)-1
For $x = 0 To $totalfiles
FileDelete($tempdirpath&"\ffinst.bat")
    $GetFilename = StringSplit($ScanFilePaths[$x],"\")
    $GetFilename = $GetFilename[Ubound($GetFilename)-1]
ProgressSet(Int((100/$totalfiles)*$x),StringReplace($ScanFilePaths[$x],$filext,".avi"),"Done/Total = "&$x&"/"&$totalfiles)
FileWriteLine($tempdirpath&"\ffinst.bat","title Converting "&$GetFilename&" ("&$x&"/"&$totalfiles&")")
FileWriteLine($tempdirpath&"\ffinst.bat",'"'&$ffmpegpath&'" -threads 2 -i "'&$ScanFilePaths[$x]&'" -f avi -r 29.97 -vcodec libxvid -vtag XVID  -aspect 4:3 -maxrate 1800kb -b 1500kb -qmin 3 -qmax 5 -bufsize 4096 -mbd 2 -bf 2 -flags +4mv -trellis -aic -cmp 2 -subcmp 2 -g 300 -acodec libmp3lame -ar 48000 -ab 128k -ac 2 -an -passlogfile "'&$GetFilename&'.log" -pass 1  -y "NUL.avi"')
FileWriteLine($tempdirpath&"\ffinst.bat",'"'&$ffmpegpath&'" -threads 2 -y -i "'&$ScanFilePaths[$x]&'" -f avi -r 29.97 -vcodec libxvid -vtag XVID  -aspect 4:3  -maxrate 1800kb -b 1500kb -qmin 3 -qmax 5 -bufsize 4096 -mbd 2 -bf 2 -flags +4mv -trellis -aic -cmp 2 -subcmp 2 -g 300 -acodec libmp3lame -ar 48000 -ab 128k -ac 2 -passlogfile "'&$GetFilename&'.log" -pass 2  "'&StringReplace($ScanFilePaths[$x],$filext,".avi")&'"')
RunWait($tempdirpath&"\ffinst.bat",$tempdirpath,@SW_HIDE)
Next
DirRemove($tempdirpath,1)


Func _ScanFolder($SourceFolder,$searchExt)
    Local $Search,$File,$FileAttributes,$FullFilePath

    $Search = FileFindFirstFile($SourceFolder & "\*.*")

    While 1
        If $Search = -1 then
        ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)
        If StringInStr($FileAttributes,"D") Then
            _ScanFolder($FullFilePath,$searchExt)
        ElseIf Stringinstr($FullFilePath,$searchExt) <> 0 Then
            $FileFolder = StringSplit($FullFilePath,"\")
            _ArrayAdd($ScanFilePaths,$FullFilePath)
        Endif
    WEnd
    FileClose($Search)
EndFunc

You might want to customize the ffmpeg parameters in case you want to change the output quality, its pretty high by default. Don't foget to put ffmpeg.exe in same dir as script, get it here http://sourceforge.net/projects/mplayer-win32/files/

Edited by Datenshi

Share this post


Link to post
Share on other sites



I selected a folder with 1 flv file, now I have a GUI, which is always on top, and cannot be moved or minimized, sitting at position 0,0 on my desktop, which says "Initializing" and progress is "0/0". ffmpeg is running my CPU at 80% (which is normal) but I have no idea when ffmpeg will finish! It is very inconvenient to have that little GUI sitting there. Some more work needed on usability.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Its a progress window, that's why i said its a simple script and that i wont maintain it/improve it. If it doesn't suite you which I'm sure it doesn't, change it! easy as that.

This is the example scripts forums, not free software forum.

Edited by Datenshi

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