diff --git a/musicalgestures/_motionvideo.py b/musicalgestures/_motionvideo.py index 98da0034..9efb2ebd 100644 --- a/musicalgestures/_motionvideo.py +++ b/musicalgestures/_motionvideo.py @@ -310,8 +310,11 @@ def mg_motion( self.motiongram_vertical_image = MgImage(target_name_mgx) self.motiongram_horizontal_image = MgImage(target_name_mgy) + # `audio_descriptors` arrives as a flag and travels on as the video to read + # audio from, which save_analysis expects. Two meanings, two names. + audio_descriptors_source: "bool | musicalgestures.MgVideo" = audio_descriptors if audio_descriptors: - audio_descriptors = self + audio_descriptors_source = self if save_data: # `normalize` was declared on mg_motion and never used. It now @@ -327,7 +330,7 @@ def mg_motion( if title is None: title = os.path.basename(of + fex) # save plot as an MgImage at motion_plot_image for parent MgVideo - self.motion_plot_image = MgImage(save_analysis(of, self.fps, aom, com, qom, motion_analysis, audio_descriptors, self.width, + self.motion_plot_image = MgImage(save_analysis(of, self.fps, aom, com, qom, motion_analysis, audio_descriptors_source, self.width, self.height, unit, title, target_name_plot=target_name_plot, overwrite=overwrite)) # Resetting numpy warnings for dividing by 0 diff --git a/musicalgestures/_posetools.py b/musicalgestures/_posetools.py index 0af52143..b1a9111e 100644 --- a/musicalgestures/_posetools.py +++ b/musicalgestures/_posetools.py @@ -225,6 +225,8 @@ def _read_result(lms, wlms): frame_bytes = w * h * 3 stopped_early = False proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # stdout=PIPE guarantees a stream; the annotation is Optional for the general case + assert proc.stdout is not None, "ffmpeg was started without a readable output stream" # Drain FFmpeg's stderr on a background thread as it is produced, rather # than only reading it in the `finally` block below: the stdout-reading # loop can run far longer than the OS pipe buffer takes to fill (a few diff --git a/musicalgestures/_ssm.py b/musicalgestures/_ssm.py index db654829..c60a6c66 100644 --- a/musicalgestures/_ssm.py +++ b/musicalgestures/_ssm.py @@ -544,6 +544,7 @@ def mg_ssm( else: print(f'Unrecognized feature: "{features}". Try "motiongrams", "videograms, "spectrogram", "chromagram" or "tempogram".') + return None diff --git a/musicalgestures/_stream.py b/musicalgestures/_stream.py index 78229c7d..7dbac751 100644 --- a/musicalgestures/_stream.py +++ b/musicalgestures/_stream.py @@ -148,6 +148,8 @@ def __enter__(self) -> "MgVideoReader": self._process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=-1 ) + # stdout=PIPE guarantees a stream; the annotation is Optional for the general case + assert self._process.stdout is not None, "ffmpeg was started without a readable output stream" self._frame_index = 0 return self diff --git a/musicalgestures/_utils.py b/musicalgestures/_utils.py index 85e6885e..c8c28eb5 100644 --- a/musicalgestures/_utils.py +++ b/musicalgestures/_utils.py @@ -271,7 +271,7 @@ class MgFigure(): Class for working with figures and plots within the Musical Gestures Toolbox. """ - def __init__(self, figure=None, figure_type: str | None = None, data: dict | None = None, + def __init__(self, figure=None, figure_type: str | None = None, data: Any = None, layers: list | None = None, image=None): """ Initializes the MgFigure object. diff --git a/musicalgestures/_videoadjust.py b/musicalgestures/_videoadjust.py index d82a58a6..934d9187 100644 --- a/musicalgestures/_videoadjust.py +++ b/musicalgestures/_videoadjust.py @@ -1,6 +1,7 @@ import numpy as np import cv2 import os +import musicalgestures from musicalgestures._utils import scale_num, get_length, ffmpeg_cmd, has_audio, generate_outfilename, convert_to_mp4