Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created February 9, 2023 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisswarren/6f69f4f0940cac08e55043ef5d5979d4 to your computer and use it in GitHub Desktop.
Save louisswarren/6f69f4f0940cac08e55043ef5d5979d4 to your computer and use it in GitHub Desktop.
Trim audio files with fade
#!/bin/sh
# Usage:
# trim FILE START END FADE_IN FADE_OUT
# 1 2 3 4 5
# Trim the file between START and END, with fade in and out, and
# 2 seconds of silence after
dur=`expr "${3%:*}" \* 60 + "${3#*:}" - "${2%:*}" \* 60 - "${2#*:}"`
fo=`expr "$dur" - $5`
ffmpeg \
-ss "$2" -to "$3" \
-i "$1" \
-af "afade=t=in:st=0:d=$4,afade=t=out:st=$fo:d=$5,apad=pad_dur=2" \
-ab 320k \
-map_metadata 0 -id3v2_version 3 \
"${1%flac}mp3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment