FFMPEG-将FFPROBE的持续时间输出存储为变量 [英] FFMPEG - Store FFPROBE's duration output as a variable

查看:429
本文介绍了FFMPEG-将FFPROBE的持续时间输出存储为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 enable ='between(t,0,0)字段中使用视频的时长,以确保每次都以视频时长的1/3覆盖图像。

I wanted to use a video's duration in the "enable='between(t,0,0)" field to make sure that I overlay an image at 1/3 of the video's duration every time.

根据FFMPEG在其网站上的信息,我需要使用此

According to FFMPEG's info on their site, I need to use this

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

it确实返回了一个值,但我似乎无法将其设置为可用变量,我已经尝试使用

it does return a value but I can't seem to be able to set it to a usable variable, I already tried by using

set duration=ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

然后通过%duration%引用它,但是没有运气。

And then referencing it via %duration%, but no luck.

有没有办法做到这一点,我做错了吗?

Is there a way to do this, am I doing something wrong?

谢谢您的帮助。

推荐答案

该命令旨在处理以下内容的输出控制台应用程序是 FOR

The command designed for processing output of a console application is FOR.

如下所示的批处理文件代码可用于捕获< a href = https://ffmpeg.org/ffprobe.html rel = nofollow noreferrer> ffprobe 并将其分配给环境变量。

A batch file code like below can be used to capture output of ffprobe and assign it to an environment variable.

@echo off
setlocal EnableExtensions DisableDelayedExpansion
if not exist input.mp4 goto :EOF
for /F "delims=" %%I in ('ffprobe.exe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 input.mp4 2^>^&1') do set "duration=%%I"
echo Duration is: %duration%
endlocal

命令 FOR 与选项 / F 一起将'中包含的字符串解释为要执行的命令,该输出将写入 STDOUT 应该逐行处理。为此,分别 FOR cmd.exe 处理批处理文件开始,另外一个命令进程在后台使用%ComSpec%/ c '之间的命令行作为附加参数附加,并捕获为处理另外启动的背景而处理 STDOUT 的所有内容

The command FOR with option /F interprets the string enclosed in ' as command to execute of which output written to STDOUT should be processed line by line. FOR respectively cmd.exe processing the batch file starts for this purpose one more command process in background with %ComSpec% /c and the command line between ' appended as additional arguments and captures everything written to handle STDOUT of the additionally started background command process.

Windows命令处理器 cmd.exe 处理批处理文件时,也将空格解释为逗号,分号; ,等号 = 和OEM编码的不间断空间 (十进制代码值为255)作为参数分隔符。因此,必须在命令行中使用 ^ 来对每个 = 进行转义,以传递给 cmd.exe 在后台启动,通过 cmd.exe 处理批处理文件而不是参数分隔符,将等号解释为文字字符。

Windows command processor cmd.exe processing the batch file interprets among space also comma ,, semicolon ;, equal sign = and OEM encoded no-break space (with decimal code value 255) as argument separator. For that reason it is necessary to escape each = with ^ in the command line to pass to cmd.exe started in background to get the equal signs interpreted as literal characters by cmd.exe processing the batch file instead of argument separators.

2>& 1 重定向写入 STDERR 的输出(标准错误)以处理 STDOUT (标准输出),由 FOR 处理。在这里有必要使用 ^ > & 运算符c $ c>,以便在执行 ffprobe 时应用此重定向,而不在解析 FOR 命令行时已解释该重定向。请参阅Microsoft文章使用命令重定向运算符。如果 ffprobe 以正确的用法将请求的信息输出到 STDOUT ,则可能不需要将 STDERR 重定向到 STDOUT 。但是如果 ffprobe 将数据输出到 STDERR ,这可能很重要。

2>&1 redirects output written to STDERR (standard error) to handle STDOUT (standard output) which is processed by FOR. It is necessary here to escape the operators > and & with ^ to apply this redirection on execution of ffprobe and not interpreting the redirection already on parsing FOR command line. See the Microsoft article Using command redirection operators. This redirection of STDERR to STDOUT is perhaps not necessary if ffprobe outputs on correct usage the requested information to STDOUT. But it could be important if ffprobe outputs the data to STDERR.

因此,在Windows中将 C:\Windows

So executed in background is following with Windows installed into C:\Windows:

C:\Windows\System32\cmd.exe /c ffprobe.exe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4 2>&1

根据语法的描述,这是Windows命令处理器的绝对有效执行,如在Windows cmd /?的帮助输出所解释的那样= https://www.howtogeek.com/235101/ rel = nofollow noreferrer>命令提示符窗口。

That is an absolutely valid execution of Windows command processor according to syntax as explained by the help output on running cmd /? in a Windows command prompt window.

选项 delims在 / F 之后用双引号= 禁用将捕获的行拆分为使用空格和水平制表符作为定义的字符串分隔符的多个标记(字符串)字符串定界符的空列表。对于使用所使用的命令行输出 ffprobe 来说, delims = 很可能不是必需的。但是我没有安装 ffprobe ,也没有对它的输出内容有所疑问。

The option delims= in double quotes after /F disables splitting up the captured line into multiple tokens (strings) using space and horizontal tab as string separators as it defines an empty list of string delimiters. "delims=" is most likely not necessary for output of ffprobe with the used command line. But I don't have ffprobe installed and it was not posted in question what it outputs.

要了解所使用的命令及其工作方式,请打开一个命令提示窗口,执行以下命令,并非常仔细地阅读每个命令显示的所有帮助页面。

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.


  • echo /?

  • endlocal /?

  • 对于/?

  • goto /?

  • 如果/?

  • set /?

  • setlocal /?

  • echo /?
  • endlocal /?
  • for /?
  • goto /?
  • if /?
  • set /?
  • setlocal /?

这篇关于FFMPEG-将FFPROBE的持续时间输出存储为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆