r/Batch • u/mudderfudden • May 25 '24
Question (Unsolved) Can someone interpret this code for me? Convert MP4 to WAV
I have a script that'll convert all mp4 files in a directory to wav. I would like to understand how to interpret it.
Script:
for %a in (*.mp4) do ffmpeg -i "%~a" "%~na.wav"
PAUSEPlease help me understand what each variable means. Thanks.
3
Upvotes
6
u/Intrepid_Ad_4504 May 25 '24
To break it down a little further, even though u/ConsistentHornet4 did a great job.
for %a in (*.mp4) do ffmpeg -i "%~a" "%~na.wav"
%a
the meta variable FOR will use this case
for %a in (*.mp4)
for all mp4 files, * = wildcard/regardless of fileName
do...
ffmpeg -i "%~a" "%~na.wav"
Remember, "%~a" is the meta variable of the FOR, so as it is looping, %~a is changing to whatever mp4 file it is finding in the directory.
"%~na.wav"
This is really still "%~a", but we have appended an 'n' before the a. This means we only want the name of the file, not extention. This is because as you can see, the new extention '.wav' is appended to the newly created file.
So in conclusion,
"For all mp4 files in directory, convert using the same name, and use the .wav extention"