@rem videodir webm -> mp4
@rem audio acc video h264 overwrite optional
set /p videodir="directory>>> "
echo %videodir%
FOR %%i IN (%videodir%) DO %%~di
cd %videodir%
pause
set /p option="turn on overwrite? [y/n]>>> "
echo %option%
pause
IF %option%==y (
FOR /R %videodir% %%i IN (*.webm) DO ( ffmpeg -i "%%i" -y -c:a aac -c:v libx264 "%videodir%\mp4\%%~ni.mp4" )
) IF %option%==n (
FOR /R %videodir% %%i IN (*.webm) DO ( ffmpeg -i "%%i" -n -c:a aac -c:v libx264 "%videodir%\mp4\%%~ni.mp4" )
) ELSE (
echo "invaild value" )
pause
If
statement keeps making error. please help me sir.
I tried to convert both D:\school.webm
C:\school3.webm
file into mp4, but whether i turn on or off overwrite option, it just keeps raising error.
CodePudding user response:
) IF %option%==n (
should be
) else IF %option%==n (
Additionally, better syntax is if /i "%option%"=="y"
which provides some protection against an entry like y hello
and /i
allows a case-insensitive match.
It would also be a good idea to use the search
facility to find out about choice
and how to use it.
CodePudding user response:
The if
statements parenthesized blocks are an overkill, you have a single command so no need to enclose them in parenthesis, in fact no need for else
either.
To directly fix you error, simply put IF %option%==n (
on a new line.. that's it.
I'll however encourage you to use choice
for these... choice like scripts, that what it is built for:
@echo off
rem videodir webm -> mp4
rem audio acc video h264 overwrite optional
set /p videodir="directory>>> "
pushd "%videodir%">nul 2>&1 || (echo no such dir "%videodir%" & exit /b 1)
choice /M "Overwrite?"
if %errorlevel% equ 1 set "opt=y"
if %errorlevel% equ 2 set "opt=n"
for /R %videodir% %%i in (*.webm) do ffmpeg -i "%%i" -%opt% -c:a aac -c:v libx264 "%videodir%\mp4\%%~ni.mp4"
popd