-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcompile-slideshow.js
More file actions
249 lines (219 loc) · 10.2 KB
/
Copy pathcompile-slideshow.js
File metadata and controls
249 lines (219 loc) · 10.2 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* eslint-disable no-console */
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import { wallpapers } from './src/components/wolves/wallpapers-list.ts'
import { trackZeroBeatCuts, trackZeroBeatCutsWithPickup } from './src/data/wolves-track-zero-beats.ts'
import { TRACK_ZERO_PRESENTATION_SECTIONS } from './src/data/wolves-track-zero-manifest.ts'
import { rezaContributorSlideId } from './src/data/wolves-track-zero-slides.ts'
function deterministicShuffle(array, seed = 42) {
const copy = [...array]
let currentSeed = seed
const random = () => {
const x = Math.sin(currentSeed++) * 10000
return x - Math.floor(x)
}
for (let i = copy.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[copy[i], copy[j]] = [copy[j], copy[i]]
}
return copy
}
// Compute the exact same timelineSlides logic from WolvesComicReader.vue
const localShowcase = wallpapers.filter((wp) => {
const isPeople = wp.name?.includes('/people/') || wp.dayName?.includes('/people/') || wp.nightName?.includes('/people/')
return !isPeople
}).map(wp => ({
id: wp.name || wp.dayName || wp.nightName || '',
isLocal: true,
path: wp.name,
title: wp.title,
type: wp.type,
dayName: wp.dayName,
nightName: wp.nightName
}))
const localPeople = wallpapers.filter((wp) => {
const isPeople = wp.name?.includes('/people/') || wp.dayName?.includes('/people/') || wp.nightName?.includes('/people/')
return isPeople
}).map(wp => ({
id: wp.name || wp.dayName || wp.nightName || '',
isLocal: true,
path: wp.name,
title: wp.title,
type: wp.type,
dayName: wp.dayName,
nightName: wp.nightName
}))
const daynightShowcase = localShowcase.filter(wp => wp.type === 'daynight')
const normalShowcase = localShowcase.filter(wp => wp.type !== 'daynight')
const andyAdvisorTarget = 'wolves/people/Bluefin Advisor Andy Randall.jpg'
const andyAdvisorIndex = localPeople.findIndex(wp => wp.id === andyAdvisorTarget)
let andyAdvisorPhoto = null
if (andyAdvisorIndex !== -1) {
andyAdvisorPhoto = localPeople.splice(andyAdvisorIndex, 1)[0]
}
const bluefinGroupTargets = [
'wolves/people/sherman-m2.webp',
'wolves/people/NOT John Bazzite.jpg',
'wolves/people/hikari.JPG',
'wolves/people/hikari2.JPG',
'wolves/people/jorge-bluefin.webp',
]
const bluefinGroupPhotos = bluefinGroupTargets
.map(id => localPeople.find(wp => wp.id === id))
.filter(Boolean)
for (const photo of bluefinGroupPhotos) {
const index = localPeople.indexOf(photo)
if (index !== -1) {
localPeople.splice(index, 1)
}
}
const rezaIndex = localPeople.findIndex(wp => wp.id === rezaContributorSlideId)
let rezaPhoto = null
if (rezaIndex !== -1) {
rezaPhoto = localPeople.splice(rezaIndex, 1)[0]
}
const pivotalTarget = 'wolves/people/kubecon-54927705495.webp'
const targetIndex = localPeople.findIndex(wp => wp.id === pivotalTarget)
let pivotalPhoto = null
if (targetIndex !== -1) {
pivotalPhoto = localPeople.splice(targetIndex, 1)[0]
}
const bkTarget = 'wolves/people/bketelsen.webp'
const bkTargetIndex = localPeople.findIndex(wp => wp.id === bkTarget)
let bkPhoto = null
if (bkTargetIndex !== -1) {
bkPhoto = localPeople.splice(bkTargetIndex, 1)[0]
}
const heartTarget = 'wolves/people/kubecon-55168460993.webp'
const heartTargetIndex = localPeople.findIndex(wp => wp.id === heartTarget)
let heartPhoto = null
if (heartTargetIndex !== -1) {
heartPhoto = localPeople.splice(heartTargetIndex, 1)[0]
}
const finaleTarget = 'wolves/people/kubecon-55164466314.webp'
const finaleTargetIndex = localPeople.findIndex(wp => wp.id === finaleTarget)
let finalePhoto = null
if (finaleTargetIndex !== -1) {
finalePhoto = localPeople.splice(finaleTargetIndex, 1)[0]
}
const shuffledDaynight = deterministicShuffle(daynightShowcase, 101)
const shuffledNormalShowcase = deterministicShuffle(normalShowcase, 202)
const shuffledPeople = deterministicShuffle(localPeople, 303)
const result = []
let currentTime = 0
// 1. Ambient Intro [0, 42]
const dnPool = shuffledDaynight.slice(0, 5)
const sec1Cuts = trackZeroBeatCuts(currentTime, TRACK_ZERO_PRESENTATION_SECTIONS.ambientIntro.endTime, dnPool.length, TRACK_ZERO_PRESENTATION_SECTIONS.ambientIntro.beatGroups)
for (const [index, item] of dnPool.entries()) {
const endTime = sec1Cuts[index]
result.push({ ...item, startTime: currentTime, duration: endTime - currentTime, endTime })
currentTime = endTime
}
// 2. Heavy Driving Verse 1 [42, 127]
const normalPool1 = shuffledNormalShowcase.slice(0, 22)
const sec2Cuts = trackZeroBeatCuts(currentTime, TRACK_ZERO_PRESENTATION_SECTIONS.drivingVerse.endTime, normalPool1.length, TRACK_ZERO_PRESENTATION_SECTIONS.drivingVerse.beatGroups)
for (const [index, item] of normalPool1.entries()) {
const endTime = sec2Cuts[index]
result.push({ ...item, startTime: currentTime, duration: endTime - currentTime, endTime })
currentTime = endTime
}
// 3. Heavy Chorus 1 [127, 229]
const normalPool2 = shuffledNormalShowcase.slice(22, 39)
const peoplePool1 = [
...bluefinGroupPhotos,
...(rezaPhoto ? [rezaPhoto] : []),
...(andyAdvisorPhoto ? [andyAdvisorPhoto] : []),
...shuffledPeople.slice(0, 15 - bluefinGroupPhotos.length - (rezaPhoto ? 1 : 0) - (andyAdvisorPhoto ? 1 : 0)),
]
const sec3Items = [...normalPool2, ...peoplePool1]
const sec3Cuts = trackZeroBeatCuts(currentTime, TRACK_ZERO_PRESENTATION_SECTIONS.contributorChorus.endTime, sec3Items.length, TRACK_ZERO_PRESENTATION_SECTIONS.contributorChorus.beatGroups)
for (const [index, item] of sec3Items.entries()) {
const endTime = sec3Cuts[index]
result.push({ ...item, startTime: currentTime, duration: endTime - currentTime, endTime })
currentTime = endTime
}
// 4. Chanting Bridge [229, 277]
const peoplePool2 = shuffledPeople.slice(15, 39)
const sec4Cuts = trackZeroBeatCutsWithPickup(currentTime, TRACK_ZERO_PRESENTATION_SECTIONS.chantingBridge.pickupTime, TRACK_ZERO_PRESENTATION_SECTIONS.chantingBridge.endTime, peoplePool2.length, ...TRACK_ZERO_PRESENTATION_SECTIONS.chantingBridge.beatGroups)
for (const [index, item] of peoplePool2.entries()) {
const endTime = sec4Cuts[index]
result.push({ ...item, startTime: currentTime, duration: endTime - currentTime, endTime })
currentTime = endTime
}
// 5. Heavy Build-Up [277, 345]
const peoplePool3 = shuffledPeople.slice(39, 73)
if (heartPhoto) {
peoplePool3.splice(21, 0, heartPhoto)
}
const sec5Cuts = trackZeroBeatCuts(currentTime, TRACK_ZERO_PRESENTATION_SECTIONS.heavyBuild.endTime, peoplePool3.length, TRACK_ZERO_PRESENTATION_SECTIONS.heavyBuild.beatGroups)
for (const [index, item] of peoplePool3.entries()) {
const endTime = sec5Cuts[index]
result.push({ ...item, startTime: currentTime, duration: endTime - currentTime, endTime })
currentTime = endTime
}
// 6. Fast Solo Climax & Outro [345, 423]
if (pivotalPhoto) {
const freezeDuration = 5.5
result.push({ ...pivotalPhoto, startTime: currentTime, duration: freezeDuration, endTime: currentTime + freezeDuration })
currentTime += freezeDuration
}
if (bkPhoto) {
const freezeDuration = 8.5
result.push({ ...bkPhoto, startTime: currentTime, duration: freezeDuration, endTime: currentTime + freezeDuration })
currentTime += freezeDuration
}
const peoplePool4 = shuffledPeople.slice(73)
const finaleStartTime = TRACK_ZERO_PRESENTATION_SECTIONS.finaleBarrage.endTime
const sec6BaseDuration = (finaleStartTime - currentTime) / peoplePool4.length
for (const item of peoplePool4) {
const duration = sec6BaseDuration
result.push({ ...item, startTime: currentTime, duration, endTime: currentTime + duration })
currentTime += duration
}
if (finalePhoto) {
result.push({ ...finalePhoto, startTime: currentTime, duration: 423 - currentTime, endTime: 423 })
}
// Build concat demuxer manifest so FFmpeg only opens one image stream at a time
const concatEntries = []
for (const slide of result) {
const relPath = slide.type === 'daynight' ? slide.dayName : slide.path
const fullPath = path.join(import.meta.dirname, 'public', 'img', 'wallpapers', relPath)
if (fs.existsSync(fullPath)) {
concatEntries.push({ path: fullPath, duration: slide.duration.toFixed(6) })
}
else {
console.warn(`Warning: file not found ${fullPath}`)
}
}
const audioPath = path.join(import.meta.dirname, 'track0.m4a')
const concatFilePath = path.join(import.meta.dirname, '.tmp-wolves-slides.ffconcat')
const outputPath = '/var/home/jorge/Videos/wolves-first-song-1440p.mp4'
if (concatEntries.length === 0) {
throw new Error('No valid wallpaper slides found for rendering')
}
const ffconcatLines = ['ffconcat version 1.0']
for (const entry of concatEntries) {
const escapedPath = entry.path.split('\'').join('\'\\\'\'')
ffconcatLines.push(`file '${escapedPath}'`)
ffconcatLines.push(`duration ${entry.duration}`)
}
// Repeat final file per concat demuxer duration rules.
const finalEscapedPath = concatEntries[concatEntries.length - 1].path.split('\'').join('\'\\\'\'')
ffconcatLines.push(`file '${finalEscapedPath}'`)
fs.writeFileSync(concatFilePath, `${ffconcatLines.join('\n')}\n`, 'utf8')
console.log('Compiling offline-native 1440p high-quality VAAPI video for YouTube...')
const vaapiCmd = `systemd-run --user --scope -p MemoryHigh=22G -p MemoryMax=28G ffmpeg -y -safe 0 -f concat -i "${concatFilePath}" -i "${audioPath}" -vaapi_device /dev/dri/renderD128 -vf "scale=2560:1440:force_original_aspect_ratio=decrease,pad=2560:1440:(ow-iw)/2:(oh-ih)/2,setsar=1,format=nv12,hwupload" -map 0:v:0 -map 1:a:0 -c:v h264_vaapi -qp 18 -g 120 -rc_mode CQP -bf 2 -c:a aac -b:a 192k -movflags +faststart -shortest "${outputPath}"`
const vp9FallbackCmd = `systemd-run --user --scope -p MemoryHigh=22G -p MemoryMax=28G ffmpeg -y -safe 0 -f concat -i "${concatFilePath}" -i "${audioPath}" -vf "scale=2560:1440:force_original_aspect_ratio=decrease,pad=2560:1440:(ow-iw)/2:(oh-ih)/2,setsar=1" -map 0:v:0 -map 1:a:0 -c:v libvpx-vp9 -b:v 0 -crf 22 -deadline good -cpu-used 2 -row-mt 0 -tile-columns 1 -frame-parallel 0 -threads 1 -pix_fmt yuv420p -c:a aac -b:a 192k -movflags +faststart -shortest "${outputPath}"`
console.log(`Running FFmpeg...`)
try {
execSync(vaapiCmd, { stdio: 'inherit' })
}
catch {
console.warn('VAAPI encode failed, falling back to high-quality VP9 software encode...')
execSync(vp9FallbackCmd, { stdio: 'inherit' })
}
finally {
fs.rmSync(concatFilePath, { force: true })
}
console.log('Priscilla compilation completely successful!')