Collection of FFMPEG Drag & Drop CMD/BAT Tools
Here’s a small collection of scripts i’ve made, downloaded, modified, etc to compress, edit, add, remux video files as well as converting mkv files without the need of re-rendering.
Copy the code and save as a .bat file, save it on your ffmpeg bin folder or any command line if ffmpeg was installed with its environment path.
To use the scripts, just drag and drop your video file on the .bat file you created.
Download ffmpeg from here: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z
In case FFMPEG is missing or the path is not configured, follow these steps.
Download the lastest “static” ffmpeg pack.
Browse in the archive up to the bin
subfolder containing ffmpeg, ffprobe and ffplay executables. Uncompress the bin
folder (in this example we’ll use C:\ffmpeg\bin
)
Register ffmpeg, ffprobe & ffplay to environment variables
Through command lines:
Hit the windows key, write down cmd
and press Enter and enter the following command, line after line:
set ffmpeg=C:\ffmpeg\bin
set ffprobe=C:\ffmpeg\bin
set ffplay=C:\ffmpeg\bin
Through user interface:
Go to:
My Computer/Environment variables
Add Name: ffmpeg Value: C:\ffmpeg\bin
Add Name: ffprobe Value: C:\ffmpeg\bin
Add Name: ffplay Value: C:\ffmpeg\bin
Add Frame Number to .mov
You can draw the frame number on top of the video and render it as a new file.
rem @echo off
:again
cd /D %~p1
ffmpeg ^
-i "%~nx1" ^
-vf "drawtext=fontfile=/Windows/Fonts/courbd.ttf: text='Frame \: %%{eif\:n\:d\:2}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: fontsize=40: box=1: boxcolor=black@0.4: boxborderw=8" ^
-c:a copy ^
"%~p1%~n1_framenumbered.mov"
pause
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Convert Any Video to a 100MB File
Reduce the size of your video to match a 100MB limit.
@echo off
:again
cd /D %~p0
SET output=%~p1%~n1_100MB.mp4
set cmd="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %1 "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET seconds=%%i
echo aaaa
echo aaaa
SET /A "totalBitrate=500000/seconds"
SET overheadBitrate=100
SET audioBitrate=96
SET /A "videoBitrate=totalBitrate-audioBitrate-overheadBitrate"
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 1 -b:a %audioBitrate%k ^
-f mp4 NUL && \
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 2 ^
-b:a %audioBitrate%k "%output%"
del /q ffmpeg2pass-*.log ffmpeg2pass-*.mbtree
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Convert Video to Discord File Size Limits
Reduce the video size to match Discord limit.
@echo off
:again
cd /D %~p0
SET output=%~p1%~n1_Discorded.mp4
set cmd="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %1 "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET seconds=%%i
echo aaaa
echo aaaa
SET /A "totalBitrate=64000/seconds"
SET overheadBitrate=100
SET audioBitrate=96
SET /A "videoBitrate=totalBitrate-audioBitrate-overheadBitrate"
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 1 -b:a %audioBitrate%k ^
-f mp4 NUL && \
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 2 ^
-b:a %audioBitrate%k "%output%"
del /q ffmpeg2pass-*.log ffmpeg2pass-*.mbtree
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Convert Video to Facebook File Size Limits
Reduce the video size to match Facebook limit.
@echo off
:again
cd /D %~p0
SET output=%~p1%~n1_Messengered.mp4
set cmd="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %1 "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET seconds=%%i
echo aaaa
echo aaaa
SET /A "totalBitrate=160000/seconds"
SET overheadBitrate=100
SET audioBitrate=96
SET /A "videoBitrate=totalBitrate-audioBitrate-overheadBitrate"
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 1 -b:a %audioBitrate%k ^
-f mp4 NUL && \
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 2 ^
-b:a %audioBitrate%k "%output%"
del /q ffmpeg2pass-*.log ffmpeg2pass-*.mbtree
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Convert Video to Whatsapp File Size Limits
Reduce the video size to match Whatsapp limit.
@echo off
:again
cd /D %~p0
SET output=%~p1%~n1_Whatsapped.mp4
set cmd="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %1 "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET seconds=%%i
echo aaaa
echo aaaa
SET /A "totalBitrate=260000/seconds"
SET overheadBitrate=100
SET audioBitrate=96
SET /A "videoBitrate=totalBitrate-audioBitrate-overheadBitrate"
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 1 -b:a %audioBitrate%k ^
-f mp4 NUL && \
ffmpeg ^
-i %1 ^
-c:v libx264 ^
-b:v %videoBitrate%k ^
-pass 2 ^
-b:a %audioBitrate%k "%output%"
del /q ffmpeg2pass-*.log ffmpeg2pass-*.mbtree
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
MKV 5.1 audio to Stereo without rendering (Useful when source audio cannot be played on your TV)
Downmix 5.1 audio to Stereo for MKV files with 5.1 audio that can’t be played.
@echo off
cd /D %~p0
echo Convert Audio to Stereo ...
for %%i in (%*) do if not exist "%~p1%%~ni_Stereo.mkv" (
ffmpeg.exe -i "%%~i" -map 0 -c copy -c:a aac -ac 2 "%~p1%%~ni_Stereo.mkv"
)
popd
echo Done..
Extract Audio Track #2 from MKV video and export it as an mp4 audio file
This script extracts the audio track #2 from the mkv you drop, if you need to extract track #1 then modify the “-map 0:a:1” to “-map 0:a:0” (track begin at 0 instead of 1)
@echo off
cd /D %~p0
echo Extracting audio track 2 ...
for %%i in (%*) do if not exist "%~p1%%~ni_Audio.mp4" (
ffmpeg -i "%%~i" -map 0:a:1 -c copy -c:a aac -ac 2 "%~p1%%~ni_Audio.mp4"
)
popd
echo Done..
Offset Audio by 1.4 seconds without re-encoding
@echo off
cd /D %~p0
echo Delay audio by 1.4 seconds ...
for %%i in (%*) do if not exist "%~p1%%~ni_delayed.mp4" (
ffmpeg.exe -i "%%~i" -itsoffset 1.4 -i "%%~i" -map 0:v -map 1:a -c copy "%~p1%%~ni_delayed.mp4"
)
popd
echo Done..
Video to instagram size and blurred background fitting
@echo off
:again
:: To change the resolution, change the SquareSize value above (just after the =). Default is 600.
set SquareSize=600
ffmpeg -i "%~1" ^
-c:v libx264 -crf 23 -filter_complex "[0:v]split=2[blur][vid];[blur]scale=%SquareSize%:%SquareSize%:force_original_aspect_ratio=increase,crop=%SquareSize%:%SquareSize%,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[vid]scale=%SquareSize%:%SquareSize%:force_original_aspect_ratio=decrease[ov];[bg][ov]overlay=(W-w)/2:(H-h)/2" -profile:v baseline -level 3.0 -pix_fmt yuv420p -preset faster -tune fastdecode ^
-c:a aac -ac 2 -b:a 128k ^
-movflags faststart ^
"%~p1%~n1_Instagramized.mp4" -y
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 10 seconds.[0m
timeout /t 10
Other codes can be found here:
- Source for the last blocks: https://github.com/L0Lock/FFmpeg-bat-collection
- Other command line tools for ffmpeg: https://stackoverflow.com/questions/9913032/how-can-i-extract-audio-from-video-with-ffmpeg
Convert OGV to MP4
Convert any OGV file to an MP4 with fast conversion and using h264, just drag and drop the file into the script.
@echo off
setlocal enabledelayedexpansion
REM Check if FFmpeg is installed
where ffmpeg >nul 2>nul
if %errorlevel% neq 0 (
echo FFmpeg is not installed or not in the system PATH. Please install FFmpeg and try again.
pause
exit /b 1
)
REM Check if a file is provided
if "%~1" == "" (
echo Please drag and drop an OGV file onto this script.
pause
exit /b 1
)
REM Input and output file paths with quotes
set "inputFile=%~1"
set "outputFile=%~dpn1.mp4"
REM Run FFmpeg command with quotes around file paths
ffmpeg -i "!inputFile!" -c:v libx264 -crf 22 -c:a aac -b:a 128k -strict -2 "!outputFile!"
REM Check FFmpeg exit code
if !errorlevel! neq 0 (
echo An error occurred during conversion.
pause
exit /b 1
)
echo Conversion successful. Output file: "!outputFile!"
pause
CONVERT ANY VIDEO TO A TIMELAPSE MP4
Convert any video to a timelapse by using every 15th frames.
@echo off
setlocal enabledelayedexpansion
REM Check if FFmpeg is installed
where ffmpeg >nul 2>nul
if %errorlevel% neq 0 (
echo FFmpeg is not installed or not in the system PATH. Please install FFmpeg and try again.
pause
exit /b 1
)
REM Check if a file is provided
if "%~1" == "" (
echo Please drag and drop an OGV file onto this script.
pause
exit /b 1
)
REM Input and output file paths with quotes
set "inputFile=%~1"
set "outputFile=%~dpn1_timelapse.mp4"
REM Run FFmpeg command with quotes around file paths
ffmpeg -i "!inputFile!" -vf framestep=15,setpts=N/60/TB -r 60 -vcodec libx264 -an "!outputFile!"
REM Check FFmpeg exit code
if !errorlevel! neq 0 (
echo An error occurred during conversion.
pause
exit /b 1
)
echo Conversion successful. Output file: "!outputFile!"
pause
CONVERT ANYTHING TO 720p MP4
Downscale video to match 720p resolution.
@echo off
setlocal enabledelayedexpansion
REM Check if FFmpeg is installed
where ffmpeg >nul 2>nul
if %errorlevel% neq 0 (
echo FFmpeg is not installed or not in the system PATH. Please install FFmpeg and try again.
pause
exit /b 1
)
REM Check if a file is provided
if "%~1" == "" (
echo Please drag and drop an OGV file onto this script.
pause
exit /b 1
)
REM Input and output file paths with quotes
set "inputFile=%~1"
set "outputFile=%~dpn1_720p.mp4"
REM Run FFmpeg command with quotes around file paths
ffmpeg -i "!inputFile!" -vf scale=1280:720 -preset slow -crf 18 "!outputFile!"
REM Check FFmpeg exit code
if !errorlevel! neq 0 (
echo An error occurred during conversion.
pause
exit /b 1
)
echo Conversion successful. Output file: "!outputFile!"
pause
VIDEO TO JPG SEQUENCE
Convert any video to a jpg sequence.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
REM Check if the batch file is called with at least one non-empty argument string.
if "%~1" == "" echo INFO: Drag an MP4 file onto this script to begin frame extraction.& pause & exit /B
set "inputFile=%~1"
REM Create the subdirectory input in the directory named after the video file.
md "%~dpn1\input" 2>nul
if not exist "%~dpn1\input\" echo ERROR: Could not create the directory: "%~dpn1\input"& pause & exit /B 2
REM Extract frames from the MP4 file.
ffmpeg.exe -i "%~1" -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 "%~dpn1\input\image%%03d.jpg"
if errorlevel 1 rd "%~dpn1\input" 2>nul & echo ERROR: Failed to extract the frames from: "%~1"& pause & exit /B 1
echo Extraction complete.
pause
endlocal
Creating thumbnail from video and saving it as a PNG
You can choose a specific frame from the video manually by specifying its timestamp. If you want to capture the frame at 00:15, add -ss 00:00:15 before your input video to take a screenshot at the 15th second of the video.
@echo off
setlocal enabledelayedexpansion
REM Check if FFmpeg is installed
where ffmpeg >nul 2>nul
if %errorlevel% neq 0 (
echo FFmpeg is not installed or not in the system PATH. Please install FFmpeg and try again.
pause
exit /b 1
)
REM Check if a file is provided
if "%~1" == "" (
echo Please drag and drop an OGV file onto this script.
pause
exit /b 1
)
REM Input and output file paths with quotes
set "inputFile=%~1"
set "outputFile=%~dpn1.png"
REM Run FFmpeg command with quotes around file paths
ffmpeg -ss 00:00:05 -i "!inputFile!" -frames:v 1 "!outputFile!"
REM Check FFmpeg exit code
if !errorlevel! neq 0 (
echo An error occurred during conversion.
pause
exit /b 1
)
echo Conversion successful. Output file: "!outputFile!"
pause
CONVERT IMG SEQUENCE TO MP4
@echo off
REM Input and output file paths with quotes
:: The script expects the first parameter to be the image file.
set "imageFile=%~1"
:: Extract the filename without extension for the output video name.
for %%A in ("%imageFile%") do set "filename=%%~nA"
set "inputFile=%filename%.jpg"
set "outputFile=%filename%.mp4"
ffmpeg ^
-framerate 24 ^
-start_number 1 ^
-i "TURN_%%04d.jpg" ^
-c:v libx264 -pix_fmt yuv420p -crf 17 ^
-preset faster -tune fastdecode ^
"TURNTABLE.mp4"
if NOT ["%errorlevel%"]==["0"] goto:error
echo [92m%~n1 Done![0m
shift
if "%~1" == "" goto:end
goto:again
:error
echo [93mThere was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.[0m
pause
exit 0
:end
cls
echo [92mEncoding succesful. This window will close after 2 seconds.[0m
timeout /t 2