Thursday, September 14, 2023

webm to mp3 bash conversion

 
#!/bin/bash

# Check if ffmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
    echo "ffmpeg is not installed. Please install it."
    exit 1
fi

# Loop through all .webm files in the current directory
for webm_file in *.webm; do
    # Check if there are any .webm files
    if [ -e "$webm_file" ]; then
        # Extract the base filename without extension
        base_filename="${webm_file%.*}"

        # Convert .webm to .mp3 using ffmpeg
        ffmpeg -i "$webm_file" -vn -acodec libmp3lame -q:a 4 "$base_filename.mp3"

        # Check if the conversion was successful
        if [ $? -eq 0 ]; then
            echo "Conversion of $webm_file to $base_filename.mp3 successful."

            # Remove the original .webm file
            rm -f "$webm_file"
            echo "$webm_file deleted."
        else
            echo "Conversion of $webm_file to $base_filename.mp3 failed."
        fi
    fi
done

No comments:

Post a Comment