我制作了一个 .bat 脚本来为视频添加水印,徽标从右到左慢慢滑过视频。这是我的代码:
set ffmpeg="C:\ffmpeg\ffmpeg.exe"
set ffprobe="C:\ffmpeg\ffprobe.exe"
@echo off
setlocal enableextensions enabledelayedexpansion
for %%A in ("H:\4 - Watermark Process\Before\*.mp4") do (
echo "________________________________________________________________________________________________________________________"
echo _ Filename _: %%A
rem Find videoDuration
for /F "delims=" %%G in ('ffprobe.exe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 "%%A" 2^>^&1') do (
set /A videoDuration=%%G/1
echo _ Video Duration _: !videoDuration!
)
rem Find videoWidth
for /F "delims=" %%I in ('ffprobe -v error -show_entries stream^=width -of csv^=p^=0:s^=x "%%A"') do (
set videoWidth=%%I
echo _ Video Width _: !videoWidth!
)
rem Find videoHeight
for /F "delims=" %%J in ('ffprobe -v error -show_entries stream^=height -of csv^=s^=x:p^=0 "%%A"') do (
set videoHeight=%%J
echo _ Video Height _: !videoHeight!
)
rem Scale logo watermark according to video Width and Height
if !videoHeight! LSS !videoWidth! (
echo "_ videoHeight LESS THAN videoWidth _"
set /A scaleWidth = !videoWidth!/10
ffmpeg -i logo.png -y -v verbose -vf scale=!scaleWidth!:-1 scaled.png
) else (
echo "_ videoHeight GREATER THAN videoWidth _"
set /A scaleWidth = !videoWidth!/4
ffmpeg -i logo.png -y -v verbose -vf scale=!scaleWidth!:-1 scaled.png
)
rem Place logo watermark based on video Duration
if !videoDuration! LSS 10 (
echo "_ videoDuration LESS THAN 10 seconds _"
echo "________________________________________________________________________________________________________________________"
ffmpeg -i "%%A" -i scaled.png -filter_complex "overlay=10:main_h-overlay_h" "H:\4 - Watermark Process\After\%%~nA.mp4"
echo "______________________________________________LESS THAN 10SEC CONVERSION COMPLETE__________________________________________________________________________"
)
if !videoDuration! GEQ 10 (
set /A "videoDurationOneThird=(videoDuration*2)/3"
echo _ videoDuration One Third _: !videoDurationOneThird!
echo "________________________________________________________________________________________________________________________"
ffmpeg -i "%%A" -i scaled.png -filter_complex "[0:v][1:v] overlay='if(gte(t,!videoDurationOneThird!), (main_w-(w+(t-!videoDurationOneThird!)*20)), NAN)':(main_h-overlay_h)/2:enable=between'(t,!videoDurationOneThird!,!videoDuration!)'" "H:\4 - Watermark Process\After\%%~nA.mp4"
)
)
pause 10
问题是我在带有感叹号的视频上收到错误消息:没有这样的文件或目录
我读到启用延迟扩展会删除感叹号,但我需要它才能使脚本正常工作。我怎样才能解决这个问题?
我尝试过的失败解决方案如下:
set ffmpeg="C:\ffmpeg\ffmpeg.exe"
set ffprobe="C:\ffmpeg\ffprobe.exe"
@echo off
setlocal enableextensions disabledelayedexpansion
for %%A in ("H:\4 - Watermark Process\BeforeWide\*.mp4") do (
set FILE=%%~A
set NAME=%%~nA
echo "________________________________________________________________________________________________________________________"
echo _ Filename _: !FILE!
setlocal enabledelayedexpansion
rem Find videoDuration
for /F "delims=" %%G in ('ffprobe.exe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 !FILE! 2^>^&1') do (
set /A videoDuration=%%G/1
echo _ Video Duration _: !videoDuration!
)
rem Find videoWidth
for /F "delims=" %%I in ('ffprobe -v error -show_entries stream^=width -of csv^=p^=0:s^=x !FILE!') do (
set videoWidth=%%I
echo _ Video Width _: !videoWidth!
)
rem Find videoHeight
for /F "delims=" %%J in ('ffprobe -v error -show_entries stream^=height -of csv^=s^=x:p^=0 !FILE!') do (
set videoHeight=%%J
echo _ Video Height _: !videoHeight!
)
rem Scale logo watermark according to video Width and Height
if !videoHeight! LSS !videoWidth! (
echo "_ videoHeight LESS THAN videoWidth _"
set /A scaleWidth = !videoWidth!/10
ffmpeg -i logo.png -y -v verbose -vf scale=!scaleWidth!:-1 scaled.png
) else (
echo "_ videoHeight GREATER THAN videoWidth _"
set /A scaleWidth = !videoWidth!/4
ffmpeg -i logo.png -y -v verbose -vf scale=!scaleWidth!:-1 scaled.png
)
rem Place logo watermark based on video Duration
if !videoDuration! LSS 10 (
echo "_ videoDuration LESS THAN 10 seconds _"
echo "________________________________________________________________________________________________________________________"
ffmpeg -i !FILE! -i scaled.png -filter_complex "overlay=10:main_h-overlay_h" "H:\4 - Watermark Process\After\!NAME!.mp4"
echo "______________________________________________LESS THAN 10SEC CONVERSION COMPLETE__________________________________________________________________________"
)
if !videoDuration! GEQ 10 (
set /A "videoDurationOneThird=(videoDuration*2)/3"
echo _ videoDuration One Third _: !videoDurationOneThird!
echo "________________________________________________________________________________________________________________________"
ffmpeg -i !FILE! -i scaled.png -filter_complex "[0:v][1:v] overlay='if(gte(t,!videoDurationOneThird!), (main_w-(w+(t-!videoDurationOneThird!)*20)), NAN)':(main_h-overlay_h)/2:enable=between'(t,!videoDurationOneThird!,!videoDuration!)'" "H:\4 - Watermark Process\After\!NAME!.mp4"
)
endlocal
)
pause 10