windows 如何使用ffprobe & batch返回视频/图像的宽度和高度

kiz8lqtg  于 12个月前  发布在  Windows
关注(0)|答案(4)|浏览(164)

我需要使用ffprobe获取图像文件的宽度和高度,并需要使用批处理(Windows)将其存储在变量中,以便稍后使用这些值。
我试过这么做,

@echo off
for /f "tokens=1-2" %%i in ('ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width,height %1') do set W=%%i & set H=%%j
echo %W%
echo %H%

但未能执行与

Argument '_' provided as input filename, but 's' was already specified.

p.s.我也用类似的方法试过imagemagick identify,但是identify在返回GIF文件的高度时似乎有一个bug

o7jaxewo

o7jaxewo1#

我已经设法调整你的脚本,它的工作,你可以尝试这种方式:

@echo off
ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width %1 >> width.txt
ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height %1 >> height.txt
FOR /f "tokens=5 delims==_" %%i in (width.txt) do @set width=%%i
FOR /f "tokens=5 delims==_" %%i in (height.txt) do @set height=%%i
echo width=%width%
echo height=%height%
del width.txt && del height.txt
pause
chhqkbe1

chhqkbe12#

我认为答案是过度杀戮。只有一个ffprobe命令,没有写入文件,没有控制台消息:

for /f "delims=" %%a in ('ffprobe -hide_banner -show_streams %1 2^>nul ^| findstr "^width= ^height="') do set "mypicture_%%a"

最后是环境变量mypicture_widthmypicture_height。您可以通过以下方式进行检查:

C:\>set mypicture_
mypicture_height=480
mypicture_width=640

如果你的图片大小是640x480,当然。

e4yzc0pl

e4yzc0pl3#

只需转义=字符^并拆分以检索w和h(可能有一种方法可以同时检索它们,但我不知道)。

@echo off

for /f "tokens=5 delims==_" %%i in ('ffprobe -v error -of flat^=s^=_ -select_streams v:0 -show_entries stream^=width %1') do set W=%%i
echo %W%

for /f "tokens=5 delims==_" %%i in ('ffprobe -v error -of flat^=s^=_ -select_streams v:0 -show_entries stream^=height %1') do set H=%%i
echo %H%
46scxncf

46scxncf4#

输出文件的名称和它的宽度+高度到终端。

#!/usr/bin/env bash

clear

name="$(find ./ -type f -iname '*.mp4' | sed 's/^..//g')"

for f in "$(echo $name | tr ' ' '\n')"
do
    for i in ${f[@]}
    do
        dimensions="$(ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x "${i}")"
        echo "${PWD}/${i} | ${dimensions}" | sort -h
    done
done

相关问题