1

I'm trying to figure out a batch script (windows based) which will allow me to multiplex some .m2v and .wav files that exist in a load of sub-directories (within one single main directory). They need to be restriped and transcoded as well, the output files need to be MXF and end up in another folder. I'm new to batch scripts, not so new to FFMPEG commands. I've not been able to find any batch scripts so far that allow for multiple files to be used, only ones that work to convert a single file.

After much searching the closest thing I've seen is this, which I've tried with no success. Oddly, one time it did produce a .mxf file, albeit 0KB, but every time since I get nothing.

for %%a in (".m2v") do ffmpeg -i "%%~na.wav" -i "%%~na.m2v" -acodec copy -vcodec copy "newfiles\%%~na.mxf". 

I'm not sure what is meant to go in the parenthesis where I have (".m2v").

what does that represent?

  • Please note that Super User is not a script writing service. If you tell us what you have tried so far (including any scripts you are using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?. – DavidPostill Jul 5 '16 at 19:53
  • After much searching the closest thing I've seen is this, which I've tried with no success. Oddly, one time it did produce a .mxf file, albeit 0KB, but every time since I get nothing. for %%a in (".m2v") do ffmpeg -i "%%~na.wav" -i "%%~na.m2v" -acodec copy -vcodec copy "newfiles\%%~na.mxf". I'm not sure what is meant to go in the parenthesis where I have (".m2v"). what does that represent? – DMtd Jul 6 '16 at 8:57
1

I'm not sure what is meant to go in the parenthesis where I have (".m2v").

what does that represent?

for %%a in (".m2v") do ffmpeg -i "%%~na.wav" -i "%%~na.m2v" -acodec copy -vcodec copy "newfiles\%%~na.mxf"

The value (".m2v") represents a set of files to process.

In your command there are no files to process since:

  • .m2v is only an extension and we can assume that it should be something like filename.m2v
  • You really need a wildcard expression here (see below for how to do this).
  • Your files are in sub-directories.

Use the following batch file (in the single main directory):

@echo off
setlocal
for /f "usebackq" %%a in (`dir /b /s *.m2v`) do (
  echo ffmpeg -i "%%~dpna.wav" -i "%%~dpna.m2v" -acodec copy -vcodec copy "newfiles\%%~na.mxf
  )
endlocal

Notes:

  • Remove the echo from the ffmpeg command when you are happy with what the batch file is going to do.

  • dir /b /s *.m2v is used to produce a list of files to process.

    The /b option gives the filenames only (we don't want the headers, summary or other details)

    The /s option allows dir to process sub-directories.

  • for /f is used to process the list of files.

  • %%~dpna is used to get the fully qualified filename without the extension.


Further Reading

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.