GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing github.com — Loading audio tensors fails: ValueError: all input arrays must have the same shape · Issue #1875 · docarray/docarray
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Loading audio tensors fails: ValueError: all input arrays must have the same shape #1875Copy link Copy link Open DescriptionInitial Checks
DescriptionI have created subclips of a video in .mp4 using ffmpeg (through moviepy): # moviepy.video.io.ffmpeg_tools.ffmpeg_extract_subclip def ffmpeg_extract_subclip(filename, t1, t2, targetname=None): """ Makes a new video file playing video file ``filename`` between the times ``t1`` and ``t2``. """ name, ext = os.path.splitext(filename) if not targetname: T1, T2 = [int(1000*t) for t in [t1, t2]] targetname = "%sSUB%d_%d.%s" % (name, T1, T2, ext) cmd = [get_setting("FFMPEG_BINARY"),"-y", "-ss", "%0.2f"%t1, "-i", filename, "-t", "%0.2f"%(t2-t1), "-map", "0", "-vcodec", "copy", "-acodec", "copy", targetname] subprocess_call(cmd) The subclip path is passed to subclip = VideoUrl("<subclip_path>") Trying to load the tensors fails: tensors = subclip.load() Stepping through the code shows that the first audio frame has a sample rate of 16: The second and all subsequent frames have 1024 samples: So this results in arrays with different shapes for the audio. What Ive tried:
If there is a way to handle the shape mismatch inside DocArray that would be great because it would let me create the subclips and model them as quickly as possible. It would need to be added to this block: docarray/docarray/typing/bytes/video_bytes.py Lines 83 to 86 in f71a5e6
Example Codeimport os from pathlib import Path import numpy as np from docarray.typing import VideoUrl from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip def generate_subclips(parent_path, video_id, video_uri, video_duration, duration=60): subclips_path = Path(parent_path) / "subclips" subclips_path.mkdir(exist_ok=True) start_times = np.arange(0, video_duration, duration) end_times = np.append(start_times[1:], video_duration) clip_times = list(zip(start_times, end_times)) for start_time, end_time in clip_times: # filename should have start_end seconds as part of the name output_file_path = subclips_path / f"{video_id}__{start_time}_{end_time}.{video_uri.suffix[1:]}" ffmpeg_extract_subclip(video_uri, start_time, end_time, targetname=output_file_path) # Example usage # parent_path = 'path/to/parent/directory' # video_id = 'example_video_id' # video_uri = Path('path/to/video.mp4') # video_duration = 1200 # for example, 20 minutes # generate_subclips(parent_path, video_id, video_uri, video_duration, duration=60) def sort_key(path): """Sorts by the start time in the subclip file name For example: Fu7YkoRWKB8_Y__0_60.mp4 will sort by `0` """ # Extract the integer after "__" from the filename return int(path.stem.split('__')[1].split('_')[0]) subclips_dir = Path(os.getcwd()).parent / "subclips" # create subclips generate_subclips(subclips_dir, <video_id>, <video_uri>, <video_duration>, duration=60) subclips_paths = sorted(subclips_dir.iterdir(), key=sort_key) video_urls = [VideoUrl(f"{str(subclip)}") for subclip in subclips_paths] # load tensors # the first subclip might work... subclip0 = VideoUrl(str(subclips_paths[0])) subclip0_tensors = subclip.load() # but the second and other subclips throw the shape mismatch error subclip1 = VideoUrl(str(subclips_paths[1])) subclip1_tensors = subclip.load() Python, DocArray & OS VersionAffected ComponentsActivity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |