-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
import os | ||
|
||
import moviepy.editor as mp | ||
from dotenv import load_dotenv | ||
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip | ||
|
||
|
||
def cut_and_save(movie_path: str, start: float, end: float, target_name: str) -> None: | ||
"""This function cuts a video from the start to the end time and saves it as target_name. | ||
Args: | ||
movie_path (str): The path to the video file. | ||
start (float): The start time in seconds. | ||
end (float): The end time in seconds. | ||
target_name (str): The file name of the new video file. | ||
Returns: | ||
None | ||
""" | ||
return ffmpeg_extract_subclip(movie_path, start, end, targetname=target_name) | ||
|
||
|
||
def import_as_clip(path_to_video: str) -> mp.VideoClip: | ||
def import_as_clip(path_to_video: str) -> mp.VideoFileClip: | ||
"""Imports a video file as a VideoFileClip object. | ||
Args: | ||
path_to_video (str): Path to a video file. | ||
Returns: | ||
mp.VideoFileClip: VideoFileClip object. | ||
""" | ||
return mp.VideoFileClip(path_to_video) | ||
|
||
|
||
# Splits a file into its individual parts using spleeter | ||
# Does not work above 700 seconds | ||
def separate_voice_and_music(file: str) -> None: # Do not work above 700 seconds | ||
os.system('spleeter separate -d 700.0 -o ../../../ -f "{instrument}/{filename}.{codec}" ' + file) | ||
|
||
|
||
def extract_audio_from_movie(file: str, extension: str = '.wav') -> None: | ||
clip: MoviePyClip = import_as_clip(file) | ||
"""Extract the audio from a movie and save it to a file. | ||
The audio is saved in the same directory as the movie. | ||
Args: | ||
file (str): The name of the movie file to extract the audio from. | ||
extension (str): The file extension of the audio file to save. | ||
""" | ||
clip = import_as_clip(file) | ||
clip.audio.write_audiofile(file.split(sep='.')[0] + extension) |