18
18
from typing import Final
19
19
20
20
from moviepy import AudioFileClip , VideoFileClip , concatenate_videoclips
21
+ from moviepy .video .io .ffmpeg_reader import ffmpeg_parse_infos
21
22
22
23
from open_dubbing import logger
23
24
@@ -34,16 +35,28 @@ def split_audio_video(*, video_file: str, output_directory: str) -> tuple[str, s
34
35
35
36
base_filename = os .path .basename (video_file )
36
37
filename , _ = os .path .splitext (base_filename )
38
+
39
+ infos = ffmpeg_parse_infos (
40
+ video_file ,
41
+ check_duration = True ,
42
+ fps_source = "fps" ,
43
+ decode_file = True ,
44
+ print_infos = True ,
45
+ )
46
+ logger ().info (f"i: { infos } " )
47
+
37
48
with VideoFileClip (video_file ) as video_clip , warnings .catch_warnings ():
38
- # warnings.filterwarnings("ignore", category=UserWarning)
49
+ # warnings.filterwarnings("ignore", category=UserWarning)
39
50
audio_clip = video_clip .audio
40
51
audio_output_file = os .path .join (output_directory , filename + "_audio.mp3" )
41
52
audio_clip .write_audiofile (audio_output_file , logger = None )
42
53
video_clip_without_audio = video_clip .with_audio (None )
43
54
fps = video_clip .fps or _DEFAULT_FPS
44
55
45
56
rotation_angle = getattr (video_clip , "rotation" , 0 )
46
- logger ().info (f"Rotation angle { rotation_angle } for video, type: { type (rotation_angle )} " )
57
+ logger ().info (
58
+ f"Rotation angle { rotation_angle } for video, type: { type (rotation_angle )} "
59
+ )
47
60
48
61
duration = getattr (video_clip , "duration" , 0 )
49
62
logger ().info (f"Duration { duration } , type: { type (duration )} " )
@@ -54,7 +67,7 @@ def split_audio_video(*, video_file: str, output_directory: str) -> tuple[str, s
54
67
55
68
video_output_file = os .path .join (output_directory , filename + "_video.mp4" )
56
69
video_clip_without_audio .write_videofile (
57
- video_output_file , codec = "libx264" , fps = fps # , logger=None
70
+ video_output_file , codec = "libx264" , fps = fps # , logger=None
58
71
)
59
72
return video_output_file , audio_output_file
60
73
0 commit comments