windowsbatch-fileffmpeg

Simple batch script for merging video and audio with ffmpeg using two wildcards


as the title says, im trying to mass-merge videos and audios with the same name together in ffmpeg

I tried

for %%A in (*.adx) do ( for %%B in (*.m2v) do ( ffmpeg -i %%A -i %%B %%B.mp4 ) )

but while it does change the video it works on, the audio remains the same. For example, if i have A, B and C in .adx, and A, B and C in .m2v, the result will be that all 3 videos (A, B and C) use the audio A.


Solution

  • …for %%B in (%%~nA.m2v)…

    Your code executes ffmpeg for each %%A for each %%B, so the result is the either the last %%B (if ffmpeg auto-overwrites the destination file) or the first %%B (if ffmpeg skips if the destination file exists).

    The modification will execute ffmpeg only if the name part of the second file matches the name part of the first.

    A simpler way would be

    for %%A in (*.adx) do ( ffmpeg -i %%A -i %%~nA.m2v %%~nA.mp4 )