Last active
December 10, 2024 12:23
-
-
Save oddmario/d0b2b0651af9d97ad0cba7aa35976ba0 to your computer and use it in GitHub Desktop.
Extract the original audio track from a video using ffmpeg + ffprobe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: