summaryrefslogtreecommitdiff
path: root/dot/local/bin/webm2opus
blob: 07688dd0a4d4a2fefdf64e62a979dc706c7c91c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
OVERWRITE=
printf_ds()
{
  local s
  [ "$2" = 1 ] && s= || s=s
  printf "$1" "$2" "$s"
}

fail=0
skip=0
for f in "$@"
do
  out=${f%.webm}.opus
  if [ ! "$OVERWRITE" -a -e "$out" ]
  then
    skip=$((skip + 1))
    continue
  fi
  ffmpeg -i "$f" -c:a copy "$out" || fail=$((fail + 1))
done

if [ "$skip" -gt 0 ]
then
  printf_ds 'Warning: refused to overwrite %d file%s\n' "$skip" "$s" >&2
fi

if [ "$fail" -gt 0 ]
then
  printf_ds 'Error: ffmpeg failed to convert %d file%s\n' "$fail" >&2
  exit 1
fi