This is a simple workflow to convert .mkv into .mp4 files using FFmpeg.
It works with a script you drag and drop your mkv onto.
HOW IT WORKS
The script first attempts a remux by changing its container, so the data remains the exact same inside.
If remuxing fails (in case of codec incompatibility) it instead transcodes the video.
/!\ Transcoding is like re-rendering the video though, so it can add another layer of compression to a pre-existing one.
PREREQUISITES
Make sure FFmpeg is installed (the script will let you know if you don't have it)
To install it easily :
> Press WIN + R
> Type winget install ffmpeg
I didn't include it in the script for safety and clarity purposes, so you still get to do it the way you want.
HOW TO USE THE SCRIPT
> Copypaste the following code in your notepad and save it as a .bat file
> Drag and drop any .mkv file onto it to convert them.
Enjoy!
@echo off
setlocal enabledelayedexpansion
REM ---- Check ffmpeg ----
where ffmpeg >nul 2>&1
if errorlevel 1 (
echo ERROR: ffmpeg not found.
echo Put ffmpeg.exe next to this BAT or add it to PATH.
pause
exit /b
)
REM ---- Output folder ----
set OUTDIR=%~dp0mp4
mkdir "%OUTDIR%" 2>nul
REM ---- Process dragged files ----
:loop
if "%~1"=="" goto done
echo.
echo Processing: %~nx1
ffmpeg -y -i "%~1" -c copy "%OUTDIR%\%~n1.mp4"
if "%ERRORLEVEL%" NEQ "0" (
echo Remux failed, transcoding...
ffmpeg -y -i "%~1" ^
-map 0 ^
-c:v libx264 -preset slow -crf 18 ^
-pix_fmt yuv420p ^
-c:a aac -b:a 192k ^
"%OUTDIR%\%~n1.mp4"
)
if exist "%OUTDIR%\%~n1.mp4" (
echo SUCCESS: %~n1.mp4 created
) else (
echo ERROR: Output file not created
)
shift
goto loop
:done
echo.
echo Finished.
echo Output folder: %OUTDIR%
pause
@echo off
setlocal enabledelayedexpansion
REM ---- Check ffmpeg ----
where ffmpeg >nul 2>&1
if errorlevel 1 (
echo ERROR: ffmpeg not found.
echo Put ffmpeg.exe next to this BAT or add it to PATH.
pause
exit /b
)
REM ---- Output folder ----
set OUTDIR=%~dp0mp4
mkdir "%OUTDIR%" 2>nul
REM ---- Process dragged files ----
:loop
if "%~1"=="" goto done
echo.
echo Processing: %~nx1
ffmpeg -y -i "%~1" -c copy "%OUTDIR%\%~n1.mp4"
if "%ERRORLEVEL%" NEQ "0" (
echo Remux failed, transcoding...
ffmpeg -y -i "%~1" ^
-map 0 ^
-c:v libx264 -preset slow -crf 18 ^
-pix_fmt yuv420p ^
-c:a aac -b:a 192k ^
"%OUTDIR%\%~n1.mp4"
)
if exist "%OUTDIR%\%~n1.mp4" (
echo SUCCESS: %~n1.mp4 created
) else (
echo ERROR: Output file not created
)
shift
goto loop
:done
echo.
echo Finished.
echo Output folder: %OUTDIR%
pause
@echo off
setlocal enabledelayedexpansion
REM ---- Check ffmpeg ----
where ffmpeg >nul 2>&1
if errorlevel 1 (
echo ERROR: ffmpeg not found.
echo Put ffmpeg.exe next to this BAT or add it to PATH.
pause
exit /b
)
REM ---- Output folder ----
set OUTDIR=%~dp0mp4
mkdir "%OUTDIR%" 2>nul
REM ---- Process dragged files ----
:loop
if "%~1"=="" goto done
echo.
echo Processing: %~nx1
ffmpeg -y -i "%~1" -c copy "%OUTDIR%\%~n1.mp4"
if "%ERRORLEVEL%" NEQ "0" (
echo Remux failed, transcoding...
ffmpeg -y -i "%~1" ^
-map 0 ^
-c:v libx264 -preset slow -crf 18 ^
-pix_fmt yuv420p ^
-c:a aac -b:a 192k ^
"%OUTDIR%\%~n1.mp4"
)
if exist "%OUTDIR%\%~n1.mp4" (
echo SUCCESS: %~n1.mp4 created
) else (
echo ERROR: Output file not created
)
shift
goto loop
:done
echo.
echo Finished.
echo Output folder: %OUTDIR%
pause
@echo off
setlocal enabledelayedexpansion
REM ---- Check ffmpeg ----
where ffmpeg >nul 2>&1
if errorlevel 1 (
echo ERROR: ffmpeg not found.
echo Put ffmpeg.exe next to this BAT or add it to PATH.
pause
exit /b
)
REM ---- Output folder ----
set OUTDIR=%~dp0mp4
mkdir "%OUTDIR%" 2>nul
REM ---- Process dragged files ----
:loop
if "%~1"=="" goto done
echo.
echo Processing: %~nx1
ffmpeg -y -i "%~1" -c copy "%OUTDIR%\%~n1.mp4"
if "%ERRORLEVEL%" NEQ "0" (
echo Remux failed, transcoding...
ffmpeg -y -i "%~1" ^
-map 0 ^
-c:v libx264 -preset slow -crf 18 ^
-pix_fmt yuv420p ^
-c:a aac -b:a 192k ^
"%OUTDIR%\%~n1.mp4"
)
if exist "%OUTDIR%\%~n1.mp4" (
echo SUCCESS: %~n1.mp4 created
) else (
echo ERROR: Output file not created
)
shift
goto loop
:done
echo.
echo Finished.
echo Output folder: %OUTDIR%
pause