How to determine webm duration using ffprobe

时间秒杀一切 提交于 2020-01-14 09:10:32

问题


My goal is simple , I have several webm files need to be concated, but first I need to determine their durations.

It seems webm file are played as streams, so there is no way to tell the length of each file.

I have been using ffprobe to do the job ,but the duration returned is N/A.The command I use was:

ffprobe -i input.file -show_format | grep duration

thanks.

The complete output of ffprobe list below:

 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

回答1:


I faced the same issue with some files that does not contain the Duration nor Bitrate on it and found the following solution:

1- Repackage the files with: (Note that this won't transcode the files, just will copy them)

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

2- Take the duration from the new copied file:

ffprobe new_source.webm | grep Duration



回答2:


Container Duration

Print total seconds:

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

Result example: 221.333000.
Adding the -sexagesimal option, the result will show HH::MM::SS time unit format.
Result example: 0:03:41.333000.

Reference: https://superuser.com/a/945604/614421




回答3:


I ran into your question while trying to solve mine: Re-encoding vlc-created mpeg2 .ts file results in 20 second file

If you want to find the duration, use something like this:

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

I chose 90M since my file was just over 70mb, choose the appropriate size according to your file.


EDIT:

Not sure why it is not working for others, I have now tested with multiple .webm files, and am having success getting the duration for all of them. If it fails for you, can you please provide a link to the webm file so I can test? In my case, it worked for the following:

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

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



来源:https://stackoverflow.com/questions/34118013/how-to-determine-webm-duration-using-ffprobe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!