0

I am using the code below to automatically watermark videos in a folder:

for %%a in ("C:\Users\Work\Desktop\Redo\*.mp4") do (
   for /F "delims=" %%I in ('ffprobe -v quiet -show_entries stream^=width -of csv^=p^=0:s^=x %%a') do set "codec=%%I"
   ffmpeg -i logo.png -y -v quiet -vf scale=!codec!*0.25:-1 scaled.png
   ffmpeg -i "%%a" -vf "movie=scaled.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h [out]" "C:\Users\Work\Desktop\Redo Done\%%~na.mp4"
)

Some of the videos fail to watermark and give the similar error below:

C:\Users\Work\Desktop\Redo\Arcade_h-overlay_h [out]: No such file or directory

I found out all videos with exclamation points (!) in the name do this.

How can I get these videos to watermark with an exclamation point in the title?

user5947524
  • 41
  • 2
  • 8

1 Answers1

1
setlocal disabledelayedexpansion
for %%a in ("C:\Users\Work\Desktop\Redo\*.mp4") do (
    for /F "delims=" %%I in ('
        ffprobe -v quiet -show_entries stream^=width -of csv^=p^=0:s^=x "%%a"
    ') do (
        ffmpeg -i logo.png -y -v quiet -vf scale=%%I*0.25:-1 scaled.png
        ffmpeg -i "%%a" -vf "movie=scaled.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h [out]" "C:\Users\Work\Desktop\Redo Done\%%~na.mp4"
    )
)

Exclamation points will be lost when expanding the for replaceable parameters when delayed expansion is active. As you are only using delayed expansion to retrieve the codec value, don't do it, you don't need it. The value inside the variable is already available as a for replaceable parameter, so, simply place the ffmpeg commands inside the second for and directly use the retrieved value.

MC ND
  • 69,615
  • 8
  • 84
  • 126