Supercreature
Supercreature

Reputation: 469

How To Extract The Duration From A Webm Using FFprobe

I have the following code which stores the duration of a video file in a variable called duration:

for /f %%i in ('ffprobe -select_streams v:0 -show_entries stream^=duration -of default^=noprint_wrappers^=1:nokey^=1 input.avi') do set duration=%%i

However, when I try to get the duration of a .webm file I get N/A. I used the answer here How to determine webm duration using ffprobe which helped me to be able to see the duration of a webm when using ffprobe. But for some reason I can see the duration in the output of ffprobe but I cannot manage to store it in a variable.

Please help me with this. Thank you


Here is the command and output:

Command:

for /f %%i in ('ffprobe -select_streams v:0 -show_entries stream^=duration -of default^=noprint_wrappers^=1:nokey^=1 webm_copy.webm') do set duration=%%i

echo %duration%

Output:

D:\SOFTWARE\ffmpeg\bin\test\go>for /F %i in ('ffprobe -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 webm_copy.webm') do set duration=%i
ffprobe version N-80066-g566be4f Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.100 / 57. 37.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from 'webm_copy.webm':
  Metadata:
    encoder         : Lavf57.37.100
  Duration: 00:01:31.44, start: 0.000000, bitrate: 278 kb/s
    Stream #0:0: Video: vp8, yuv420p, 480x360, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn (default)
    Stream #0:1: Audio: vorbis, 44100 Hz, stereo, fltp (default)

D:\SOFTWARE\ffmpeg\bin\test\go>set duration=N/A

D:\SOFTWARE\ffmpeg\bin\test\go>echo N/A
N/A

Upvotes: 0

Views: 1835

Answers (1)

llogan
llogan

Reputation: 133753

You can retrieve the duration stored in the container for Matroska and Webm. Change -show_entries stream=duration to -show_entries format=duration.

If you want just the duration value to br outputted see the -loglevel/-v and -of options as shown in the examples in FFmpeg Wiki: FFprobe.

Upvotes: 3

Related Questions