Skip to content

Commit 8c86f97

Browse files
SanderGidevxpy
authored andcommitted
ffprobe_audio
1 parent ba3faf7 commit 8c86f97

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

ffmpeg_util.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ class InputOutputVideoMetadata(BaseModel):
2121
output: VideoMetadata
2222

2323

24+
class AudioMetadata(BaseModel):
25+
duration_sec: float = 0
26+
27+
28+
def ffprobe_audio(input_path: str) -> AudioMetadata:
29+
cmd_args = [
30+
"ffprobe",
31+
"-v",
32+
"error",
33+
"-show_entries",
34+
"format=duration",
35+
"-of",
36+
"default=noprint_wrappers=1:nokey=1",
37+
input_path,
38+
]
39+
print("\t$ " + " ".join(cmd_args))
40+
return AudioMetadata(
41+
duration_sec=float(subprocess.check_output(cmd_args, encoding="utf-8"))
42+
)
43+
44+
2445
def ffprobe_video(input_path: str) -> VideoMetadata:
2546
cmd_args = [
2647
"ffprobe",

retro/sadtalker.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from celeryconfig import app, setup_queues
2020
from ffmpeg_util import (
2121
ffprobe_video,
22+
ffprobe_audio,
2223
ffmpeg_read_input_frames,
2324
VideoMetadata,
2425
ffmpeg_get_writer_proc,
@@ -219,21 +220,7 @@ def sadtalker(
219220
print(subprocess.check_output(args, encoding="utf-8"))
220221
audio_path = wav_audio_path
221222
# make sure audio is not 0 seconds
222-
audio_length = float(
223-
subprocess.check_output(
224-
[
225-
"ffprobe",
226-
"-v",
227-
"error",
228-
"-show_entries",
229-
"format=duration",
230-
"-of",
231-
"default=noprint_wrappers=1:nokey=1",
232-
audio_path,
233-
],
234-
encoding="utf-8",
235-
)
236-
)
223+
audio_length = ffprobe_audio(audio_path).duration_sec
237224
if audio_length <= 0.1:
238225
raise ValueError("Audio is too short")
239226

0 commit comments

Comments
 (0)