-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchaptersplit
executable file
·101 lines (74 loc) · 4.2 KB
/
chaptersplit
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
94
95
96
97
98
99
100
#!/bin/bash
# Original code from: http://crunchbang.org/forums/viewtopic.php?id=38748#p414992
# m4bronto
# Chapter #0:0: start 0.000000, end 1290.013333
# first _ _ start _ end
# nb: the swp file that editscript relies on is provided by nano
editscript(){
local scriptpath script path swp; scriptpath=$(realpath "$0" 2>/dev/null); script="${scriptpath##*/}"; path="${scriptpath%/*}"; swp="$path/.$script.swp"
[[ ! -e "$swp" ]] && printf "\n\n%s\n\n" "$swp" && (/usr/bin/nano "$scriptpath") && exit
printf "\n%s is already being edited.\n%s exists; try fg or look in another window.\n" "$scriptpath" "$swp"; exit ;}
pause(){ read -rp "$*" < /dev/tty; }
[[ "$1" == @(edit|e|-e) ]] && editscript
outputdir="/dev/shm/cache/convert"
START=1
edit=0
scriptname="$(realpath $0)"
basename "$PWD"
title="FDR"
inext="mp3"
outext="mp3"
inext="opus"
outext="opus"
inext="m4?"
outext="m4a"
stamp=$(date +%s)
#compgen -A file "*$inext"
function pause(){
read -p "$*"
}
if [[ $# -eq 0 ]] || [[ "$1" = "edit" ]]; then
edit="true"
fi
echo "this is the value of $1"
if "${edit:-false}"; then editscript; fi
mkdir -p "$outputdir"
while [ $# -gt 0 ]; do
ffmpeg -i "$1" 2> ".tmp$stamp"
n="$START"
while read -r first _ _ start _ end; do
if [[ $first = Chapter ]]; then
read # discard line with Metadata:
read _ _ chapter
if [[ "$n" -lt 10 ]]; then partnum="0$n"; else partnum="$n"; fi
# ffmpeg -nostdin -activation_bytes a0737c04 -vsync 2 -i "$1" -ss "${start%?}" -to "$end" -vn -b:a 17k -acodec libopus "$title -- $chapter.opus" </dev/null
# ffmpeg -n -nostdin -hide_banner -stats -vsync 2 -i "$1" -filter_complex "compand=attacks=0:decays=0.12:points=-70/-900|-40/-90|-35/-37|-21/-18|1/-1|20/-1:soft-knee=0.03:gain=1.00:volume=-90, firequalizer=gain_entry='entry(0,-99);entry(140,0);entry(1000,0);entry(8000,1);entry(10500,4);entry(12000,5);entry(14500,-4);entry(19000,-20)', volume=1.0" -ss "${start%?}" -to "$end" -vn -b:a 17k -acodec libopus "$title -- $chapter.opus" </dev/null
###copy:
# ffmpeg -n -nostdin -hide_banner -stats -vsync 2 -ss "${start%?}" -to "$end" -i "$1" -vn -codec copy "$title -- $chapter.$outext" </dev/null
# ffmpeg -n -nostdin -hide_banner -stats -vsync 2 -ss "${start%?}" -to "$end" -i "$1" -vn -codec copy "/dev/shm/cache/convert/$title -- Part $partnum: $chapter.$outext" </dev/null
ffmpeg -n -nostdin -hide_banner -stats -ss "${start%?}" -to "$end" -i "$1" -vn -codec copy "/dev/shm/cache/convert/$title -- Part $partnum: $chapter.$outext" </dev/null
#
#1. Audio Files:
#For audio-only files (e.g., MP3, AAC, WAV), the concept of frames per second (FPS) doesn't apply because audio is continuous and not frame-based like video.
#The -fps_mode option is used to manage the frame rate when dealing with video streams. It's not relevant to audio-only files, so you can safely omit it in most cases when working with audio.
###convert:
#ffmpeg -n -nostdin -hide_banner -stats -vsync 2 -filter_complex "compand=attacks=0:decays=0.12:points=-70/-900|-40/-90|-35/-37|-21/-18|1/-1|20/-1:soft-knee=0.03:gain=1.00:volume=-90, firequalizer=gain_entry='entry(0,-99);entry(140,0);entry(1000,0);entry(8000,1);entry(10500,4);entry(12000,5);entry(14500,-4);entry(19000,-20)', volume=1.0" -ss "${start%?}" -to "$end" -i "$1" -vn -b:a 17k -acodec libopus "/dev/shm/cache/$title -- $chapter.opus" </dev/null
### convert audible: ffmpeg -n -nostdin -activation_bytes a0737c04 -hide_banner -stats -vsync 2 -filter_complex "compand=attacks=0:decays=0.12:points=-70/-900|-40/-90|-35/-37|-21/-18|1/-1|20/-1:soft-knee=0.03:gain=1.00:volume=-90, firequalizer=gain_entry='entry(0,-99);entry(140,0);entry(1000,0);entry(8000,1);entry(10500,4);entry(12000,5);entry(14500,-4);entry(19000,-20)', volume=1.0" -ss "${start%?}" -to "$end" -i "$1" -vn -b:a 17k -acodec libopus "/dev/shm/cache/$title -- $chapter.opus" </dev/null
(( n=n+1 ))
fi
done <".tmp$stamp"
rm ".tmp$stamp"
shift
done
for i in "$title -- Chapter "?.opus;
do
mv "$i" "${i/Chapter /Chapter 0}";
done
if [ -n "$1" ];
then
echo mediaduration "${1#*.}" `mediaduration "${1#*.}"`
echo mediaduration opus `mediaduration opus`
else
echo mediaduration "${file#*.}" `mediaduration "${file#*.}"`
echo mediaduration opus `mediaduration opus`
fi