View Full Version : Batch convert AVI to MKV
netmask
18th October 2019, 06:33
I'm sure this has been covered countless times but my searches for a simple straight forward method have been in vain. So is there either a script I can run or a GUI preferable. I have played with MKVToolNix but I always end up with one big file all titles being appended rather than as separate files.... In all I have around 100 avi files that I would like to put in a MKV container. Many thanks.
Tadanobu
18th October 2019, 07:22
While we're at it, I'll join your thread and ask for help too.
In the past, I've been using batch files to append videos (old 2 CD rips) and merge subs. They work fine most of the time but I notice several cases where the subs and/or the audio become a bit out of synch after the process. Any idea why ? Does it comes from the script or the input files ? The same thing has been happening using MKVToolNix.
Also, I think it would be nice to have a thread with a collection of batches to perform various operations.
stax76
18th October 2019, 08:08
You can try staxrip.
sneaker_ger
18th October 2019, 10:06
I have played with MKVToolNix but I always end up with one big file all titles being appended rather than as separate files
It depends on your setting.
"MKVToolNix GUI"->"Preferences (Ctrl+P)"->"Multiplexer"->"When dropping files". There you can set to create new multiplex for each file or ask every time (when using drag&drop). Then you can add 100 files, click "Multiplexer"->"Actions for all tabs"->"Start multiplexing".
Note that this will only change the container, not re-encode to more modern codecs. To do the latter you need a software like the mentioned StaxRip. You didn't say why you want to convert to mkv.
Groucho2004
18th October 2019, 11:01
In all I have around 100 avi files that I would like to put in a MKV container.
Use ffmpeg in a batch file:
for %%i in (*.avi) do (
ffmpeg -fflags +genpts -i "%%i" -acodec copy -vcodec copy "%%~ni.mkv"
)
StainlessS
18th October 2019, 11:38
Groucho2004 thing expanded a bit [no idea what "-fflags +genpts" does but I guess you could try add it (timestamps probably)]
Demo.Bat or Demo.Cmd
REM We DO NOT LIKE SPACES IN FILE NAMES (REM == REMark ie comment)
setlocal
REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"
REM Where to get input file, No terminating Backslash, "." = current directory (ie same as .bat file dir)
set INDIR="."
REM Where to place output file, No terminating Backslash. "." would be same as .bat file : ".\OUT" = OUT folder in same directory as bat file.
set OUTDIR="D:"
REM Below, can add extensionas as eg *.WMV (SPACE separated)
FOR %%A IN (*.Avi *.mp4) DO (
REM ****** Un-REM ONLY one of below lines *******.
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM *********************************************.
)
REM ... Above UN-REM'ed lines :
REM (1) Remux, copy both video and audio (output MKV).
REM (2) UtVideo lossless video, copy audio (output MKV).
REM (3) UtVideo lossless video, PCM audio (output AVI).
Pause
Not all streams can successfully be encapsulated in all containers.
EDIT: I use 3rd one a lot for Avisynth, avoids lots of fussing about with FFMpegSource and LSmashSource, and [EDIT: Lossless] AVI is pretty much always frame accurate.
Groucho2004
18th October 2019, 11:49
no idea what "-fflags +genpts" does but I guess you could try add it (timestamps probably)
It prevents errors such as "Can't write packet with unknown timestamp".
Not all streams can successfully be encapsulated in all containers.True, it's trial and error and/or some googleling (or is it googling? Who knows...).
netmask
1st November 2019, 00:49
It depends on your setting.
"MKVToolNix GUI"->"Preferences (Ctrl+P)"->"Multiplexer"->"When dropping files". There you can set to create new multiplex for each file or ask every time (when using drag&drop). Then you can add 100 files, click "Multiplexer"->"Actions for all tabs"->"Start multiplexing".
Note that this will only change the container, not re-encode to more modern codecs. To do the latter you need a software like the mentioned StaxRip. You didn't say why you want to convert to mkv.
The media player in question accepts MKV and is problematic with avi's. All done now and they all work seamlessly.
Cary Knoop
1st November 2019, 01:32
Is -vcodec and -acodec instead of -c:v -c:a still supported?
StainlessS
1st November 2019, 11:55
Is -vcodec and -acodec instead of -c:v -c:a still supported?
Well -vcodec and -acodec are both used in the bat demo previoulsy posted, and have not ever caused me any problems.
REM ****** Un-REM ONLY one of below lines *******.
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.