I’m using ffmpeg to convert .avi file into a .png image sequence. This one works just fine:
@ ECHO OFF
FOR %%A IN (*.avi) DO CALL :avi2png "%%A"
:avi2png
ffmpeg.exe -y -i %* -sameq -f image2 -c:v png "%%03d.png"
ECHO.
GOTO :EOF
But I want the script to extract the name without the extension from .avi file that is currently being processed. This is what the image sequence should look like: currentavi001.png, currentavi002.png etc. The script I came up with isn’t working:
@ ECHO OFF
FOR %%A IN (*.avi) DO CALL :avi2png "%%A"
:avi2png
ffmpeg.exe -y -i %* -sameq -f image2 -c:v png "%%~nA%%03d.png"
ECHO.
GOTO :EOF
I’ve tried both %~nA and %%~nA, but to no avail. The script returns this:
Couldn't open file :
av_interleaved_write_frame(): Input/output error.
I’m a complete layman and would welcome every bit of help.
You can’t refer to the
%%Avariable in :avi2png. Try this:If you have one file in the current directory named
my_movie.aviffmpegwill create the pngmy_movie001.png.When you
calla label from aforloop, you can no longer use your originalforloop variable (in this case %%A), instead:labelis treated as a separate batch file and all variables on the line after the:labelare treated as switches passed to a batch file.So this…
…works with this…
…to produce output like this:
Just as if it were a stand-alone batch file.
Oh, also
%%Aand the like are never referred to by%%A%%(or%A%, a totally different variable). If you do that (and%%A==Hello) the result would beHello%, and likely eat a character somewhere in your code, resulting in bizarre errors.