Wrong FPS and FRAME_COUNT read from a wmv file with opencv4.0 under python

asked 2020-08-19 11:39:40 -0600

Hi,

On a debian machine, Opencv 4.0, Python 3.7.7 opencv return time scale instead of fps and return duration in timebase unit instead of frame count from a wmv video that does not contain avg_frame_rate and nb_frames in its header. How can we test with opencv if infos are missing in the header and try to use other values (like r_frame_rate) from the header to calculate frame rate and duration or total number of frames ?

Underneath are the output from opencv command under python and ffprobe.

Thank you for your help

duprat@ponset:/movies$ python Python 3.7.7 (default, Apr 1 2020, 13:48:52) [GCC 9.3.0] on linux

import cv2

cap = cv2.VideoCapture('Record1.wmv') cap.get(cv2.CAP_PROP_FPS)

1000.0

cap.get(cv2.CAP_PROP_FRAME_COUNT)

160450763.0

duprat@ponset:/movies$ ffprobe -show_entries stream Record1.wmv

ffprobe version 4.2.2-1+b1 Copyright (c) 2007-2019 the FFmpeg developers built with gcc 9 (Debian 9.2.1-28) configuration: --prefix=/usr --extra-version=1+b1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, asf, from 'Record1.wmv': Metadata: WMFSDKNeeded : 0.0.0.0000 DeviceConformanceTemplate: AP@L2 WMFSDKVersion : 12.0.7601.17514 IsVBR : 0 Duration: 44:34:10.76, bitrate: 2656 kb/s Stream #0:0(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 800x600, 4000 kb/s, SAR 1:1 DAR 4:3, 25 tbr, 1k tbn, 1k tbc [STREAM] index=0 codec_name=vc1 codec_long_name=SMPTE VC-1 profile=Advanced codec_type=video codec_time_base=0/1 codec_tag_string=WVC1 codec_tag=0x31435657 width=800 height=600 coded_width=800 coded_height=600 has_b_frames=1 sample_aspect_ratio=1:1 display_aspect_ratio=4:3 pix_fmt=yuv420p level=2 color_range=unknown color_space=unknown color_transfer=unknown color_primaries=unknown chroma_location=left field_order=unknown timecode=N/A refs=1 id=N/A r_frame_rate=25/1

avg_frame_rate=0/0

time_base=1/1000

start_pts=N/A start_time=N/A duration_ts=160450763

duration=160450.763000

bit_rate=4000000 max_bit_rate=N/A bits_per_raw_sample=N/A nb_frames=N/A

nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=0 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 DISPOSITION:timed_thumbnails=0 TAG:language=eng

edit retag flag offensive close merge delete

Comments

imho, you answered your own question already: -- use ffprobe, don't insist on doing this with opencv

berak gravatar imageberak ( 2020-08-19 12:31:32 -0600 )edit