Command works if called in a subroutine, causes error in For loop?

Microsoft Windows
Post Reply
Rekrul
Posts: 8
Joined: 2021-Aug-15, 11:29 pm

Command works if called in a subroutine, causes error in For loop?

Post by Rekrul »

I'm trying to convert some video files to a slower framerate. I have all the programs and commands needed to do this, so I figured I'd make a script to batch process them. If I put the commands inside a For loop, one of them immediately causes an error. However if I move all the commands to a separate routine and Call it, they work fine. Can someone please explain why?

This does not work;

Code: Select all

for %%F in (*.mkv) do (

mkvextract tracks %%F 0:video.264
ffmpeg -i %%F audio.ac3
BeSweet -core( -input "audio.ac3" -output "audio-new.ac3" ) -azid( ) -ota( -r 25000 23976 ) -bsn( -exe aften.exe )
mkvmerge.exe" --default-duration 0:23.976fps --fix-bitstream-timing-information 0 video.264 audio-new.ac3 -o %%~nF-new.mkv
del video.264 audio.ac3 audio-new.ac3
)
When run, it immediately says that "-azid was unexpected at this time".

This works;

Code: Select all

for %%F in (*.mkv) do (

set Name=%%~nF
call :Process
)
goto End

:Process
mkvextract tracks %Name%.mkv 0:video.264
ffmpeg -i %Name%.mkv audio.ac3
BeSweet -core( -input "audio.ac3" -output "audio-new.ac3" ) -azid( ) -ota( -r 25000 23976 ) -bsn( -exe aften.exe )
mkvmerge.exe" --default-duration 0:23.976fps --fix-bitstream-timing-information 0 video.264 audio-new.ac3 -o %Name%-new.mkv
del video.264 audio.ac3 audio-new.ac3
exit /b

:End
It's the exact same code, just moved to a subroutine. Why does it work there and not in the For loop?
OJBakker
Posts: 1
Joined: 2021-Jul-29, 7:06 am

Re: Command works if called in a subroutine, causes error in For loop?

Post by OJBakker »

The closing parenthesis ')' before '-azid( )' ends the for-parenthesized command block, then the next command becomes -azid and this is not a valid command. You need to escape the () inside the for command block to avoid this. Change '(' to '^(' and ')' to '^)' except for the parenthesis of the for-command itself.
Rekrul
Posts: 8
Joined: 2021-Aug-15, 11:29 pm

Re: Command works if called in a subroutine, causes error in For loop?

Post by Rekrul »

OJBakker wrote: 2022-Mar-23, 10:46 am The closing parenthesis ')' before '-azid( )' ends the for-parenthesized command block, then the next command becomes -azid and this is not a valid command. You need to escape the () inside the for command block to avoid this. Change '(' to '^(' and ')' to '^)' except for the parenthesis of the for-command itself.
Ah, that makes sense. I didn't even think of that.

Thank you for the explanation. :)
Post Reply