0

Hello I am trying to use a .bat file to watermark videos I upload to my website. I want the watermark to start 2/3 the way through the video. I've written the code below to do it:

set ffmpeg="C:\ffmpeg\bin\ffmpeg.exe"
set ffprobe="C:\ffmpeg\bin\ffprobe.exe"

setlocal disabledelayedexpansion
for %%a in ("H:\4 - Watermark Process\Before\*.mp4") do (
    for /F "delims=" %%I in ('ffprobe -v quiet -show_entries format^=duration stream^=width -of csv^=p^=0:s^=x "%%a"') do set "duration=%%I"
    echo Duration is: %duration%
    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:enable=gte(t\,duration*2/3) [out]" "H:\4 - Watermark Process\After\%%~na.mp4"
    )
)

pause 10

The problem is I get a few errors

The first is the duration has no output when I use echo to see if it is working I get:

echo Duration is:

And I get other errors in my overlay code

Error

  • 1
    Your duration issue is the most common issue in this particular area of this site, it's a delayed expansion issue. You cannot both define and use a variable within the same code block _(`for`)_. – Compo Oct 07 '20 at 21:10
  • There is an orphaned `do (` in your code, which needs to be removed! Anyway, if the inner loop `for /F %%I` only runs once, just move the whole `ffmpeg` stuff into it and directly use `%%I` instead of assigning a variable `duration`, so you do not have to think of anything like delayed expansion… – aschipfl Oct 08 '20 at 07:59

0 Answers0