Skip to content

Instantly share code, notes, and snippets.

@riyad riyad/extract-audio.sh
Last active Nov 17, 2018

Embed
What would you like to do?
Extract audio from any media file ffmpeg can play into a new one (without converting or reencoding!)
#!/bin/sh
#
# Author: Riyad Preukschas <riyad@informatik.uni-bremen.de>
# License: Mozilla Public License 2.0
#
# Extract audio from any file ffmpeg can play (without converting or reencoding!).
if [[ $# -ne 3 ]]; then
echo "Error: wrong number of arguments"
echo "Usage: $0 -f <format> <input_file>"
echo " will extract (without converting or reencoding!) the audio from"
echo " <input_file> to a new file in the specified <format>."
echo ""
echo "OPTIONS"
echo " -f <format>"
echo " specify the format of the output file (e.g. mp3, ogg, opus, m4a)."
echo " NOTE: not all input and output formats are compatible."
exit 1
fi
if [[ "$1" == "-f" ]]; then
# $@ == -f format input_file
readonly format="$2"
readonly input_file="$3"
else
# $@ == input_file -f format
readonly format="$3"
readonly input_file="$1"
fi
readonly output_file="${input_file}.${format}"
# if the input file doesn't exists ffmpeg will complain anyway
# if the output file exists ffmpeg will ask whether it should be overwritten
ffmpeg -i "${input_file}" -vn -c:a copy "${output_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.