EloiStree / 2024_03_19_HackWowGroup

Hack and Wow 2024 Note drop.
0 stars 0 forks source link

Topic: Turn video to mp3 from arguments #3

Open EloiStree opened 5 months ago

EloiStree commented 5 months ago
## python video_to_audio.py input_video.mp4 output_audio.mp3

import argparse
from moviepy.editor import VideoFileClip

def extract_audio(input_path, output_path):
    try:
        video_clip = VideoFileClip(input_path)
        audio_clip = video_clip.audio
        audio_clip.write_audiofile(output_path)
        print(f"Audio extracted from {input_path} to {output_path}")
    except FileNotFoundError:
        print("Error: Input file not found.")
    except PermissionError:
        print("Error: Permission denied to access input or create output file.")
    except Exception as e:
        print(f"An error occurred: {e}")

def main():
    parser = argparse.ArgumentParser(description="Extract audio from a video file.")
    parser.add_argument("input_path", help="Path to the input video file")
    parser.add_argument("output_path", help="Path to the output audio file")
    args = parser.parse_args()

    extract_audio(args.input_path, args.output_path)

if __name__ == "__main__":
    main()