matplotvideo - syncing video and matplotlib
What is it?
matplotvideo is a Python package providing an easy way to sync matplotlib plots to video. Some of the features:
- Frame-accurate seeking forward and backward
- Playback speed control between 0.01x and 4x
- Auto frame-skip to maintain playback speed when plot takes to long
- Seek with slider through entire video
- Intuitive pause/play toggle using spacebar
- Play all
cv2supported media types
Where to get it
The source code is currently hosted on GitHub at: https://github.com/PySport/matplotvideo
Installers for the latest released version are available at the Python package index.
# or PyPI
pip install matplotvideo
The package requires cv2 to be installed. When you don't have it installed yet, you can check out opencv-python.
Video player controls:
Sync between Scene Change data plot and video
- 'a' 1 frame back
- 'd' 1 frame forward
- space toggle paused / play
- esc quit video player
- playback speed can be changed with the slider
- playback position can be changed with the slider
Application examples
- Verify data using video
- Enrich video with additional data, like computer vision model output
- Find interesting video/data frames
Usage
Import attach_video_player_to_figure and attach to matplotlib figure. You can pass additional keyword arguments to attach_video_player_to_figure that are passed to the on_frame callback on each invocation.
from matplotvideo import attach_video_player_to_figure
import matplotlib.pyplot as plt
# (timestamp, value) pairs
# sample: big bunny scene cuts
fancy_data = [
(0, 1),
(11.875, 1),
(11.917, 2),
(15.75, 2),
(15.792, 3),
(23.042, 3),
(23.083, 4),
(47.708, 4),
(47.75, 5),
(56.083, 5),
(56.125, 6),
(60, 6)
]
def on_frame(video_timestamp, line):
timestamps, y = zip(*fancy_data)
x = [timestamp - video_timestamp for timestamp in timestamps]
line.set_data(x, y)
line.axes.relim()
line.axes.autoscale_view()
line.axes.figure.canvas.draw()
def main():
fig, ax = plt.subplots()
plt.xlim(-15, 15)
plt.axvline(x=0, color='k', linestyle='--')
line, = ax.plot([], [], color='blue')
attach_video_player_to_figure(fig, "BigBuckBunny.mp4", on_frame, line=line)
plt.show()
main()
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file matplotvideo-0.0.2.tar.gz.
File metadata
- Download URL: matplotvideo-0.0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7f13ff29a70a1ff4cd13e8456f3007060c8fcef40bff56b861a258b1228fd6b
|
|
| MD5 |
2805fce715e2cb4522196240809f5c26
|
|
| BLAKE2b-256 |
1b2fa4be316e16fb05508a9cafa4d7522065fe42c11b615ec2d522725a2f3382
|