Vi.*_*Vi. 31 video linux vlc-media-player ffmpeg mplayer
假设我们有一个视频文件 some_video。
如何从 shell 脚本(使用 mplayer/transcode/gstreamer/vlc/ffmpeg/whatever)获取它的长度?
VIDEO_LENGTH_IN_SECONDS=`ffmpeg .... -i some_video ... | grep -o .....`
Run Code Online (Sandbox Code Playgroud)
小智 48
ffprobe -i some_video -show_entries format=duration -v quiet -of csv="p=0"
Run Code Online (Sandbox Code Playgroud)
将以秒为单位返回视频持续时间。
slh*_*hck 24
类似于:
ffmpeg -i input 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//
Run Code Online (Sandbox Code Playgroud)
这将提供:HH:MM:SS.ms。您还可以使用ffprobe,它随大多数 FFmpeg 安装提供:
ffprobe -show_format input | sed -n '/duration/s/.*=//p'
Run Code Online (Sandbox Code Playgroud)
… 或者:
ffprobe -show_format input | grep duration | sed 's/.*=//')
Run Code Online (Sandbox Code Playgroud)
要转换为秒(并保留毫秒),请输入:
awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'
Run Code Online (Sandbox Code Playgroud)
要将其转换为毫秒,请通过管道输入:
awk '{ split($1, A, ":"); print 3600000*A[1] + 60000*A[2] + 1000*A[3] }'
Run Code Online (Sandbox Code Playgroud)
如果你只想要没有毫秒的秒数,请输入:
awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'
Run Code Online (Sandbox Code Playgroud)
例子:

小智 6
ffprobe -v error -select_streams v:0 -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 movie.mp4
Run Code Online (Sandbox Code Playgroud)
将返回总持续时间(以秒为单位)。(视频+音频)= 124.693091
ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 movie.mp4
Run Code Online (Sandbox Code Playgroud)
将仅返回视频持续时间(以秒为单位)stream=duration= 123.256467
ffprobe -v error -sexagesimal -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 movie.mp4
Run Code Online (Sandbox Code Playgroud)
将仅返回使用该-sexagesimal格式的视频持续时间。= 0:02:03.256467
| 归档时间: |
|
| 查看次数: |
33376 次 |
| 最近记录: |