如何从ffmpeg输出中提取持续时间? [英] How to extract duration time from ffmpeg output?
本文介绍了如何从ffmpeg输出中提取持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要获取有关媒体文件的大量信息,可以这样做
To get a lot of information about a media file one can do
ffmpeg -i <filename>
它会输出很多行,特别是一行
where it will output a lot of lines, one in particular
Duration: 00:08:07.98, start: 0.000000, bitrate: 2080 kb/s
我只想输出00:08:07.98
,所以我试试
I would like to output only 00:08:07.98
, so I try
ffmpeg -i file.mp4 | grep Duration| sed 's/Duration: (.*), start/1/g'
但它会打印所有内容,而不仅仅是长度.
But it prints everything, and not just the length.
即使 ffmpeg -i file.mp4 |grep Duration
输出一切.
如何获得持续时间长度?
How do I get just the duration length?
推荐答案
ffmpeg 正在将该信息写入 stderr
,而不是 stdout
.试试这个:
ffmpeg is writing that information to stderr
, not stdout
. Try this:
ffmpeg -i file.mp4 2>&1 | grep Duration | sed 's/Duration: (.*), start/1/g'
注意将 stderr
重定向到 stdout
:2>&1
Notice the redirection of stderr
to stdout
: 2>&1
您的 sed
语句也不起作用.试试这个:
Your sed
statement isn't working either. Try this:
ffmpeg -i file.mp4 2>&1 | grep Duration | awk '{print $2}' | tr -d ,
这篇关于如何从ffmpeg输出中提取持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文