Here is a batch file for this task.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
(for %%i in (*.mov) do (
md "result_%%~ni"
ffmpeg.exe -i "%%i" -filter_complex "[0:v]boxblur=40,scale=1080x1920,setsar=1[bg];[0:v]scale=1080:1920:force_original_aspect_ratio=decrease[fg];[bg][fg]overlay=y=(H-h)/2" -c:v libx264 -profile:v main -level:v 3.0 -x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 -c:a aac -preset slow -crf 23 -r 30 -sn -force_key_frames "expr: gte(t, n_forced * 0.5)" -f segment -segment_time 14.5 -reset_timestamps 1 "result_%%~ni\%%~ni%%03d.mp4"
if not errorlevel 1 set "FolderName=result_%%~ni" & call :MoveFiles
)) & exit /B
:MoveFiles
set "FolderCount=0"
:FolderLoop
set /A FolderCount+=1
set "SlicesFolder=%FolderName%\Slices_%FolderCount%"
md "%SlicesFolder%"
set "FileCount=0"
for %%j in ("%FolderName%\*.mp4") do (
setlocal EnableDelayedExpansion
if !FileCount! == 10 endlocal & goto FolderLoop
endlocal
move "%%j" "%SlicesFolder%\" >nul
set /A FileCount+=1
)
goto :EOF
Let us assume the current directory on starting the batch file contains the movie file Development & Test(!) 100%.mov
.
The batch file creates the subdirectory result_Development & Test(!) 100%
in the current directory.
Then the batch file runs ffmpeg.exe
which creates in this directory the files:
Development & Test(!) 100%_001.mp4
Development & Test(!) 100%_002.mp4
Development & Test(!) 100%_003.mp4
Development & Test(!) 100%_004.mp4
Development & Test(!) 100%_005.mp4
Development & Test(!) 100%_006.mp4
Development & Test(!) 100%_007.mp4
Development & Test(!) 100%_008.mp4
Development & Test(!) 100%_009.mp4
Development & Test(!) 100%_010.mp4
Development & Test(!) 100%_011.mp4
Development & Test(!) 100%_012.mp4
The subroutine MoveFiles
creates in result_Development & Test(!) 100%
two more subdirectories and moves the files into them. So the final directory structure is:
- result_Development & Test(!) 100%
- Slices_1
- Development & Test(!) 100%_001.mp4
- Development & Test(!) 100%_002.mp4
- Development & Test(!) 100%_003.mp4
- Development & Test(!) 100%_004.mp4
- Development & Test(!) 100%_005.mp4
- Development & Test(!) 100%_006.mp4
- Development & Test(!) 100%_007.mp4
- Development & Test(!) 100%_008.mp4
- Development & Test(!) 100%_009.mp4
- Development & Test(!) 100%_010.mp4
- Slices_2
- Development & Test(!) 100%_011.mp4
- Development & Test(!) 100%_012.mp4
The command exit /B
can be replaced by goto SliceDone
with the label :SliceDone
below the posted code and more command lines with endlocal
as last command line.
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
call /?
echo /?
endlocal /?
exit /?
for /?
goto /?
if /?
md /?
move /?
set /?
setlocal /?
See also: