VideoHelp Forum




+ Reply to Thread
Results 1 to 13 of 13
  1. With the help of people here and at superuser.com I have successfully created a new type of concatenation script. I'll start from the beginning, I was backing up my DVD collection to my hard drive. Disks are fragile, so I wanted to keep them where they belong: on a shelf. Anyway, a lot of the DVD files I was concatenating had timestamps that didn't quite sync. This is actually a common issue with disks and certain types of media. The usual solution is to just use mkvtoolnix instead, but this time I wanted to fix the issue directly, and automate concatenation to a single action, in this case, dragging and dropping the files to be concatenated onto a batch script, which I dubbed ffconcat.bat. Still, no matter what I tried, fixing the timestamps during concatenation always failed, and the only viable suggestion my research yielded was instructions for re-creating the files to be concatenated with synced timestamps and then concatenating them instead. So I decided to automate THAT process instead, which threw a big wrench in my original script but I worked through it. There is one problem however, and I don't have time to fix it in this version of the script, seeing as it's not so easy to fix as it sounds. (Still, the script can operate just fine as is, for now anyway) I made the script sort the list of files to be concatenated in alphanumeric order. This way the file names can establish order of concatenation. Problem is the way cmd sorts the lines in the listfile. For example, if I tried to sort this:

    1
    2
    4
    5
    6
    10
    3
    7
    8
    9

    I get this:

    1
    10
    2
    3
    4
    5
    6
    7
    8
    9

    But I want this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    So instead files have to be named like this:

    01
    02
    03
    04
    05
    06
    07
    08
    09
    10

    It's not the end of the world, and it's not even an issue if your combining 9 or less files. I hope to fix it someday, but after days focusing on this, life is starting to catch up. I got stuff to do, but I'll update this someday. Right then, here is my code, it's currently set up to combine everything without re-encoding, but if you change the output command for ffmpeg (3rd line from the bottom) you can output with whatever arguments you like. Oh, and this works for all common media formats. Output is Output.mkv in the same directory as the batch file. Place the batch file in the same directory as ffmpeg.exe

    ffconcat.bat:

    Code:
    mkdir "%~dp0Temp"
    
    Echo Const ForReading = 1 > "%~dp0Temp\Replace.vbs"
    Echo Const ForWriting = 2 >> "%~dp0Temp\Replace.vbs"
    Echo strFileName = Wscript.Arguments(0) >> "%~dp0Temp\Replace.vbs"
    Echo strOldText = Wscript.Arguments(1) >> "%~dp0Temp\Replace.vbs"
    Echo strNewText = Wscript.Arguments(2) >> "%~dp0Temp\Replace.vbs"
    Echo Set objFSO = CreateObject("Scripting.FileSystemObject") >> "%~dp0Temp\Replace.vbs"
    Echo Set objFile = objFSO.OpenTextFile(strFileName, ForReading) >> "%~dp0Temp\Replace.vbs"
    Echo strText = objFile.ReadAll >> "%~dp0Temp\Replace.vbs"
    Echo objFile.Close >> "%~dp0Temp\Replace.vbs"
    Echo strNewText = Replace(strText, strOldText, strNewText) >> "%~dp0Temp\Replace.vbs"
    Echo Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) >> "%~dp0Temp\Replace.vbs"
    Echo objFile.Write strNewText  'WriteLine adds extra CR/LF >> "%~dp0Temp\Replace.vbs"
    Echo objFile.Close >> "%~dp0Temp\Replace.vbs"
    cscript //nologo "%~dp0Temp\Replace.vbs"
    
    @echo off setlocal enabledelayedexpansion
    echo. > "%~dp0Temp\Concat1.txt"
    for %%i in (%*) do if not exist "%~dp0Temp\%%~ni.mkv" (
       ffmpeg -fflags +genpts -y -i "%%~i" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~dp0Temp\%%~ni.mkv"
    )
    for %%A in (%*) do ( echo file '%~dp0Temp\%%~nxA'>> "%~dp0Temp\Concat1.txt" )
    
    sort < "%~dp0Temp\Concat1.txt" > "%~dp0Temp\Concat2.txt"
    
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3G2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3g2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3GP'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3gp'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3GP2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3gp2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3GPP'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".3gpp'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AAC'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".aac'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AC3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ac3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AIF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".aif'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AIFF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".aiff'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AMR'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".amr'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AMV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".amv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".APE'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ape'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ASF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".asf'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".AVI'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".avi'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".CDA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".cda'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DIVX'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".divx'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DPG'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".dpg'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DSF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".dsf'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DTS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".dts'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DTSHD'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".dtshd'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".DVR-MS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".dvr-ms'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".EAC3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".eac3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".EVO'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".evo'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".F4V'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".f4v'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".FLAC'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".flac'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".FLV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".flv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".IFO'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ifo'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".K3G'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".k3g'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M1A'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m1a'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M1V'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m1v'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M2A'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m2a'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M2T'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m2t'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M2TS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m2ts'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M2V'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m2v'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M4A'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m4a'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M4B'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m4b'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M4P'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m4p'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".M4V'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".m4v'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MKA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mka'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MKV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mkv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MOD'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mod'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MOV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mov'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MP2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mp2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MP2V'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mp2v'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MP3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mp3'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MP4'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mp4'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpa'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPC'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpc'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPD'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpd'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPE'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpe'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPEG'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpeg'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPG'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpg'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MPV2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mpv2'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MTS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mts'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".MXF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".mxf'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".NSR'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".nsr'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".NSV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".nsv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".OGG'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ogg'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".OGM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ogm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".OGV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ogv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".OPUS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".opus'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".QT'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".qt'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".RA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ra'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".RAM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ram'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".RM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".rm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".RMVB'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".rmvb'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".RPM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".rpm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".SKM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".skm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".SWF'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".swf'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TAK'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".tak'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TP'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".tp'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TPR'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".tpr'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TRP'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".trp'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TS'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".ts'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".TTA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".tta'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".VOB'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".vob'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WAV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wav'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WEBM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".webm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WM'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wm'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WMA'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wma'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WMP'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wmp'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WMV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wmv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WTV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wtv'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".WV'" ".mkv'"
    cscript "%~dp0Temp\Replace.vbs" "%~dp0Temp\Concat2.txt" ".wv'" ".mkv'"
    
    ffmpeg -fflags +genpts -f concat -safe 0 -i "%~dp0Temp\Concat2.txt" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~dp0Output.mkv"
    del /Q "%~dp0Temp"
    rmdir "%~dp0Temp"
    pause
    Note: I found the vbscript part here: https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-...and-line-envir
    Quote Quote  
  2. Renaming of those extensions might be avoided, not sure now.

    For utilities on your PC since you start, I recommend using python. You've been warned

    I converted that batch from above into python, it seams to work with some tests. File can be named ffconcat.py
    Code:
    from pathlib import Path
    import shlex
    from subprocess import Popen, PIPE
    import sys
    import shutil
    
    FFMPEG = r"F:\tools\ffmpeg.exe"
    
    def run_command(cmd):
        print(cmd)
        p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
        line = 1
        while line:
            line = p.stderr.readline().decode('utf-8')
            print(line)    
    
    def main(filepaths):
        if not filepaths:
            raise ValueError("no filepaths were given")
        filepaths =  [Path(f) for f in filepaths]
        filepaths_dir = filepaths[0].parent
        temp_dir = filepaths_dir / "Temp"
        #create temp directory
        temp_dir.mkdir(parents=True, exist_ok=True)
    
        concat_filepath = str(temp_dir / "concat.txt")
        with open(concat_filepath, 'w') as concat:
            for filepath in filepaths:
                filepath_out = temp_dir / f"{filepath.stem}.mkv"
                #write mkv filepath into a concat text file
                concat.write(f"file '{filepath_out}'\n")
                if filepath_out.is_file():
                    continue
                #if mkv does not exist, run ffmpeg, reset_timestamps and save it as mkv file
                cmd = f'"{FFMPEG}" -fflags +genpts -y -i "{filepath}" -c copy -reset_timestamps 1 -video_track_timescale 90000 "{filepath_out}"'
                run_command(cmd)
        
        #concat mkv filepaths
        output_filepath = filepaths_dir / f"output.mkv"
        cmd = f'"{FFMPEG}" -fflags +genpts -f concat -safe 0 -i "{concat_filepath}" -c copy -reset_timestamps 1 -video_track_timescale 90000 "{output_filepath}"'
        run_command(cmd)
    
        #delete temp directory, remove this line if changing code, so accidentally some directory is not deleted!
        #or remove this line and always delete temp directory manually
        shutil.rmtree(temp_dir)
    
    if __name__ == "__main__":
        """
        Usage:
        drop files on this ffconcat.py
        or use command line:
        python ffconcat.py video1 video2 ....
        """
        filepaths = []
        for arg in sys.argv[1:]:
            filepaths.append(arg)
        main(filepaths)
    same as batch file, files can be dropped on ffconcat.py or use in command line: python ffconcat.py video1 video2 etc.
    Last edited by _Al_; 12th Oct 2023 at 00:43.
    Quote Quote  
  3. Originally Posted by _Al_ View Post
    Renaming of those extensions might be avoided, not sure now.

    For utilities on your PC since you start, I recommend using python. You've been warned

    I converted that batch from above into python, it seams to work with some tests. File can be named ffconcat.py
    Code:
    from pathlib import Path
    import shlex
    from subprocess import Popen, PIPE
    import sys
    import shutil
    
    FFMPEG = r"F:\tools\ffmpeg.exe"
    
    def run_command(cmd):
        print(cmd)
        p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
        line = 1
        while line:
            line = p.stderr.readline().decode('utf-8')
            print(line)    
    
    def main(filepaths):
        if not filepaths:
            raise ValueError("no filepaths were given")
        filepaths =  [Path(f) for f in filepaths]
        filepaths_dir = filepaths[0].parent
        temp_dir = filepaths_dir / "Temp"
        #create temp directory
        temp_dir.mkdir(parents=True, exist_ok=True)
    
        concat_filepath = str(temp_dir / "concat.txt")
        with open(concat_filepath, 'w') as concat:
            for filepath in filepaths:
                filepath_out = temp_dir / f"{filepath.stem}.mkv"
                #write mkv filepath into a concat text file
                concat.write(f"file '{filepath_out}'\n")
                if filepath_out.is_file():
                    continue
                #if mkv does not exist, run ffmpeg, reset_timestamps and save it as mkv file
                cmd = f'"{FFMPEG}" -fflags +genpts -y -i "{filepath}" -c copy -reset_timestamps 1 -video_track_timescale 90000 "{filepath_out}"'
                run_command(cmd)
        
        #concat mkv filepaths
        output_filepath = filepaths_dir / f"output.mkv"
        cmd = f'"{FFMPEG}" -fflags +genpts -f concat -safe 0 -i "{concat_filepath}" -c copy -reset_timestamps 1 -video_track_timescale 90000 "{output_filepath}"'
        run_command(cmd)
    
        #delete temp directory, remove this line if changing code, so accidentally some directory is not deleted!
        #or remove this line and always delete temp directory manually
        shutil.rmtree(temp_dir)
    
    if __name__ == "__main__":
        """
        Usage:
        drop files on this ffconcat.py
        or use command line:
        python ffconcat.py video1 video2 ....
        """
        filepaths = []
        for arg in sys.argv[1:]:
            filepaths.append(arg)
        main(filepaths)
    same as batch file, files can be dropped on ffconcat.py or use in command line: python ffconcat.py video1 video2 etc.
    Ah cool man! I'm sure python users will love that, and yes I do understand the difficulties of using dos. Still, I like to avoid 3rd-party programs if at all possible, if I only make use of dos, vbscript and registry keys, maybe some powershell too then people can just copy/paste the script, easy, no extra downloads. Besides it makes it more challenging that way. Still alphabetizing properly might in fact need a third-party program, if that's true I might be forced to use python this time.
    Quote Quote  
  4. ok, then this in windows batch, same as your script above, no vb needed

    using subroutines/functions to avoid complications if code needs to be changed
    Code:
    @echo off
    
    :define_variables
    set "temp_dir=%~dp0Temp"
    set "concat1=%temp_dir%\Concat1.txt"
    set "concat2=%temp_dir%\Concat2.txt"
    set "output_file=%~dp0\Output.mkv"
    set "ffmpeg=F:\tools\ffmpeg.exe"
    
    :start
    mkdir "%temp_dir%"
    echo. > "%concat1%"
    for %%i in (%*) do call :process "%%~i"
    sort < "%concat1%" > "%concat2%"
    call :concat "%concat2%" "%output_file%"
    del /Q "%temp_dir%"
    rmdir "%temp_dir%"
    :end
    echo End of ffconcat.bat, press any key to exit ... & pause>nul & exit
    
    
    
    :process <filepath>
    set "mkv_filepath=%temp_dir%\%~n1.mkv"
    if not exist "%mkv_filepath%"  call :create_mkv "%~1" "%mkv_filepath%"
    echo file '%mkv_filepath%'>> "%concat1%"
    goto :eof
    
    :create_mkv <filepath> <mkv filepath>
    "%ffmpeg%" -fflags +genpts -y -i "%~1" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~2"
    goto :eof
    
    :concat <concat text file> <output file>
    "%ffmpeg%" -fflags +genpts -f concat -safe 0 -i "%~1" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~2"
    goto :eof
    Last edited by _Al_; 12th Oct 2023 at 12:41.
    Quote Quote  
  5. Originally Posted by _Al_ View Post
    ok, then this in windows batch, same as your script above, no vb needed

    using subroutines/functions to avoid complications if code needs to be changed
    Code:
    @echo off
    
    :define_variables
    set "temp_dir=%~dp0Temp"
    set "concat1=%temp_dir%\Concat1.txt"
    set "concat2=%temp_dir%\Concat2.txt"
    set "output_file=%~dp0\Output.mkv"
    set "ffmpeg=F:\tools\ffmpeg.exe"
    
    :start
    mkdir "%temp_dir%"
    echo. > "%concat1%"
    for %%i in (%*) do call :process "%%~i"
    sort < "%concat1%" > "%concat2%"
    call :concat "%concat2%" "%output_file%"
    del /Q "%temp_dir%"
    rmdir "%temp_dir%"
    :end
    echo End of ffconcat.bat, press any key to exit ... & pause>nul & exit
    
    
    
    :process <filepath>
    set "mkv_filepath=%temp_dir%\%~n1.mkv"
    if not exist "%mkv_filepath%"  call :create_mkv "%~1" "%mkv_filepath%"
    echo file '%mkv_filepath%'>> "%concat1%"
    goto :eof
    
    :create_mkv <filepath> <mkv filepath>
    "%ffmpeg%" -fflags +genpts -y -i "%~1" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~2"
    goto :eof
    
    :concat <concat text file> <output file>
    "%ffmpeg%" -fflags +genpts -f concat -safe 0 -i "%~1" -c copy -reset_timestamps 1 -video_track_timescale 90000 "%~2"
    goto :eof
    I like how efficient this script is, too bad it didn't work for me. For some reason it says file not found, did the files to be dragged and dropped need to be in the same directory or something? And I'm curious, how did you make the extensions in the listfile mkv? I didn't spot that part of the code anywhere
    Quote Quote  
  6. no, I do not have them in the same directory

    it might be ffmpeg path, I defined variable ffmpeg because I do not have it in Windows %PATH%, I use portable setups on windows.,
    define proper ffmpeg path in that script , or delete the line and in script instead of "%ffmpeg%" use just ffmpeg, if ffmpeg is in %PATH% or in the same directory
    Quote Quote  
  7. Originally Posted by _Al_ View Post
    no, I do not have them in the same directory

    it might be ffmpeg path, I defined variable ffmpeg because I do not have it in Windows %PATH%, I use portable setups on windows.,
    define proper ffmpeg path in that script , or delete the line and in script instead of "%ffmpeg%" use just ffmpeg, if ffmpeg is in %PATH% or in the same directory
    Ah, seems you made a small error. The original code works on files other than MKV, but this one requires even the source files to be mkv. It's the entire reason I had to change all those extensions in my code, because the original listfile generated with the original files would also have the original extensions, but in fact the generated listfile will instead be used to concat files of the same name but in a mkv container.
    Quote Quote  
  8. I tested it with source files as avi, and it should work even for mkv files as well. Final Concat txt has those mkv fles listed created in Temp directory. Not sure what you mean, if I misunderstood that script.
    Quote Quote  
  9. instead of
    Code:
    del /Q "%temp_dir%"
    rmdir "%temp_dir%"
    use
    Code:
    rem del /Q "%temp_dir%"
    rem rmdir "%temp_dir%"
    to be able to double check files in Temp directory
    Quote Quote  
  10. Originally Posted by _Al_ View Post
    I tested it with source files as avi, and it should work even for mkv files as well. Final Concat txt has those mkv fles listed created in Temp directory. Not sure what you mean, if I misunderstood that script.
    Sorry, my mistake. I had an iso mounted I was running tests on, but the USB I had the iso on got disconnected. I remounted the file and now it's working great! Lovely, this will save many people a lot of time, thanks for the help
    Quote Quote  
  11. no problem, sorry for being a pain, I'm on the mission - to emphasize using of functions, call processes etc. within batch script, because it significantly improves readability, exposes what variables are needed for what procedure, like in our case ffmpeg command line.It is generally always avoided because passing paths as variables might be problematic (empty characters in paths), so expanded filepaths with quotes could be used, as in script above, and it just always work. You provided a nice example.

    Besides. Nice procedure, it is really handy now, thanks.
    I was interested in this for home videos, but a bit advanced procedures when there are different formats needed to be joined, but that needs re-encoding obviously. Not like in this case, concatenating same format.
    Quote Quote  
  12. -video_track_timescale 90000 has no effect with mkv container.
    - reset_timestamps is an option of the segment muxer. Has nothing to do with -f concat.
    Last edited by ProWo; 12th Oct 2023 at 15:23.
    Quote Quote  
  13. Originally Posted by _Al_ View Post
    no problem, sorry for being a pain, I'm on the mission - to emphasize using of functions, call processes etc. within batch script, because it significantly improves readability, exposes what variables are needed for what procedure, like in our case ffmpeg command line.It is generally always avoided because passing paths as variables might be problematic (empty characters in paths), so expanded filepaths with quotes could be used, as in script above, and it just always work. You provided a nice example.

    Besides. Nice procedure, it is really handy now, thanks.
    I was interested in this for home videos, but a bit advanced procedures when there are different formats needed to be joined, but that needs re-encoding obviously. Not like in this case, concatenating same format.
    Yep, this is pretty much just for concatenating videos of the same format, frame size, etc., at least in it's current state. Still, by adjusting the first ffmpeg command you can even concat videos of different frame sizes and such, you would just need to specify arguments to render everything different about the videos to instead be the same, and that's even easier with your shorter version of the script. Less fluff to scroll through . And ofc by adjusting the second command you can control the output format, which in my case was the whole point. You see, I'm experimenting with VVC. I did many tests and found the best arguments to create a VVC/AAC file with the best quality. VVC is like 26x smaller than h.264, and soon so will my DVD collection. I got disks stacked to the rafters man, and the only bad thing about it is how fragile they are. I want them all on my hard drive, assuming I can fit them somehow.

    Originally Posted by ProWo View Post
    -video_track_timescale 90000 has no effect with mkv container.
    - reset_timestamps is an option of the segment muxer. Has nothing to do with -f concat.
    Oh I didn't realize that, but I know one of the timestamp commands I used definitely worked, else my test files qould not have combined. If your right, perhaps it was this part: -fflags +genpts
    Also, if reset_timestamps is part of the segment muxer than it would have been effective during the initial conversion, before the concat procedure. Assuming the command works with the mkv container, ofc.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!