FFmpeg get duration of video file without meta data

1

I got a video file which has no meta data.

If I do this for example:

ffmpeg -i test.m2v

I get these values:

Duration: N/A, bitrate: N/A

Is there still a way to get the duration of the video / .m2v file ?

Edit:

The full console output:

ffmpeg version 2.8.4 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.2.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-libdcadec --enable-libfr
eetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enab
le-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink
--enable-zlib
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegvideo, from '.\Test.m2v':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mpeg2video (Main), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 7000 kb/s, 25 fps, 25 tbr, 1200k tbn, 50 tbc

utdev

Posted 2017-02-15T08:46:51.790

Reputation: 159

Can you show the entire console output, please? – slhck – 2017-02-15T09:55:37.600

@slhck ok I put the whole console output in the question edit – utdev – 2017-02-15T10:07:06.947

That one does have the duration. But, in general, if it's a raw bitstream, ffprobe with count_frames will work. – Gyan – 2017-02-15T10:54:41.653

Whops I posted a wrong output, I tested it with another file and that worked, I'll post the output from the original file. Thus how would the command look with ffprobe? – utdev – 2017-02-15T11:02:36.143

Answers

2

For a raw bitstream, ffprobe can be used.

ffprobe -show_entries stream=r_frame_rate,nb_read_frames -select_streams v -count_frames -of compact=p=0:nk=1 -v 0 in.m2v

This produces

30/1|120

where first entry is the frame rate as a rational number, and second is the number of frames counted. Duration is 120 / (30/1) = 4.00s

Gyan

Posted 2017-02-15T08:46:51.790

Reputation: 21 016

does the "in" belongs to the command or is that just a random filename`? – utdev – 2017-02-16T14:30:34.643

Ok I tried this on a 25sec video and I got 27,48 after the calculation. It is not accurate, is it really accurate if you use it? – utdev – 2017-02-16T14:40:21.663

Works here .Can you upload the errant file? – Gyan – 2017-02-17T13:31:43.437

where do you want me to upload it? – utdev – 2017-02-17T13:47:52.160

datafilehost, dropbox. drive... – Gyan – 2017-02-17T14:00:18.060

https://www.datafilehost.com/d/e7712560 – utdev – 2017-02-17T14:07:42.327

Is accurate. There are 687 frames, all of which I extracted as a image sequence. That's 27.48s. Why do you think it's exactly 25 seconds? – Gyan – 2017-02-17T14:30:55.493

Use ffmpeg -i in.m2v -vsync 0 img-%d.png to check – Gyan – 2017-02-17T14:31:55.223

Did you also try this with a length of ~10minutes, there is a higher gap when I tried it with a video which has a length of ~10 minutes. – utdev – 2017-02-21T11:24:54.943

No. But there's no gap, as duration is accurate in terms of # of frames stored and fps. How did you get 25s as duration of your clip? – Gyan – 2017-02-21T11:29:57.900

if I put the video in a video player, in my case power dvd it shows 25s – utdev – 2017-02-21T11:34:13.610

Try another player, or time it with an app/stopwatch..etc – Gyan – 2017-02-21T11:37:31.650

The time of the player is correct, any other idea – utdev – 2017-02-21T11:54:52.487