The issue you're encountering arises because the first interval (00:00-01:01) is being treated as silence, resulting in an empty label. To assign the first song correctly to this interval, you can prepend a 0 to the ends array. This ensures that the first interval starts at 00:00 and is associated with the first song in your songs array.
Here's how you can modify your one-liner to achieve the desired output:
songs=("Cineris Somnia" "Ivy" "Daydream" "Dust and Light" "Swaying Daisy" "Garden of Light" "The White Box" "Waiting by the Windowsill" "Charlotte's Theme" "The White Box-Broken" "A Warm Room" "Charlotte's Theme-Wither" "Wild Rose" "Marie's Theme" "Deep Forest" "Mist" "Night Carol" "False Blue" "Death of the Little Bird" "Ophelia's Theme-Darkness" "Hall of Silence" "Downstairs" "Black Insanity" "Judgment" "Decaying Corridor" "Pandora's Box" "Ophelia's Theme-Light" "Under Cloudy Skies" "Tender Black" "Neverending Dream" "Angel's Lament" "World of Ashes" "Cineris Somnia - Alone In The Ashes" "Cineris Somnia - PV Version" "Cineris Somnia - Fragile")
LC_ALL=C ends=(0 $(ffmpeg -i output.mp4 -af silencedetect=n=-50dB:d=1 -f null - 2>&1 | grep "silence_end" | awk '{gsub(",",".",$5); if($5 >=2) print int($5 + 0.5)}'))
start=0
i=0
for end in "${ends[@]}"; do
if [ "$i" -ge "${#songs[@]}" ]; then
break
fi
s_m=$((start /60))
s_s=$((start %60))
e_m=$((end /60))
e_s=$((end %60))
printf "%02d:%02d-%02d:%02d %s\n" "$s_m" "$s_s" "$e_m" "$e_s" "${songs[i]}"
start=$end
i=$((i + 1))
done
Explanation of the Changes:
-
Prepending 0 to the ends Array:
- Original Line:
ends=($(ffmpeg -i output.mp4 -af silencedetect=n=-50dB:d=1 -f null - 2>&1 | grep "silence_end" | awk '{gsub(",",".",$5); if($5 >=2) print int($5 + 0.5)}'))
- Modified Line:
ends=(0 $(ffmpeg -i output.mp4 -af silencedetect=n=-50dB:d=1 -f null - 2>&1 | grep "silence_end" | awk '{gsub(",",".",$5); if($5 >=2) print int($5 + 0.5)}'))
- Reason: By adding
0 at the beginning of the ends array, the first interval starts from 00:00 and goes up to the first detected silence end (01:01 in your case), which is then correctly labeled with the first song.
-
Resulting Output:
With this modification, your output will correctly assign the first song to the initial interval:
00:00-01:01 Cineris Somnia
01:01-03:40 Ivy
03:40-05:15 Daydream
05:15-08:14 Dust and Light
08:14-09:31 Swaying Daisy
09:31-11:10 Garden of Light
11:10-12:44 The White Box
12:44-12:51 Waiting by the Windowsill
12:51-14:41 Charlotte's Theme
14:41-16:22 The White Box-Broken
16:22-00:00 A Warm Room
00:00-34:12 Charlotte's Theme-Wither
34:12-35:11 Wild Rose
35:11-36:47 Marie's Theme
36:47-38:16 Deep Forest
38:16-39:38 Mist
39:38-41:13 Night Carol
41:13-43:17 False Blue
43:17-44:34 Death of the Little Bird
44:34-46:07 Ophelia's Theme-Darkness
46:07-47:16 Hall of Silence
47:16-48:39 Downstairs
48:39-49:58 Black Insanity
49:58-50:53 Judgment
50:53-52:16 Decaying Corridor
(Note: The specific timestamps may vary based on the actual audio content and silence detection results.)
Additional Tips:
-
Ensure Correct Shell Syntax: When writing one-liners, it's easy to introduce syntax errors. Make sure all quotes and parentheses are correctly balanced.
-
Testing: Before running the entire one-liner, consider breaking it down into smaller parts to ensure each segment works as expected.
-
Debugging: If you encounter further issues, adding echo statements or temporarily removing parts of the pipeline can help identify where the problem lies.
By making this adjustment, the first interval will now correctly display the first song, eliminating the empty label.
Final One-Liner:
songs=("Cineris Somnia" "Ivy" "Daydream" "Dust and Light" "Swaying Daisy" "Garden of Light" "The White Box" "Waiting by the Windowsill" "Charlotte's Theme" "The White Box-Broken" "A Warm Room" "Charlotte's Theme-Wither" "Wild Rose" "Marie's Theme" "Deep Forest" "Mist" "Night Carol" "False Blue" "Death of the Little Bird" "Ophelia's Theme-Darkness" "Hall of Silence" "Downstairs" "Black Insanity" "Judgment" "Decaying Corridor" "Pandora's Box" "Ophelia's Theme-Light" "Under Cloudy Skies" "Tender Black" "Neverending Dream" "Angel's Lament" "World of Ashes" "Cineris Somnia - Alone In The Ashes" "Cineris Somnia - PV Version" "Cineris Somnia - Fragile"); LC_ALL=C ends=(0 $(ffmpeg -i output.mp4 -af silencedetect=n=-50dB:d=1 -f null - 2>&1 | grep "silence_end" | awk '{gsub(",",".",$5); if($5 >=2) print int($5 + 0.5)}')); start=0; i=0; for end in "${ends[@]}"; do if [ "$i" -ge "${#songs[@]}" ]; then break; fi; s_m=$((start /60)); s_s=$((start %60)); e_m=$((end /60)); e_s=$((end %60)); printf "%02d:%02d-%02d:%02d %s\n" "$s_m" "$s_s" "$e_m" "$e_s" "${songs[i]}"; start=$end; i=$((i + 1)); done
Modify the ends array to start at 0 by prepending 0 to it. This ensures the first interval is labeled with the first song. For example:
ends=(0 $(ffmpeg -i output.mp4 -af silencedetect=n=-50dB:d=1 -f null - 2>&1 | grep "silence_end" | awk '{gsub(",",".",$5); if($5 >=2) print int($5 + 0.5)}'))
This change will make the output start with "00:00-01:01 Cineris Somnia" as desired.