Skip to content

Commit

Permalink
ffprobe_audio
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi authored and devxpy committed Jul 30, 2024
1 parent ba3faf7 commit 8c86f97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
21 changes: 21 additions & 0 deletions ffmpeg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ class InputOutputVideoMetadata(BaseModel):
output: VideoMetadata


class AudioMetadata(BaseModel):
duration_sec: float = 0


def ffprobe_audio(input_path: str) -> AudioMetadata:
cmd_args = [
"ffprobe",
"-v",
"error",
"-show_entries",
"format=duration",
"-of",
"default=noprint_wrappers=1:nokey=1",
input_path,
]
print("\t$ " + " ".join(cmd_args))
return AudioMetadata(
duration_sec=float(subprocess.check_output(cmd_args, encoding="utf-8"))
)


def ffprobe_video(input_path: str) -> VideoMetadata:
cmd_args = [
"ffprobe",
Expand Down
17 changes: 2 additions & 15 deletions retro/sadtalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from celeryconfig import app, setup_queues
from ffmpeg_util import (
ffprobe_video,
ffprobe_audio,
ffmpeg_read_input_frames,
VideoMetadata,
ffmpeg_get_writer_proc,
Expand Down Expand Up @@ -219,21 +220,7 @@ def sadtalker(
print(subprocess.check_output(args, encoding="utf-8"))
audio_path = wav_audio_path
# make sure audio is not 0 seconds
audio_length = float(
subprocess.check_output(
[
"ffprobe",
"-v",
"error",
"-show_entries",
"format=duration",
"-of",
"default=noprint_wrappers=1:nokey=1",
audio_path,
],
encoding="utf-8",
)
)
audio_length = ffprobe_audio(audio_path).duration_sec
if audio_length <= 0.1:
raise ValueError("Audio is too short")

Expand Down

0 comments on commit 8c86f97

Please sign in to comment.