This batch file isn't working and I know the ffmpeg commands work when the command is on its own.
I am using a WAV file that's exactly the length of the video (it was extracted from the video I am trying to add it back to).
The NOAUDIO and NOVIDEO labels work properly if I delete the wav and/or video file from the folder where ffmpeg.exe and the batch file are.
When the batch file is run with a wav audio and mp4 video file there, it just flashes up a command window. I tried putting pause after every single command but, still no joy.
Is there a mistake here somewhere?
Cheers folks...
:: --------------------
::
:: This will put any included WAV file with any included
:: video file, assuming the video file type exists:
::
:: - AVI
:: - MKV
:: - MP4
:: - WEBM
::
:: --------------------
@echo off
title Replace Video Audio with WAV
color 0f
:: --------------------
if not exist *.wav goto NOAUDIO
if not exist *.avi if not exist *.mkv if not exist *.mp4 if not exist *.webm goto NOVIDEO
:: --------------------
if exist *.avi goto AVIFILE
if exist *.mkv goto MKVFILE
if exist *.mp4 goto MP4FILE
if exist *.webm goto WEBMFILE
:: --------------------
For %%a IN ("*.wav") DO Set "FILEWAV=%%~na"
:: --------------------
:AVIFILE
For %%a IN ("*.avi") DO Set "FILEAVI=%%~na"
start /wait ffmpeg.exe -i "%FILEAVI%.avi" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEAVI%-NEW.mp4"
goto FINISHED
:MP4FILE
For %%a IN ("*.mp4") DO Set "FILEMP4=%%~na"
start /wait ffmpeg.exe -i "%FILEMP4%.mp4" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEMP4%-NEW.mp4"
goto FINISHED
:WEBMFILE
For %%a IN ("*.webm") DO Set "FILEWEBM=%%~na"
start /wait ffmpeg.exe -i "%FILEWEBM%.webm" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEWEBM%-NEW.mp4"
goto FINISHED
:MKVFILE
For %%a IN ("*.mkv") DO Set "FILEMKV=%%~na"
start /wait ffmpeg.exe -i "%FILEMKV%.mkv" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEMKV%-NEW.mp4"
goto FINISHED
:: --------------------
:NOAUDIO
cls
echo.
echo.
echo There is no audio to put with the video!
echo.
echo Exiting...
timeout 6 >nul
goto FINISHED
:: --------------------
:NOVIDEO
cls
echo.
echo.
echo There is no video to put audio with!
echo.
echo Exiting...
timeout 6 >nul
goto FINISHED
:: --------------------
:FINISHED
exit
:: --------------------
I just tested this and it does work, using the exact same commands as in the above batch file just with all the labels removed...
For %%a IN ("*.wav") DO Set FILEWAV=%%~na
:MP4FILE
For %%a IN ("*.mp4") DO Set FILEMP4=%%~na
start /wait ffmpeg.exe -i "%FILEMP4%.mp4" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEMP4%-NEW.mp4"
goto FINISHED
:FINISHED
exit
So I know the reason it's not working is something to do with the order the batch file runs. It's odd because I have another batch file just like it for extracting the WAV in the first place and that does work, with labels set out just like the first batch file above. Perplexing.
If I reduce it to just this, it works...
For %%a IN ("*.wav") DO Set FILEWAV=%%~na
For %%a IN ("*.avi") DO Set FILEAVI=%%~na
start /wait ffmpeg.exe -i "%FILEAVI%.avi" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEAVI%-NEW.mp4"
For %%a IN ("*.mp4") DO Set FILEMP4=%%~na
start /wait ffmpeg.exe -i "%FILEMP4%.mp4" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEMP4%-NEW.mp4"
For %%a IN ("*.webm") DO Set FILEWEBM=%%~na
start /wait ffmpeg.exe -i "%FILEWEBM%.webm" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEWEBM%-NEW.mp4"
For %%a IN ("*.mkv") DO Set FILEMKV=%%~na
start /wait ffmpeg.exe -i "%FILEMKV%.mkv" -i "%FILEWAV%.wav" -c:v copy -map 0:v:0 -map 1:a:0 "%FILEMKV%-NEW.mp4"
exit