Commit
·
21b498c
1
Parent(s):
3fc2a44
enhancement: bump audio format to m4a (mp3 deprecated)
Browse files
cli.py
CHANGED
|
@@ -2,7 +2,7 @@ from argparse import ArgumentParser
|
|
| 2 |
from utils.download_video import download_video
|
| 3 |
from utils.transcriber import transcriber
|
| 4 |
from utils.subtitler import subtitler
|
| 5 |
-
from utils.
|
| 6 |
import logging, os
|
| 7 |
from tqdm import tqdm
|
| 8 |
|
|
@@ -28,8 +28,8 @@ def main(video_url:str,
|
|
| 28 |
if video_url != None:
|
| 29 |
INVIDEO_PATH = download_video(video_url, INVIDEO_DIR, invideo_filename)
|
| 30 |
pbar.update(25)
|
| 31 |
-
INAUDIO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.
|
| 32 |
-
|
| 33 |
pbar.update(25)
|
| 34 |
if not os.path.exists(SRT_PATH):
|
| 35 |
transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
|
|
@@ -38,9 +38,9 @@ def main(video_url:str,
|
|
| 38 |
pbar.update(25)
|
| 39 |
return
|
| 40 |
INVIDEO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.mp4")
|
| 41 |
-
INAUDIO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.
|
| 42 |
if not os.path.exists(INAUDIO_PATH):
|
| 43 |
-
|
| 44 |
pbar.update(50)
|
| 45 |
if not os.path.exists(SRT_PATH):
|
| 46 |
transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
|
|
|
|
| 2 |
from utils.download_video import download_video
|
| 3 |
from utils.transcriber import transcriber
|
| 4 |
from utils.subtitler import subtitler
|
| 5 |
+
from utils.convert_video_to_audio import convert_video_to_audio
|
| 6 |
import logging, os
|
| 7 |
from tqdm import tqdm
|
| 8 |
|
|
|
|
| 28 |
if video_url != None:
|
| 29 |
INVIDEO_PATH = download_video(video_url, INVIDEO_DIR, invideo_filename)
|
| 30 |
pbar.update(25)
|
| 31 |
+
INAUDIO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.m4a")
|
| 32 |
+
convert_video_to_audio(INVIDEO_PATH,INAUDIO_PATH)
|
| 33 |
pbar.update(25)
|
| 34 |
if not os.path.exists(SRT_PATH):
|
| 35 |
transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
|
|
|
|
| 38 |
pbar.update(25)
|
| 39 |
return
|
| 40 |
INVIDEO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.mp4")
|
| 41 |
+
INAUDIO_PATH = os.path.join(INVIDEO_DIR, f"{invideo_filename}.m4a")
|
| 42 |
if not os.path.exists(INAUDIO_PATH):
|
| 43 |
+
convert_video_to_audio(INVIDEO_PATH,INAUDIO_PATH)
|
| 44 |
pbar.update(50)
|
| 45 |
if not os.path.exists(SRT_PATH):
|
| 46 |
transcriber(INAUDIO_PATH, SRT_PATH, max_words_per_line)
|
utils/{convert_mp4_to_mp3.py → convert_video_to_audio.py}
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
from moviepy.editor import VideoFileClip
|
| 2 |
|
| 3 |
-
def
|
| 4 |
# Load the video file
|
| 5 |
video_clip = VideoFileClip(mp4_file_path)
|
| 6 |
|
| 7 |
# Extract the audio from the video clip
|
| 8 |
audio_clip = video_clip.audio
|
| 9 |
|
| 10 |
-
# Save the audio clip as an
|
| 11 |
-
audio_clip.write_audiofile(
|
| 12 |
|
| 13 |
# Close the clips
|
| 14 |
audio_clip.close()
|
| 15 |
video_clip.close()
|
| 16 |
-
return
|
|
|
|
| 1 |
from moviepy.editor import VideoFileClip
|
| 2 |
|
| 3 |
+
def convert_video_to_audio(mp4_file_path, m4a_file_path):
|
| 4 |
# Load the video file
|
| 5 |
video_clip = VideoFileClip(mp4_file_path)
|
| 6 |
|
| 7 |
# Extract the audio from the video clip
|
| 8 |
audio_clip = video_clip.audio
|
| 9 |
|
| 10 |
+
# Save the audio clip as an m4a file
|
| 11 |
+
audio_clip.write_audiofile(m4a_file_path, codec='aac')
|
| 12 |
|
| 13 |
# Close the clips
|
| 14 |
audio_clip.close()
|
| 15 |
video_clip.close()
|
| 16 |
+
return m4a_file_path
|
utils/process_video.py
CHANGED
|
@@ -26,7 +26,7 @@ def process_video(invideo_filename:str,
|
|
| 26 |
subtitler(invideo_filename, srt_path, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
|
| 27 |
return OUTVIDEO_PATH
|
| 28 |
logging.info("Converting Video to Audio")
|
| 29 |
-
INAUDIO_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.
|
| 30 |
if not os.path.exists(INAUDIO_PATH):
|
| 31 |
convert_mp4_to_mp3(invideo_filename, INAUDIO_PATH)
|
| 32 |
SRT_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.srt")
|
|
|
|
| 26 |
subtitler(invideo_filename, srt_path, OUTVIDEO_PATH, fontsize, font, bg_color, text_color)
|
| 27 |
return OUTVIDEO_PATH
|
| 28 |
logging.info("Converting Video to Audio")
|
| 29 |
+
INAUDIO_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.m4a")
|
| 30 |
if not os.path.exists(INAUDIO_PATH):
|
| 31 |
convert_mp4_to_mp3(invideo_filename, INAUDIO_PATH)
|
| 32 |
SRT_PATH = os.path.abspath(f"{invideo_filename.split('.')[0]}.srt")
|