File tree Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Original file line number Diff line number Diff 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+
2445def ffprobe_video (input_path : str ) -> VideoMetadata :
2546 cmd_args = [
2647 "ffprobe" ,
Original file line number Diff line number Diff line change 1919from celeryconfig import app , setup_queues
2020from 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
You can’t perform that action at this time.
0 commit comments