Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何使用ffprobe&;返回视频/图像的宽度和高度;批处理_Windows_Batch File_Command Line_Ffmpeg_Ffprobe - Fatal编程技术网

Windows 如何使用ffprobe&;返回视频/图像的宽度和高度;批处理

Windows 如何使用ffprobe&;返回视频/图像的宽度和高度;批处理,windows,batch-file,command-line,ffmpeg,ffprobe,Windows,Batch File,Command Line,Ffmpeg,Ffprobe,我需要使用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% 但未能执行

我需要使用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、 我还以类似的方式尝试了imagemagick Identification,但在返回GIF文件的高度时,Identification似乎有一个错误

我已设法调整了您的脚本,它正在工作,您可以这样尝试:

@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

我已经成功地调整了您的脚本,它正在工作,您可以通过以下方式尝试:

@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

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


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


我认为答案太过分了。只需一个
ffprobe
命令,无需写入文件,无需控制台消息:

for /f "delims=" %%a in ('ffprobe -hide_banner -show_streams %1 2^>nul ^| findstr "^width= ^height="') do set "mypicture_%%a"
最后是环境变量
mypicture\u width
mypicture\u height
。您可以通过以下方式进行检查:

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

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

我认为答案太过分了。只需一个
ffprobe
命令,无需写入文件,无需控制台消息:

for /f "delims=" %%a in ('ffprobe -hide_banner -show_streams %1 2^>nul ^| findstr "^width= ^height="') do set "mypicture_%%a"
最后是环境变量
mypicture\u width
mypicture\u height
。您可以通过以下方式进行检查:

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

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

对您添加的内容和原因进行一个小说明会很有帮助。这样,您将不会收到错误消息:
参数'\u'作为输入文件名提供,但已经指定了。
对您添加的内容和原因进行一个小说明。这样,您将不会收到错误消息:
参数'\u'作为输入文件名提供,但已指定了。