batch file – ffmpeg – setting video time duration

The script is supposed to take a folder full of images, and convert it into a video slideshow that is 30 seconds long.

I need to set the video output to be 30 seconds long in duration. However the output results in a video that is only half a second long.

@echo off
setlocal enabledelayedexpansion

set "ffmpeg_path=C:\Users\ohhst\OneDrive\Desktop\ffmpeg\bin\ffmpeg.exe"
set "input_folder=%~1"
set "output_file=output.mp4"
set "width=640"
set "height=640"
set "duration=30"

echo Input folder: "%input_folder%"
pause

if not exist "%input_folder%" (
    echo The specified folder does not exist.
    pause
    exit /b 1
)

pushd "%input_folder%"

for %%A in (*.jpg) do set /a "count+=1"

set /a "frame_duration=duration*1000/count"

echo Frame duration: %frame_duration% ms
echo Image count: %count%
pause

echo. > image_list.txt
for %%A in (*.jpg) do echo file '%%A'>> image_list.txt

"%ffmpeg_path%" -f concat -safe 0 -i image_list.txt -vf "scale=%width%:%height%,pad=%width%:%height%:(ow-iw)/2:(oh-ih)/2,setpts=PTS*%duration%/FRAME_RATE" -c:v libx264 -pix_fmt yuv420p -r 30 "%output_file%"

del image_list.txt
popd

echo Video created as "%output_file%"
pause

exit /b 0

Read more here: Source link