DOS batch file and FFMPEG question

Questions on how we spend our money and our time - consumer goods and services, home and vehicle, leisure and recreational activities
Post Reply
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

DOS batch file and FFMPEG question

Post by Tamales »

I'm trying to run a batch file from a directory that has multiple file pairs of the form video1.avi & video1.wav; video2.avi & video2.wav; etc. The avi doesn't have embedded audio (audio was created separately in a PCM wav file of the same name).

I have the ffmpeg executable (version 4.2.1, which is the latest) in the same directory as the avi/wav file pairs. The video isn't being changed but the audio is being transcoded to aac, and the mkv container, from what I've read, is a good general-purpose container that accepts pretty much anything.

The desire is to multiplex all the avi/wav pairs into a single combined mkv file, and to do that for all the pairs in this directory, and write the resulting mkv file into a subdirectory called muxed.

The batch file is one line:

for %%a in ("*.avi") do ffmpeg-4-2-1 -i "%%~na.avi" -i "%%~na.wav" –c:v copy –c:a aac –b:a 256k "muxed\%%~na.mkv"

I'm not sure if my problem is with FFMPEG syntax or batch file syntax. Or both.
When I run the batch file, the error that ffmpeg gives isn't clear but it seems to have to do with the "%%~na...." stuff in double quote.

Any suggestions?
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

Oh and a related question on running FFMPEG. Do you HAVE to edit your PATH variable to include some directory in the FFMPEG package (the "bin" subdirectory?) , or is the FFMPEG.exe file completely portable and you can drop it into any subdirectory where you have video/audio files to process, without editing the environment variables (running under windows 10)?
FreemanB
Posts: 374
Joined: Thu May 22, 2014 5:55 am

Re: DOS batch file and FFMPEG question

Post by FreemanB »

Can you tell us what the error message is? No idea if I can help, but that would be the first thing I'd look at.
GrowthSeeker
Posts: 1071
Joined: Tue May 15, 2018 10:14 pm

Re: DOS batch file and FFMPEG question

Post by GrowthSeeker »

I don't know, but you'll probably have better luck on a more techy type site.

https://superuser.com/questions/277642/ ... -in-ffmpeg
Just because you're paranoid doesn't mean they're NOT out to get you.
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

The ffmpeg output contains garbled characters right before it terminates, but it starts out OK, interpreting both the video and audio file details correctly. Then it outputs:
Unable to find suitable output format for '*****c:v' *****c:v invalid argument
(where the 5 asterisks are 5 garbled characters. The single quotes are in the original)
doneat53
Posts: 123
Joined: Tue Jul 04, 2017 1:23 pm

Re: DOS batch file and FFMPEG question

Post by doneat53 »

start by running the ffmpeg commands by command line. once that works then batch it. Add less flags until it works and then determine which flag is messing you up.

Could be an incompatability with your ffmpeg version.
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

At this point I think it's more about the batch file syntax, since I ran ffmpeg with just a single specific file pair, rather than the FOR loop in the batch file with variables, and it worked fine. Essentially like this:
ffmpeg -i test1.avi -i test1.wav –c:v copy –c:a aac –b:a 256k “muxed\output.mkv”
and that ran OK and the mkv file plays fine. But I have tons of these conversions, so I want to figure out how to do batch conversions.
Not many online discussions of batch files and ffmpeg, but this one has a similar example:
https://forum.videohelp.com/threads/356 ... ith-ffmpeg
the one titled: Multiplex *.avi and *.wav files with same name to avi
is the closest to what I'm trying to do.
User avatar
walkabout
Posts: 891
Joined: Wed May 25, 2011 8:28 am
Location: Northern Alabama

Re: DOS batch file and FFMPEG question

Post by walkabout »

You might consider using powershell. I find that syntax much more comprehensible than bat file syntax.
GrowthSeeker
Posts: 1071
Joined: Tue May 15, 2018 10:14 pm

Re: DOS batch file and FFMPEG question

Post by GrowthSeeker »

You might check out powershell, which can be substituted in place of the dos prompt. It might be easier to do with a powershell script than a batch file.
Just because you're paranoid doesn't mean they're NOT out to get you.
Makefile
Posts: 2657
Joined: Fri Apr 22, 2016 11:03 pm

Re: DOS batch file and FFMPEG question

Post by Makefile »

What if you replace the ffmpeg-4-2-1 command with echo
Then go through the output and see if you can copy and paste some of the command lines it generates and see if you can get the garbled error message with a single command.

Are you 100% sure that all - are plain hyphens and all " are plain quotes--not dashes or curly quotes that a word processor might substitute. I ask because one of your replies has curly quotes. In fact, the -c in your original post is not a plain hyphen c.
rich126
Posts: 4475
Joined: Thu Mar 01, 2018 3:56 pm

Re: DOS batch file and FFMPEG question

Post by rich126 »

Tamales wrote: Fri Jan 03, 2020 10:45 am I'm trying to run a batch file from a directory that has multiple file pairs of the form video1.avi & video1.wav; video2.avi & video2.wav; etc. The avi doesn't have embedded audio (audio was created separately in a PCM wav file of the same name).

I have the ffmpeg executable (version 4.2.1, which is the latest) in the same directory as the avi/wav file pairs. The video isn't being changed but the audio is being transcoded to aac, and the mkv container, from what I've read, is a good general-purpose container that accepts pretty much anything.

The desire is to multiplex all the avi/wav pairs into a single combined mkv file, and to do that for all the pairs in this directory, and write the resulting mkv file into a subdirectory called muxed.

The batch file is one line:

for %%a in ("*.avi") do ffmpeg-4-2-1 -i "%%~na.avi" -i "%%~na.wav" –c:v copy –c:a aac –b:a 256k "muxed\%%~na.mkv"

I'm not sure if my problem is with FFMPEG syntax or batch file syntax. Or both.
When I run the batch file, the error that ffmpeg gives isn't clear but it seems to have to do with the "%%~na...." stuff in double quote.

Any suggestions?
Been a while since doing batch files. As others said, I would move to powershell for the long term. Back to the original question.

You are doing a for loop and looking for files with a "avi" extension then when each one is found you are executing the ffmpeg command.

The %%~na gives you the filename without the file extension (i.e., if the filename was "bob.txt", it gives you "bob").

My first suggestion would be to remove the double quotes from the first two items after the -i. -i %%~na.avi -i %%~na.wav and see what happens. With the quotes you are passing "filename.wav" (the quotes are included with the filename) to ffmpeg and maybe the application doesn't want to see the quotes. You might also want to remove them from around the mux portion as well.
----------------------------- | If you think something is important and it doesn't involve the health of someone, think again. Life goes too fast, enjoy it and be nice.
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

Makefile wrote: Fri Jan 03, 2020 12:44 pm What if you replace the ffmpeg-4-2-1 command with echo
Then go through the output and see if you can copy and paste some of the command lines it generates and see if you can get the garbled error message with a single command.

Are you 100% sure that all - are plain hyphens and all " are plain quotes--not dashes or curly quotes that a word processor might substitute. I ask because one of your replies has curly quotes. In fact, the -c in your original post is not a plain hyphen c.
This is an interesting thought since the hyphen before the c in -c:v seems to trigger something in the error message. Can you elaborate on what you mean by a plain hyphen? I just used the key right of the number 0 on a standard keypad. Is the hyphen in the numeric keypad a differently-coded hyphen?
Makefile
Posts: 2657
Joined: Fri Apr 22, 2016 11:03 pm

Re: DOS batch file and FFMPEG question

Post by Makefile »

Tamales wrote: Fri Jan 03, 2020 12:51 pm This is an interesting thought since the hyphen before the c in -c:v seems to trigger something in the error message. Can you elaborate on what you mean by a plain hyphen? I just used the key right of the number 0 on a standard keypad. Is the hyphen in the numeric keypad a differently-coded hyphen?
You want a plain old hyphen, ASCII code 45. Either key will do. As long as you re-key the batch file in a plain text editor, including Notepad, that is what you will get.

It is likely you either edited the batch file in a word processor that replaced the hyphen with something else, or copied and pasted example code from someone who did. If you open the batch file in a hex editor you should see the difference between the two hyphens (or scroll up to your original post and see the -i is visibly different than -c).
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

Makefile wrote: Fri Jan 03, 2020 1:01 pm
Tamales wrote: Fri Jan 03, 2020 12:51 pm This is an interesting thought since the hyphen before the c in -c:v seems to trigger something in the error message. Can you elaborate on what you mean by a plain hyphen? I just used the key right of the number 0 on a standard keypad. Is the hyphen in the numeric keypad a differently-coded hyphen?
You want a plain old hyphen, ASCII code 45. Either key will do. As long as you re-key the batch file in a plain text editor, including Notepad, that is what you will get.

It is likely you either edited the batch file in a word processor that replaced the hyphen with something else, or copied and pasted example code from someone who did. If you open the batch file in a hex editor you should see the difference between the two hyphens (or scroll up to your original post and see the -i is visibly different than -c).
Thank you! That worked. I opened the batch file in notepad, deleted the (alleged) hyphens and replaced them with hyphens from within notepad, and it all works as planned! And you're right, I did create the original in a Word doc and copied it over to notepad before saving to a bat file.
All these years and I've never run across that odd problem before. Anyway, thanks again.
Topic Author
Tamales
Posts: 1644
Joined: Sat Jul 05, 2014 10:47 am

Re: DOS batch file and FFMPEG question

Post by Tamales »

Makefile wrote: Fri Jan 03, 2020 1:01 pm [...] If you open the batch file in a hex editor you should see the difference between the two hyphens (or scroll up to your original post and see the -i is visibly different than -c).
You have some eagle eyes, and/or a really crisp monitor. I had to zoom way in from my browser to be able to see that one hyphen is thicker and shorter than the other.
Post Reply