From b239af8bbd67cabb5a4d199ffb15cb19deb042b8 Mon Sep 17 00:00:00 2001 From: Leonhard Helminger Date: Fri, 25 Sep 2026 15:32:17 -0700 Subject: [PATCH] Add optional audio track support to `write_video` and `show_video(s)`. PiperOrigin-RevId: 988530771 --- mediapy/__init__.py | 204 +++++++++++++++++++++++++++++++++++++------- mediapy_test.py | 193 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 365 insertions(+), 32 deletions(-) diff --git a/mediapy/__init__.py b/mediapy/__init__.py index a1b505e..41400f2 100644 --- a/mediapy/__init__.py +++ b/mediapy/__init__.py @@ -191,6 +191,17 @@ _T = typing.TypeVar('_T') _Path = typing.Union[str, 'os.PathLike[str]'] +# Raw PCM sample formats (as in `ffmpeg -formats`) for the audio dtypes that +# `VideoWriter` is able to feed to `ffmpeg`. Multi-byte formats lack the +# byte-order suffix ('le' or 'be'), which is appended for the native order. +_FFMPEG_AUDIO_FORMAT_FROM_DTYPE = { + np.uint8: 'u8', + np.int16: 's16', + np.int32: 's32', + np.float32: 'f32', + np.float64: 'f64', +} + _IMAGE_COMPARISON_HTML = """\