Batch file sample to execute an ffmpeg command
Below is a simple Windows batch (.bat) file example that runs an ffmpeg command. Replace the example ffmpeg command and paths with whatever you need.
Save this as run-ffmpeg.bat and run it by double-click or from a command prompt.
Contents of run-ffmpeg.bat:
@echo off
REM -- Set path to ffmpeg executable (either full path or rely on PATH)
SET FFMPEG_EXE="C:\ffmpeg\bin\ffmpeg.exe"
REM -- Set input and output files (change as needed)
SET INPUT_FILE="C:\videos\input.mp4"
SET OUTPUT_FILE="C:\videos\output.mp4"
REM -- Optional: create output folder if it doesn't exist
IF NOT EXIST "%~dp0output" (
mkdir "%~dp0output"
)
REM -- Example ffmpeg command: re-encode to H.264 with 1280x720 scaling
%FFMPEG_EXE% -y -i %INPUT_FILE% -vf "scale=1280:720" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k %OUTPUT_FILE%
REM -- Check errorlevel and report
IF %ERRORLEVEL% EQU 0 (
echo ffmpeg finished successfully.
) ELSE (
echo ffmpeg finished with error code %ERRORLEVEL%.
)
pause
Notes and variations
- If ffmpeg is in your PATH, set FFMPEG_EXE=ffmpeg.exe (or omit the variable and call ffmpeg directly).
- Use -y to overwrite output without prompting. Remove it to be asked before overwrite.
- For multiple files, wrap in a FOR loop: for %%F in ("C:\videos*.mov") do ( "%FFMPEG_EXE%" -i "%%F" -c:v libx264 -c:a aac "C:\out%%~nF.mp4" )
- To avoid the console staying open, remove the final pause.
- Quote paths that contain spaces (examples above use quotes).
If you tell me the specific ffmpeg operation you want (convert container, transcode, extract audio, resize, batch convert a folder, etc.), I can give a tailored .bat file.
Was this answer helpful?
Thanks — your feedback improves the quality gate.