summaryrefslogtreecommitdiff
path: root/ar/.local/bin/v2m
blob: b2f051098f5cf5a7a60a57bdb8897c5a5651b705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

# Extract MP3 audio from a video file

if [ $# -eq 0 ]; then
    echo "Usage: video2mp3 <input_file> [output_file]"
    echo "Example: video2mp3 video.mp4"
    echo "Example: video2mp3 video.mp4 audio.mp3"
    exit 1
fi

INPUT="$1"

# Check that the file exists
if [ ! -f "$INPUT" ]; then
    echo "Error: file not found: $INPUT"
    exit 1
fi

# Determine the output filename
if [ $# -eq 2 ]; then
    OUTPUT="$2"
else
    # Strip the extension from the input file and append .mp3
    OUTPUT="${INPUT%.*}.mp3"
fi

echo "Converting: $INPUT -> $OUTPUT"

# Extract mp3 with ffmpeg (high quality: 320kbps)
ffmpeg -i "$INPUT" -vn -acodec libmp3lame -b:a 320k "$OUTPUT"

if [ $? -eq 0 ]; then
    echo "✓ Done: $OUTPUT"
else
    echo "✗ An error occurred"
    exit 1
fi