FFMPEG Command Collection



Just a collection of FFMPEG commands for encoding

Link to download FFMPEG: https://ffmpeg.org/download.html

Note

First and foremost, make sure to add FFMPEG to your PATH.

By adding FFmpeg to your PATH, you can use FFmpeg commands directly from the command line without having to specify the full path to the executable.

Steps to add FFmpeg to the PATH:


Batch commands:

Batch compress all MP4 files in the same folder

Put this .bat file in the same folder as .MP4 files and have them all be compressed to a CRF rate of 24. Resulting in a smaller filesize. All compressed files will be saved in a new subfolder called “done”.

@echo off
echo === MP4 Batch Compressor === 
echo.

echo This BAT script will compress all the .mp4 files that are in the same folder as this script.
echo All original files will remain untouched.
echo The compressed versions will be placed in a subfolder called "done".
echo.

set /p confirm=Do you wish to proceed? (Y/N): 
if /i not "%confirm%"=="Y" (
    echo Operation cancelled.
    pause
    exit /b
)

mkdir "done" 2>nul

for %%f in (*.mp4) do (
    echo Compressing: %%f
    ffmpeg -i "%%f" -c:v libx264 -crf 24 -preset slower -c:a copy "done\%%f"
)

echo.
echo All done.
pause

Batch convert all MKV into MP4

Converts all MKV files in the same folder as the .bat file into MP4.

@echo off
echo === MKV to MP4 Batch Converter === 
set i = 1

for %%f in (*.mkv) do ffmpeg -i "%%f" -map 0 -vcodec copy -acodec copy "%%~nf.mp4"
pause

Batch convert all MP4 into MKV

I would recommend using MKVToolNix instead for this, but if needed. Converts all MKV files in the same folder as the .bat file into MP4.

@echo off
echo === MP4 to MKV Batch Converter === 
set i = 1

for %%f in (*.mp4) do ffmpeg -i "%%f" -map 0 -vcodec copy -acodec copy "%%~nf.mkv"
pause

Batch convert MP4 to WEBM

Converts all MKV files in the same folder as the .bat file into MP4.

@echo off
echo === MP4 to WEBM Batch Converter === 
set i = 1

for %%f in (*.mp4) do ffmpeg -i "%%f" -c:v libvpx-vp9 -c:a libopus "%%~nf.webm"
pause

Batch convert MOV with Alpha to WEBM and keep transparency

Converts MOV files that have alpha channel to WEBM and keeps the transparency.

@echo off 
echo === MOV to WEBM Batch Converter === 

for %%i in (*.mov)do echo\Encoding: "%%~nxi" "%%~ni.webm"  &&  (
       ffmpeg -i "%%~fi" -c:v libvpx-vp9 -b:v 0 -crf 15  "%%~dpni.webm" -hide_banner -v error -stats
       ) 
pause

Single file commands

Merge SUBS (soft) into VIDEO file

ffmpeg -i VIDEO.EXT -i SUBS.EXT -c copy -c:s mov_text OUTPUT.MP4

Merge VIDEO and AUDIO into one MP4

ffmpeg -i VIDEO.EXT -i AUDIO.EXT -c:v copy -c:a copy OUTPUT.MP4

@echo off
:START
cls
echo === Merge MP4 and M4A ===

set /p video_file=Enter the name of the video file (with extension): 
set /p audio_file=Enter the name of the audio file (with extension): 
set /p output_file=Enter the name of the output file (with extension): 

echo.
echo You entered:
echo Video file : %video_file%
echo Audio file : %audio_file%
echo Output file: %output_file%
echo.

set /p confirm=Is this correct? (Y/N): 
if /I "%confirm%"=="Y" goto PROCESS
if /I "%confirm%"=="N" goto START

echo Invalid choice. Please type Y or N.
pause
goto START

:PROCESS
ffmpeg -i "%video_file%" -i "%audio_file%" -c:v copy -c:a copy "%output_file%"
echo.
echo Done!
pause