- Place
concatenate_within_folder.batat the top of the directory tree - Open command line at location where the batch file is placed
- Run the batch file by typing
concatenate_within_folder.batin the command line - See instructions within batch file for more details
- Place
move_compress.batat the top of the directory tree - Open command line at location where the batch file is placed
- Run the batch file by typing
move_compress.batin the command line - See instructions within batch file for more details
@echo off & setlocal
set "compress_factor=4";
FOR /r %%i in (.) DO (
cd "%%~fni"
del "list_to_concat.txt"
for %%f in (*.avi) do (
echo file %%f >> "list_to_concat.txt"
)
ffmpeg -f concat -safe 0 -i "list_to_concat.txt" -c copy -vcodec libxvid -q:v %compress_factor% -an -y "%%~fni/%%~ni_concat.avi"
echo "done"
)
@echo off & setlocal
- Display options \
@echo offTurns off the command being displayed in the command line \setlocalcommand is used so that variables defined (see next section) are local in scope. For more explanation, see Local v/s Global variables
set "compress_factor=4";Here we define and assign a local variable calledcompress_factor.
FOR /r %%i in (.) DO ( ... )
- This is a for loop in batch scripting
/roption is used to iterate through all folders and subfolders%%iis the loop variable -- here it is a placeholder for a directoryin (.)-- specifies to begin searching for all directories iteratively, starting from the directory where batch file is placedDO (...)-- carry out the commands within the parentheses
cd "%%~fni"
- Change directory to the directory that is being looped over
cd-- change directory%%~fniis the path to the directoryi(which is the loop variable)%%is usually placed before a loop variable (herei, which is the directory name) to invoke the value of the variable~-- indicates that it is a pathfni-- folder name of ith folder- `~fni
del "list_to_concat.txt"
- Searches the current directory for the file
"list_to_concat.txt"and deletes it (this is necessary as we need to create a new text file with the list of videos to be merged
-
for %%f in (*.avi) do ( echo file %%f >> "list_to_concat.txt" )
- This is a for loop that finds all AVI files in the current directory and adds the line
file NAME_OF_AVIto the text filelist_to_concat.txt- The syntax of for loop is similar to what is explained above;
%%fis the loop variable(*.avi)is used to loop over all files with extension .aviechois used to print (this is similar tofprintfin C language).
ffmpeg ...
- This is the main video processing command
ffmpeg-- call ffmpeg-f-- apply a filter (sometimes-filter_complexis also used -- see other batch files)concat-- name of the filter (can use multiple filters likescale,textbox-- see other batch files in the repository)-safe 0-- Not sure what exactly, but likely a fix for unsafe filenames (see comment in this answer)-i "list_to_concat.txt"---istands for input; here instead of listing each input video to be concatenated, we specify a text file with list of input videos-c copy-- Copy the frames directly without going through decode->filter->encode process (see answer here)-vcodec libxvid-- specify the video codec (XVid here). To list all video codecs available, typeffmpeg -codecsin command line. More info here-q:v %compress_factor%-- Quality of video compression. To use the value of thecompress_factor(or any) static variable defined earlier, enclose them in%-an-- No audio stream in output-y-- Overwrites any existing output file with same name."%%~fni/%%~ni_concat.avi"--%%~fniis the path of the current directory.%%~niis the name of the current directory. So if you are in a directory calledD:/videos, you will see an output videoD:/videos/videos_concat.avi