经常用 ffmepg 批量视频截图,网上都有现成拿来直接用,但偶尔想要带时间戳的截图方便找素材位置,之前在网上找了很久未果,最近终于找到一个相近的,在 powershell 测试是能套娃 ffprobe 执行
原版
.\ffmpeg.exe -i ".\video.mp4" -vf "fps=1/'$(.\ffprobe.exe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 .\video.mp4)'*5,drawtext=fontfile=C\\:/Windows/Fonts/Arial.ttf:fontsize=45:fontcolor=yellow:box=1:[email protected]:x=(W-tw)/2:y=H-th-10:text='%{pts\:hms}'" -fps_mode vfr thumb_%02d.jpg
但放到 bat 批处理就报错
cd /D "%~dp0"
ffmpeg\ffmpeg.exe -i "%~1" -vf "fps=1/'$(ffmpeg\ffprobe.exe -v error -show_entries format=duration -of default=noprint_wrappers=1 "%~1")'*12,drawtext=fontfile=C\\:/Windows/Fonts/Arial.ttf:fontsize=45:fontcolor=yellow:box=1:[email protected]:x=(W-tw)/2:y=H-th-10:text='%{pts\:hms}'" -fps_mode cfr "%~dpn1"_%%04d.jpg
报错信息
[fps @ 000001ec5a6ccec0] [Eval @ 0000003bbc1fdc30] Undefined constant or missing '(' in 'UsersuserDownloadsvideo.mp4)*12'
[fps @ 000001ec5a6ccec0] Unable to parse option value "UsersuserDownloadsvideo.mp4)*12"
[fps @ 000001ec5a6ccec0] Error setting option start_time to value UsersuserDownloadsvideo.mp4)*12.
[Parsed_fps_0 @ 000001ec5626ef00] Error applying options to the filter.
[AVFilterGraph @ 000001ec5984ac00] Error initializing filter 'fps' with args '1/$(ffmpeg\ffprobe.exe -v error -show_entries format=duration -of default=noprint_wrappers=1 d:\Users\user\Downloads\video.mp4)*12'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!
1
ysc3839 2022-11-03 17:30:31 +08:00
$() 这是执行命令然后读取 stdout 输出吧,cmd 要实现这个操作很麻烦的,得用 for 。建议放弃 cmd 。
|
2
ch2 2022-11-03 18:57:20 +08:00
用 ps1 吧
|
3
wizardyhnr 2022-11-04 04:16:53 +08:00
ffprobe 单独写出来赋变量呢,一定要单行挑战么?
以前写的 cmd 下探测分辨率作为下一步参数。大致就是把输入写入文件,再读回来,bash 下不用这么麻烦。 ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "%~1" > res.txt set /p res=<res.txt rem 输出分辨率模式是 1280,720, 替换成 1280:720 set res=%res:,=:% |
4
damnsoul OP @wizardyhnr 赋变量有试过,但我没学过语言,网上现学现用,有限的知识改不出来😓
|