-
Notifications
You must be signed in to change notification settings - Fork 2
/
strip-audio
executable file
·93 lines (73 loc) · 2.08 KB
/
strip-audio
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# SPDX-FileCopyrightText: 2021 - 2024 sudorook <daemon@nullcodon.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
set -Eeuo pipefail
ROOT="$(dirname "${0}")"
source "${ROOT}"/globals
! check_command ffmpeg find xargs && exit 3
#
# Functions
#
function do_strip_flac {
local in="${1}"
local tmp
tmp=$(mktemp)
trap 'rm -vf "${tmp}"' INT RETURN ERR TERM
ffmpeg -v warning -i file:"${in}" -c copy -f ogg - |
ffmpeg -v warning -i - \
-map_metadata -1 -map 0:a -c:a copy -vn \
-fflags +bitexact -flags:a +bitexact \
-f flac file:"${tmp}" -y
mv "${tmp}" "${in}"
}
export -f do_strip_flac
function do_strip_mp3 {
local in="${1}"
local tmp
tmp=$(mktemp)
trap 'rm -vf "${tmp}"' INT RETURN ERR TERM
ffmpeg -v warning -i file:"${in}" -c copy -f avi - |
ffmpeg -v warning -i - \
-map_metadata -1 -map 0:a -c:a copy \
-fflags +bitexact -flags:v +bitexact -flags:a +bitexact \
-f mp3 file:"${tmp}" -y
mv "${tmp}" "${in}"
}
export -f do_strip_mp3
function strip_wrapper {
local ext="${1##*.}"
case "${ext,,}" in
flac)
do_strip_flac "${1}"
;;
mp3)
do_strip_mp3 "${1}"
;;
esac
}
export -f strip_wrapper
#
# Main
#
show_header "Stripping ${*@Q}..."
if [ $# -eq 0 ]; then
show_error "ERROR: No path(s) provided. Exiting."
exit 3
fi
find "${@}" -type f \( -iname "*.flac" -o -iname "*.mp3" \) -print0 |
xargs -0 -I{} -P "$(nproc)" bash -c 'strip_wrapper "{}"'
sync