Join multiple Fraps videos with FFmpeg 'concat:'

raffriff

Moderator
Staff member
Site Contributor
#1
UPDATED 13 July, 2013

I found a new method to join Fraps AVI segments using the FFmpeg "concat:" protocol
(it's new to me anyway.)
The following script is kind of a proof-of-concept, but it's still very usable as it is.
(this post was formerly 'buried' in another thread)

Save the code below as 'FFrapsJoin.vbs' (or whatever you like).
There are some things that you need to modify in this script:
  • You MUST set FFPATH = to the full path for ffmpeg.exe
    (the default location is "C:\Program Files\ffmpeg\bin\ffmpeg.exe")
    ...

    If you don't have ffmpeg, in my opinion the best place to get it is here:
    http://ffmpeg.zeranoe.com/builds/
    ...
  • For best performance, you MAY set the OUTPATH= to a folder on a different
    physical drive.
    (the default is to save to the source folder - which is OK, just a little slower)
    ...
  • You MAY choose a different encoding preset
    (the default is a high quality encode suitable for uploading to YouTube)

    Look near the beginning of the file for the lines starting with switches = ...
    • un-comment (remove the ['] in front of) the setting you want;
    • comment (put a ['] in front of) all the others
    • or make your own if you know what you're doing; see here for more samples
    • Optional: save versions of the script with different command lines
How to use it:
1) drag videos you want to join onto the script icon (limit about 20);​
>> NOTE you have to select the "group of files" manually;
all Fraps files that belong together will have the same Modified date & time
2) NEW: script will modify file names, replacing illegal characters with "_"​
3) FFmpeg will run in a command window;​
4) a new video will be created, called "<first file name>-joined.avi";​
5) examine the new video, and if OK, delete the source files.​
NOTE: all files must be same resolution and frame rate or they won't join​

FFrapsJoin.vbs
Code:
'****************************************************
'** FFrapsJoin - joins AVI files together with FFmpeg
'****************************************************
Option Explicit
'
'** REQUIREMENTS:
'    * FFmpeg http://ffmpeg.zeranoe.com/builds/
'    * script must be located in source folder
'    * script must be run from source folder (won't run over a network)
'    * maximum 20 files at a time, more or less
'    * files must be same size, frame rate etc.
'    * Fraps source files are assumed; other files may or may not work.
 
'** USER SETTINGS:
'
'** change this path as required:
Const FFPATH = "C:\Program Files\ffmpeg\bin\ffmpeg.exe"
 
'** set OUTPATH to a folder on a different physical drive for best performance:
'Const OUTPATH = "G:\VideoProjects\raw" ' (example - this line is commented out)
Const OUTPATH = "" '( if empty, default = source folder, which is also script folder)
 
Dim switches
'** change the FFmpeg command line as desired:
'    * un-comment (remove the ['] in front of) the setting you want;
'    * comment (put a ['] in front of) all the others
 
'** stream copy: no re-encoding
'switches = "-f avi -acodec copy -vcodec copy"
 
'** "near-lossless" for intermediate use (about 4:1 compression)
'switches = "-acodec pcm_s16le -vcodec mjpeg -q:v 1 -qmin 1 -pix_fmt yuvj420p -vf ""format=yuv420p"""
 
'** for upload (default) (about 12:1 compression)
switches = "-f avi -acodec copy -vcodec libx264 -crf 19.0 -pix_fmt yuv420p -nr 500 -preset faster -tune zerolatency -trellis 0 -deblock -1:-2 -x264opts bframes=2:weightp=0:b-pyramid=none"
 
'** for upload at best speed (about 12:1 compression)
'  (much faster, but quality is not as nice as the above setting)
'switches = "-f avi -acodec copy -vcodec libx264 -crf 24.0 -pix_fmt yuv420p -preset ultrafast -tune zerolatency -keyint_min 1 -x264opts keyint=1:non-deterministic=1:sliced-threads=1"
 
 
'** YOU SHOULD NOT HAVE TO CHANGE ANYTHING BELOW THIS LINE........................
 
Const APP_EXE = "FFrapsJoin.vbs"
Const APP_TITLE = "FFrapsJoin"
Const VERSION = "1.7"
 
Dim USAGE: USAGE = APP_EXE & " - USAGE:"
USAGE = USAGE & vbCrLf & "  1) drag videos you want to join onto the script icon (limit about 20);"
USAGE = USAGE & vbCrLf & "  2) FFmpeg will run in a command window;"
USAGE = USAGE & vbCrLf & "  3) a new video will be created called ""<first file name>-joined.avi"";"
USAGE = USAGE & vbCrLf & "  4) examine the new video, and if OK, delete the source files."
USAGE = USAGE & vbCrLf & "  NOTE: all files must be same resolution and frame rate or they won't join"
 
'@version 1.5  28-Feb-2012  - revise FrapsJoin version 1.4 - join directly with FFmpeg
'@version 1.51 01-Mar-2012  - add "high-speed" preset
'@version 1.7  15-Jul-2013  - updated mjpeg codec, concat sytax
'
' copyright 2013 Lindsay Bigelow (raffriff)
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'
' Fraps is a trademark of Beepa Pty Ltd.
' FFmpeg is free software under the GNU General Public License.
'
'***********************
'MAIN
 
    Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
    Dim wsh: Set wsh = CreateObject("WScript.Shell")
    Dim p  'path
    Dim n  'file name
    Dim n1 '1st file name
 
    '** show USAGE if no arguments:
    Dim countArgs: countArgs = WScript.Arguments.Count
    If (countArgs = 0) Then
        MsgBox USAGE, vbExclamation, APP_TITLE
        WScript.Quit
    End If
 
    '** copy arguments to local array
    Dim i, j, t
    Dim args: ReDim args(countArgs - 1)
    For i = 0 To (countArgs - 1)
        args(i) = WScript.Arguments(i)
    Next
 
    '** sort arguments:
    For i = (countArgs - 2) To 0 Step (-1)
        For j= 0 to i
            If (StrComp(args(j), args(j + 1), vbTextCompare) > 0) Then
                t = args(j + 1)
                args(j + 1) = args(j)
                args(j) = t
            End If
        Next
    Next
 
    '** build FFmpeg command line using concat protocol:
 
    Const FFMT = -2 'system default
    Dim plist: plist =  fso.GetParentFolderName(args(0)) & "\FFrapsJoin-join.lst"
    Dim flist: Set flist = fso.OpenTextFile(plist, 2, FFMT) 'ForWriting
 
    flist.Write "ffconcat version 1.0" & vbLf & vbLf
    n1 = ""
    For i = 0 To (countArgs - 1)
        p = args(i)
        n = fso.GetBaseName(p) & "." & fso.GetExtensionName(p)
        If (Len(n1) = 0) Then
            n1 = fso.GetBaseName(p)
        End If
        n = xFixName(n)
        flist.Write "file " & n & vbLf & vbLf
    Next
    flist.Close
 
    ' wait for file 'plist' to exist:
    Set flist = fso.OpenTextFile(plist, 1, FFMT) 'ForReading
    t = flist.ReadLine()
    flist.Close
 
    '** create batch file in current folder:
    Dim pbat: pbat =  fso.GetParentFolderName(args(0)) & "\" & n1 & "-join.bat"
    Dim fbat: Set fbat = fso.OpenTextFile(pbat, 2, FFMT) 'ForWriting
    Dim pp:  pp = OUTPATH
    If (Len(pp)) Then
        If (Right(pp, 1) <> "\") Then
            pp = pp & "\"
        End If
    End If
 
    '** write batch file:
    fbat.WriteLine fso.GetDriveName(args(0))
    fbat.WriteLine "cd " & fso.GetParentFolderName(args(0))
    fbat.WriteLine """" & ffpath & """ -i concat:""" & plist & """ " & _
                  switches & " """ & pp & n1 & suffix & """"
    fbat.WriteLine "pause"
    fbat.WriteLine "del """ & plist & """"
    fbat.WriteLine "del """ & pbat & """"
    fbat.Close
 
    '** run batch file:
    wsh.Run """" & pbat & """"
 
WScript.Quit(0)
'END MAIN
 
'**************************
'
Function xFixName(ByVal s) 'As String
 
    Dim f: Set f = fso.GetFile(fso.GetParentFolderName(args(0)) & "\" & s)
    Dim rex: Set rex = New RegExp
 
    rex.Pattern = "[^a-zA-Z0-9._-]"
    rex.Global = True
 
    s = rex.Replace(s, "_")
    s = Replace(s, "__", "_")
 
    If (f.Name <> s) Then
        On Error Resume Next
        f.Name = s
        Do While (Err.Number <> 0)
            Err. Clear
            s = "_" & s
            f.Name = s
        Loop
    End If
    xFixName = s
End Function
EDIT 7 May 2012 - rename to 'FFrapsJoin' to avoid confusion with the project 'AviJoin' on SourceForge
EDIT 15 June 2012 - added MJPEG codec, updated 'concat' syntax (not sure when ffmpeg changed it...)
 
Top