本文介绍了我们可以在ffmpeg ffprobe中声明一个变量吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是ffmpeg的新手.
I am new to ffmpeg.
我想通过ffmpeg获取视频时长并将其声明为变量.在这里我可以将值用于其他功能.我正在使用电源壳.
I want to get a video duration through ffmpeg and declare it to a variable. where I can use the value for a different function. I am using power shell.
这是我的代码:
ffmpeg -i 1aef53e6-92ac-4d28-89f8-4cce28fa0f58.mp4 2>&1 | sed -n 's/Duration: \(.*\), start/\1/gp'
推荐答案
假设您已在Windows PATH
变量中设置了ffmpeg的路径,如说明的,这应该为您提供文件的持续时间值:
Provided you have set up the path for ffmpeg in the Windows PATH
variable like explained here, this should get you the duration value for the file:
$filename = '1aef53e6-92ac-4d28-89f8-4cce28fa0f58.mp4'
$duration = if ((ffmpeg -i $filename 2>&1 | Out-String) -match 'Duration:\s+([\d:.]+)') { $matches[1] }
提醒您,在此 $ duration
之后是一个字符串.
如果您需要为此创建一个 TimeSpan
对象,请使用:
Mind you, after this $duration
is a string.
If you need to create a TimeSpan
object of this, use:
$t = [TimeSpan]::Parse($duration)
这篇关于我们可以在ffmpeg ffprobe中声明一个变量吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!