# get the number of frame of a video using vision.VideoFileReader and VideoReader

252 views (last 30 days)
zhang on 26 Mar 2014
Answered: Gerard Wensink on 12 May 2019
obj.NumOfFrames
count= 0;
% Read a video frame and run the detector.
count= ind+1;
end
But obj.NumOfFrames does not equal to count for my video file. Actually count = obj.NumOfFrames+1.
Can anyone explain this?
Thanks, Zhong
Walter Roberson on 3 Mar 2017

Behzad Taheri on 24 Dec 2016
Edited: Behzad Taheri on 24 Dec 2016
If you try:
>> obj
General Properties:
Name: 'atrium.avi'
Path: 'C:\Program Files\MATLAB\R2015a\toolbox\vision\visiondata'
Duration: 47
CurrentTime: 0
Tag: ''
UserData: []
Video Properties:
Width: 640
Height: 360
FrameRate: 30
BitsPerPixel: 24
VideoFormat: 'RGB24'
you will see that, only Duration and FrameRate are available. So the number of frames can be calculated as: Duration x FrameRate = 47 x 30 = 1410
##### 2 CommentsShowHide 1 older comment
Yunxing Tian on 1 Apr 2019
In my experiment, the actural frame number is 296, however, the durition is 9.9200 and the fps is 30. floor(9.92*30) = 297

OJ27 on 5 Jan 2016
because you set count=0. Remember matlab indexing starts the count at 1.

Walter Roberson on 3 Mar 2017
Basically, you need to scan the entire movie to find the number of frames correctly. The NumberOfFrames, when it existed, was an estimate.

Gerard Wensink on 12 May 2019
Best method: (Direct by calculating right parameters, confirmed by ffmpeg)
Cmd ->
ffprobe.exe -v error -select_streams v:0 -show_entries stream=r_frame_rate,duration -of default=nw=1 "d:\movies\The.Matrix.1999.1080p.BrRip.x264.YIFY.dut.mp4"
Result ->
r_frame_rate=24000/1001
duration=8177.794625
Calculation ->
Frames=24000/1001*8177.794625=196071 (exactly... ;P)
Proof ->
ffmpeg -i "d:\movies\The.Matrix.1999.1080p.BrRip.x264.YIFY.dut.mp4" -f null /dev/null
ffmpeg version N-92938-g0aaaca25e0-ffmpeg-windows-pacman Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.0 (GCC)
configuration: --pkg-config=pkg-config --pkg-config-flags=--static --extra-version=ffmpeg-windows-pacman --enable-version3 --disable-debug --disable-w32threads --arch=x86_64 --target-os=mingw32 --cross-prefix=/opt/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --enable-libcaca --enable-gray --enable-libtesseract --enable-fontconfig --enable-gmp --enable-gnutls --enable-libass --enable-libbluray --enable-libbs2b --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-libmysofa --enable-libaom --enable-libopenjpeg --enable-libopenh264 --enable-liblensfun --enable-nvenc --enable-nvdec --extra-libs=-lm --extra-libs=-lpthread --extra-cflags=-DLIBTWOLAME_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCACA_STATIC --enable-amf --enable-libmfx --enable-gpl --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable-librubberband --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxavs --enable-avresample --extra-cflags='-march=core2' --extra-cflags=-O2 --enable-static --disable-shared --prefix=/opt/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-nonfree --enable-decklink --enable-libfdk-aac
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 43.100 / 58. 43.100
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 47.100 / 7. 47.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'd:\movies\The.Matrix.1999.1080p.BrRip.x264.YIFY.dut.mp4':
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.25.100
Duration: 02:16:17.91, start: 0.000000, bitrate: 2497 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x800 [SAR 1:1 DAR 12:5], 2397 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
handler_name : GPAC ISO Audio Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.25.100
Stream #0:0(und): Video: wrapped_avframe, yuv420p, 1920x800 [SAR 1:1 DAR 12:5], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
handler_name : VideoHandler
encoder : Lavc58.43.100 wrapped_avframe
Stream #0:1(und): Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s (default)
handler_name : GPAC ISO Audio Handler
encoder : Lavc58.43.100 pcm_s16le
HERE!!! ->
frame=196071 fps=331 q=-0.0 Lsize=N/A time=02:16:17.90 bitrate=N/A speed=13.8x
YOU SEE???? GREAT IS'NT IT EH?
shareeditdeleteflag
gerardwensink@gmail.com
Thank you...