Read/write/show images and videos in an IPython/Jupyter notebook.
[GitHub source] [API docs] [Colab example]
Examples:
See the notebook
mediapy_examples.ipynb
Images:
!pip install -q mediapy
import mediapy as media
import numpy as np
image = media.read_image('https://github.com/hhoppe/data/raw/main/image.png')
print(image.shape, image.dtype) # It is a numpy array.
media.show_image(image)
checkerboard = np.kron([[0, 1] * 16, [1, 0] * 16] * 16, np.ones((4, 4)))
media.show_image(checkerboard)
media.show_image(media.color_ramp((128, 128)), height=48, title='ramp')
images = {
'original': image,
'brightened': media.to_float01(image) * 1.5,
}
media.show_images(images)
media.write_image('/tmp/checkerboard.png', checkerboard)
Videos:
url = 'https://github.com/hhoppe/data/raw/main/video.mp4'
video = media.read_video(url)
print(video.shape, video.dtype) # It is a numpy array.
print(video.metadata.fps) # The 'metadata' attribute includes framerate.
media.show_video(video) # Play the video using the retrieved framerate.
media.show_images(video, height=80, columns=4) # Show frames side-by-side.
video = media.moving_circle((128, 128), num_images=10)
media.show_video(video, fps=10)
media.write_video('/tmp/video.mp4', video, fps=60)
# Darken a video frame-by-frame:
filename_in = '/tmp/video.mp4'
filename_out = '/tmp/out.mp4'
with media.VideoReader(filename_in) as r:
print(f'shape={r.shape} fps={r.fps} bps={r.bps}')
darken_image = lambda image: media.to_float01(image) * 0.5
with media.VideoWriter(
filename_out, shape=r.shape, fps=r.fps, bps=r.bps) as w:
for image in r:
w.add_image(darken_image(image))
media.show_video(media.read_video(filename_out), fps=60)
Setup:
Video I/O relies on the external program ffmpeg, which must be present in
the system PATH. On Unix, it can be installed using:
apt install ffmpeg
or within a notebook using:
!command -v ffmpeg >/dev/null || (apt update && apt install -y ffmpeg)
Metadata
Release files for mediapy 1.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mediapy-1.2.7.tar.gz | 28.7 kB | Without provenance | Details for mediapy-1.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mediapy-1.2.7-py3-none-any.whl | Python 3 | none | any | Details for mediapy-1.2.7-py3-none-any.whl |
Total release size: 56.7 kB
Release files / mediapy-1.2.7.tar.gz
| Download URL | mediapy-1.2.7.tar.gz |
|---|---|
| Size | 28.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd3826ca156f9165cd369f44d4d345d5609df1da3caf867df7ce304e19dd7fde
|
|
BLAKE2b-256 checksum How to use checksums |
7c998b59dbcebf7e84b35e86c893f52fdc2953299d66ef1fcbacca26162818b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / mediapy-1.2.7-py3-none-any.whl
| Download URL | mediapy-1.2.7-py3-none-any.whl |
|---|---|
| Size | 28.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc81a9190d9724b02286efac4e7a67f384024e078fda0a3cac9fdf25e2f8878f
|
|
BLAKE2b-256 checksum How to use checksums |
1070eeb41d81fea2b3165cfe7ae1c662f9dc6310b14b230a96260376c2891cc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for mediapy 1.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.