generated from thinkode/modelRepository
initial commit and version 1.0
This commit is contained in:
46
audioExtractor.py
Normal file
46
audioExtractor.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from moviepy import VideoFileClip
|
||||
import shutil
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import json
|
||||
from log import log_step
|
||||
from genericpath import exists
|
||||
|
||||
try:
|
||||
# Create the parser
|
||||
parser = argparse.ArgumentParser(description="dubstudio audio extraction tool (v1.0) - V. BOULANGER - 2025")
|
||||
|
||||
# Options definition
|
||||
parser.add_argument('-v', '--video', help='Video file to process', default='video.mp4')
|
||||
parser.add_argument('-o', '--output', help='Output audio file name', default='audio.wav')
|
||||
parser.add_argument('-f', '--folder', help="Output folder name where the WAV audio files will be stored", default='artifacts')
|
||||
|
||||
# Options analyzing
|
||||
args = parser.parse_args()
|
||||
|
||||
log_step('init', 100, {
|
||||
"videoFile": args.video,
|
||||
"outputFolder": args.folder,
|
||||
"outputFile": args.output
|
||||
})
|
||||
|
||||
# Create the temporary directory
|
||||
if not exists(args.folder):
|
||||
os.mkdir(args.folder)
|
||||
|
||||
log_step('directoryCreation', 100, "creating the output directory")
|
||||
|
||||
# Conversion to audio only
|
||||
video = VideoFileClip(args.video)
|
||||
video.audio.write_audiofile("{}/{}".format(args.folder, args.output))
|
||||
log_step('audio_extraction', 100, "extracting the audio from the video")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
# Delete the output folder
|
||||
if exists(args.folder):
|
||||
shutil.rmtree(args.folder)
|
||||
log_step("exit", 100, "program exit")
|
||||
|
||||
except Exception as e:
|
||||
log_step("error", 100, str(e))
|
||||
Reference in New Issue
Block a user