summaryrefslogtreecommitdiff
path: root/bin/split-media-files.sh
blob: 5f79c81e24f092d9de89628dccb47b26d57bf64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!bash

max_duration=$((4*3600))

if [[ $# -ne 1 ]]; then
    echo 1>&2 "Usage: $0 <media-file>"
    exit 1
fi

input_file="$1"

base="$(echo $input_file | perl -pe 's/(.*)\.([^.]*)$/$1/')"
extension="$(echo $input_file | perl -pe 's/(.*)\.([^.]*)$/$2/')"
if [[ $extension == "m4b" ]]; then
  extension=m4a
fi

ffmpeg -i "${input_file}" -c copy -f segment -segment_time $max_duration \
       "${base}-%03d.${extension}"