nnn/plugins/ringtone

37 lines
946 B
Plaintext
Raw Normal View History

2019-06-21 17:06:34 +00:00
#!/usr/bin/env sh
# Description: Create an mp3 ringtone out of an audio file in any format
# Needs user to provide start and end where to cut the file
# Input file audio.ext results in audio_ringtone.mp3
2019-10-25 02:20:54 +00:00
#
# Tip: To convert a complete media file, set start as 0 and
# the runtime of the file as end.
#
2020-05-06 05:29:57 +00:00
# Dependencies: date, ffmpeg
2019-06-21 17:06:34 +00:00
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
2019-06-27 01:38:02 +00:00
if [ -n "$1" ]; then
2019-11-21 20:44:25 +00:00
printf "start (hh:mm:ss): "
read -r start
2019-06-27 01:38:02 +00:00
st=$(date -d "$start" +%s) || exit 1
2019-06-21 17:06:34 +00:00
2019-11-21 20:44:25 +00:00
printf "end (hh:mm:ss): "
read -r end
2019-06-27 01:38:02 +00:00
et=$(date -d "$end" +%s) || exit 1
2019-06-21 17:06:34 +00:00
2019-11-21 20:44:25 +00:00
if [ "$st" -ge "$et" ]; then
printf "error: start >= end "
read -r _
2019-06-21 17:06:34 +00:00
exit 1
fi
2019-11-21 20:44:25 +00:00
interval=$(( et - st ))
2019-06-21 17:06:34 +00:00
2019-06-27 01:38:02 +00:00
outfile=$(basename "$1")
2019-06-21 17:06:34 +00:00
outfile="${outfile%.*}"_ringtone.mp3
ffmpeg -i "$1" -ss "$start" -t "$interval" -vn -sn -acodec libmp3lame -q:a 2 "$outfile"
fi