如何提取ffmpeg的输出持续时间? [英] How to extract duration time from ffmpeg output?

查看:207
本文介绍了如何提取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 ,所以我尽量

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的持续时间输出的一切。

我如何得到的只是时间长短?

How do I get just the duration length?

推荐答案

ffmpeg的是写这些信息标准错误,而不是标准输出。试试这个:

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'

注意标准错误重定向到标准输出 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屋!

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