Skip to content

Instantly share code, notes, and snippets.

@zrong
Created February 12, 2017 11:38
Show Gist options
  • Save zrong/f470b14dc51ecc5c62ae9d09671ba9ce to your computer and use it in GitHub Desktop.
Save zrong/f470b14dc51ecc5c62ae9d09671ba9ce to your computer and use it in GitHub Desktop.
cut a mp3 file by ffmpeg
#!/bin/bash
##############################
# cut a mp3 file
# @author rzeng
# @date 2017-02-12
# @requirements ffmpeg
##############################
if ! [ "$(which ffmpeg)" ];then
echo "Install ffmpeg first!"
exit 127
fi
time=$1
input_file=$2
output_file=$3
if [ -z "$time" ];then
echo 'Give me time!'
exit 127
fi
if ! [ -f "$input_file" ];then
echo 'Give me a input file please!'
exit 127
fi
if ! [ -f "$output_file" ];then
output_file=${input_file}.cut.mp3
fi
ffmpeg -i $input_file -t $time -acodec copy $output_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment