Skip to content

Commit

Permalink
Fix a bug: unable to detect FPS for videos with variable FPS
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenhanQian committed Sep 5, 2024
1 parent 37d4ed5 commit e64b32a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vhap/preprocess_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ def video2frames(video_path: Path, image_dir: Path, keep_video_name: bool=False,
file_path_stem = video_path.stem + '_' if keep_video_name else ''

probe = ffmpeg.probe(str(video_path))

video_fps = int(probe['streams'][0]['r_frame_rate'].split('/')[0])
if video_fps ==0:
video_fps = int(probe['streams'][0]['avg_frame_rate'].split('/')[0])
if video_fps == 0:
# nb_frames / duration
video_fps = int(probe['streams'][0]['nb_frames']) / float(probe['streams'][0]['duration'])
if video_fps == 0:
raise ValueError('Cannot get valid video fps')

num_frames = int(probe['streams'][0]['nb_frames'])
video = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
W = int(video['width'])
Expand Down

0 comments on commit e64b32a

Please sign in to comment.