Skip to content

Commit

Permalink
Clean up get_audio try/catch
Browse files Browse the repository at this point in the history
The prior implementation made a best effort to continue in the event of
an error, but immediately threw an error afterwards since there was no
output from the subprocess.

As get_audio isn't called until the audio connection from a Load Video
is used, it's safe to raise an exception here and properly expose the
error message from ffmpeg as is done elsewhere.

See Kosinkadink#250
  • Loading branch information
AustinMroz authored and GentlemanHu committed Jul 14, 2024
1 parent 3b8e37e commit c54fb15
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions videohelpersuite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ def get_audio(file, start_time=0, duration=0):
res = subprocess.run(args + ["-f", "f32le", "-"],
capture_output=True, check=True)
audio = torch.frombuffer(bytearray(res.stdout), dtype=torch.float32)
match = re.search(', (\\d+) Hz, (\\w+), ',res.stderr.decode('utf-8'))
except subprocess.CalledProcessError as e:
logger.warning(f"Failed to extract audio from: {file}")
audio = torch.zeros(1,2)
match = re.search(', (\\d+) Hz, (\\w+), ',res.stderr.decode('utf-8'))
raise Exception(f"VHS failed to extract audio from {file}:\n" \
+ e.stderr.decode("utf-8"))
if match:
ar = int(match.group(1))
#NOTE: Just throwing an error for other channel types right now
Expand Down

0 comments on commit c54fb15

Please sign in to comment.