google / mediapy

This Python library makes it easy to display images and videos in a notebook.
https://pypi.org/project/mediapy/
Apache License 2.0
389 stars 18 forks source link

Incorrect video framerate #3

Closed dvschultz closed 3 years ago

dvschultz commented 3 years ago

A video that is 50seconds @ 24fps appears to be 20s @ 60fps in mediapy

Screen Shot 2021-03-21 at 3 35 06 AM Screen Shot 2021-03-21 at 3 34 50 AM
hhoppe commented 3 years ago

Could you please share the input video and the mediapy call(s) so that we can investigate? Thanks.

hhoppe commented 3 years ago

Please try including fps=24 in the media.show_video() call. (The issue is that the video retrieved using read_video() is a simple numpy array without the framerate information.)

Programmatically, one can use:

with media.VideoReader('https://github.com/hhoppe/data/raw/main/video.mp4') as reader:
  fps = reader.fps
  video = np.array(tuple(reader))
media.show_video(video, fps=fps)

or

with media.VideoReader('https://github.com/hhoppe/data/raw/main/video.mp4') as reader:
  media.show_video(reader, fps=reader.fps)
hhoppe commented 3 years ago

This should be fixed in https://github.com/google/mediapy/commit/21d54f34fdaea1724be2098c396a8c4fefab308b

Now the framerate should carry through even in the simple case below:

import mediapy as media
url = 'https://github.com/hhoppe/data/raw/main/video.mp4'
media.show_video(media.read_video(url))