batch-fileffmpegbatch-processingmp4mkv

Convert multiple files of multiple format to mkv


I use this code to convert all mp4 files in a folder to mkv

for %f IN (*.mp4) DO ffmpeg -i "%f" -c copy -strict -2 "%~nf.mkv"

However I'm looking for a way to convert .mp4 as well as .ts (telesync) files to mkv in one go. Right now I have to do it separately. Any help would be appreciated.

Thanks.


Solution

  • The help (for /?) isn't very clear about the syntax. It simply states:

    file-set is a one or more file names.
    

    SS64 is a bit more explicit, but also completely holds back about the possibility of using wildcards:

    Filenameset    A set of one or more files, enclosed in parentheses (file1,file2)
    

    Actually, for accepts several file masks (like dir):

    for %f IN (*.mp4 *.ts "I also want this file.wmv") DO ...
    

    To correctly process file names/masks with spaces or other special characters, quote them.
    (whether you separate them with a space or a comma is up to you)