Skip to content

Instantly share code, notes, and snippets.

@oddmario
Last active December 10, 2024 12:23
Show Gist options
  • Save oddmario/d0b2b0651af9d97ad0cba7aa35976ba0 to your computer and use it in GitHub Desktop.
Save oddmario/d0b2b0651af9d97ad0cba7aa35976ba0 to your computer and use it in GitHub Desktop.
Extract the original audio track from a video using ffmpeg + ffprobe
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_file> <output_file>"
exit 1
fi
input="$1"
output="$2"
# Find the "original" audio track dynamically
track=$(ffprobe -i "$input" -v error -select_streams a \
-show_entries stream=index:stream_tags=title -of csv=p=0 | grep -i "original" | cut -d ',' -f1)
if [ -z "$track" ]; then
echo "No 'original' audio track found!"
exit 1
fi
# Use the detected audio track index
ffmpeg -i "$input" -vn -acodec aac -map 0:"$track" "$output"
echo "File processed successfully: $output"
@oddmario
Copy link
Author

Example usage:

./extract_original_audio.sh MyVideo.mkv audio.aac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment