Spaces:
Runtime error
Runtime error
| from moviepy.editor import VideoFileClip | |
| def extract_track(input_file, track_name, output_file): | |
| """ | |
| Extracts a specific audio track from a multitrack MP4 file and saves it as a separate file. | |
| Parameters: | |
| input_file (str): The path to the input multitrack MP4 file. | |
| track_name (str): The name of the track to be extracted (e.g., 'vocals', 'drums', 'bass', 'other'). | |
| output_file (str): The path to save the extracted track. | |
| Returns: | |
| None | |
| """ | |
| try: | |
| clip = VideoFileClip(input_file) | |
| selected_track = clip.audio.subclip(0, clip.duration) | |
| selected_track.write_audiofile(output_file) | |
| clip.close() | |
| print(f"Track '{track_name}' extracted successfully and saved as '{output_file}'.") | |
| except Exception as e: | |
| print("An error occurred:", e) | |
| # Example usage: | |
| extract_track("path/to/multitrack_file.mp4", "vocals", "output_vocals.wav") | |