summaryrefslogtreecommitdiff
path: root/bin/split-media-files.sh
blob: efa9c3bae75781d32ec924ab71d7bc453630d7fa (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="$(basename $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}" -metadata title="%03d" -c copy -f segment -segment_time $max_duration \
       "${base}-%03d.${extension}"