11

我的目标很简单,我有几个 webm 文件需要连接,但首先我需要确定它们的持续时间。

似乎 webm 文件是作为流播放的,所以没有办法知道每个文件的长度。

我一直在使用 ffprobe 来完成这项工作,但返回的持续时间是 N/A。我使用的命令是:

ffprobe -i input.file -show_format | grep duration

谢谢。

ffprobe 的完整输出列表如下:

 ffprobe version 2.6.2 Copyright (c) 2007-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libtheora --enable-libvorbis --enable-libvpx --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, matroska,webm, from '231':
  Metadata:
    encoder         : GStreamer matroskamux version 1.5.91
    creation_time   : 2015-12-05 07:59:29
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 14.99 fps, 14.99 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      title           : Video
    Stream #0:1(eng): Audio: vorbis, 48000 Hz, stereo, fltp (default)
    Metadata:
      title           : Audio
duration=N/A
4

5 回答 5

22

对于一些不包含 Duration 或 Bitrate 的文件,我遇到了同样的问题,并找到了以下解决方案:

1-重新打包文件:(请注意,这不会对文件进行转码,只会复制它们)

ffmpeg -i source.webm -vcodec copy -acodec copy new_source.webm

2-从新复制的文件中获取持续时间:

ffprobe new_source.webm | grep Duration
于 2016-10-18T20:45:08.217 回答
1

容器持续时间

打印总秒数:

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

结果示例:221.333000.
添加该-sexagesimal选项,结果将显示 HH::MM::SS 时间单位格式。
结果示例:0:03:41.333000.

参考:https ://superuser.com/a/945604/614421

于 2017-02-19T09:25:55.113 回答
0

The following solution is based on Daniel's version, but I modified it so I could inspect the individual stream lengths instead. This may help in the case where the duration is written in the metadata as TAG:DURATION.

ffprobe \
-v error \
-sexagesimal \
-show_entries stream=index,codec_name,start_time,duration:stream_tags=duration \
video.webm

Results in:

[STREAM]
index=0
codec_name=av1
start_time=0:00:00.007000
duration=N/A
TAG:DURATION=00:06:03.631000000
[/STREAM]
[STREAM]
index=1
codec_name=opus
start_time=0:00:-0.007000
duration=N/A
TAG:DURATION=00:06:04.001000000
[/STREAM]

This is useful because, as you can see, the streams report a different duration and you can identify problems in an easier manner.

于 2021-11-09T10:52:45.870 回答
0

运行命令

ffprobe -v quiet -print_format json -show_format  -show_streams input.mp4

如果您正在寻找 webm 容器中每个流的持续时间,则 ffprobe 输出中的字段名称和位置是不同的。在每个流中,您都会看到一个字段tags

"tags": {
                "language": "eng",
                "HANDLER_NAME": "ISO Media file produced by Google Inc. Created on: 12/09/2019.",
                "VENDOR_ID": "[0][0][0][0]",
                "ENCODER": "Lavc59.4.101 libvorbis",
                "DURATION": "00:03:14.703000000"
            }

您必须将这种人类可读的时间格式转换为秒。您可以轻松地使用以下实用程序功能。

def convert_secs(text):
    if isinstance(text, float):
        num = str(text)
        nums = num.split('.')
    else:
        nums = text.split(':')
    if len(nums) == 2:
        st_sn = int(nums[0]) * 60 + float(nums[1])
        return st_sn
    elif len(nums) == 3:
        st_sn = int(nums[0]) * 3600 + int(nums[1]) * 60 + float(nums[2])
        return st_sn
    else:
        raise ValueError("Not correct time")
于 2021-08-23T11:46:02.633 回答
-3

我在尝试解决我的问题时遇到了您的问题:Re-encoding vlc-created mpeg2 .ts file results in 20 second file

如果要查找持续时间,请使用以下内容:

ffmpeg -probesize 90M -analyzeduration 90M -i my_mpeg2_file.webm

我选择了90M,因为我的文件刚刚超过70mb,根据你的文件选择合适的大小。


编辑:

不知道为什么它对其他人不起作用,我现在已经使用多个 .webm 文件进行了测试,并且成功地获得了所有这些文件的持续时间。如果它对你来说失败了,你能提供一个 webm 文件的链接以便我测试吗?就我而言,它适用于以下情况:

https://thepaciellogroup.github.io/AT-browser-tests/video/ElephantsDream.webm

http://dl3.webmfiles.org/big-buck-bunny_trailer.webm

于 2016-11-23T11:35:47.123 回答