Recursively convert images in each subfolder into individual videos using FFmpeg

I am using this script to convert all images in a folder into a video. Each image is shown for 4 seconds and the script runs from a bat file.

`ffmpeg -framerate 1/4 -i %%03d.jpg -pix_fmt yuv420p video.mp4`

I have hundreds of subfolders each containing images with the same resolution and I want to convert them into one moive per subfolder.

I might be close to a solution but it still does not do the job

@echo off
setlocal enabledelayedexpansion

:: Set the frame rate and file format
set "framerate=1/4"
set "image_format=%%03d.jpg"
set "output_video=video.mp4"

:: Traverse all subfolders
for /d /r %%F in (*) do (
    echo Processing folder: %%F
    cd "%%F"
    :: Check if images exist
    if exist "%image_format%" (
        echo Converting images in %%F to video...
        ffmpeg -framerate %framerate% -i "%image_format%" -pix_fmt yuv420p "%%~nxF.mp4"
    ) else (
        echo No images found in %%F, skipping...
    )
    cd ..
)

Any help is appreciated

Read more here: Source link