( videoId: string, userId: string, video: typeof videos.$inferSelect, )
| 177 | } |
| 178 | |
| 179 | async function extractAudio( |
| 180 | videoId: string, |
| 181 | userId: string, |
| 182 | video: typeof videos.$inferSelect, |
| 183 | ): Promise<string | null> { |
| 184 | "use step"; |
| 185 | |
| 186 | const [bucket] = await Storage.getAccessForVideo( |
| 187 | decodeStorageVideo(video), |
| 188 | ).pipe(runPromise); |
| 189 | |
| 190 | const videoUrl = await resolveVideoSourceUrl(videoId, userId, video); |
| 191 | |
| 192 | const useMediaServer = isMediaServerConfigured(); |
| 193 | console.log( |
| 194 | `[transcribe] Audio detection: useMediaServer=${useMediaServer}, videoId=${videoId}`, |
| 195 | ); |
| 196 | |
| 197 | let hasAudio: boolean; |
| 198 | let audioBuffer: Buffer; |
| 199 | |
| 200 | if (useMediaServer) { |
| 201 | try { |
| 202 | const probe = await probeVideoViaMediaServer(videoUrl); |
| 203 | console.log( |
| 204 | `[transcribe] Probe result for ${videoId}: audioCodec=${probe.audioCodec}, videoCodec=${probe.videoCodec}, duration=${probe.duration}, audioChannels=${probe.audioChannels}, sampleRate=${probe.sampleRate}`, |
| 205 | ); |
| 206 | hasAudio = probe.audioCodec !== null; |
| 207 | } catch (probeError) { |
| 208 | console.error( |
| 209 | `[transcribe] Probe failed for ${videoId}, falling back to audio check:`, |
| 210 | probeError, |
| 211 | ); |
| 212 | hasAudio = await checkHasAudioTrackViaMediaServer(videoUrl); |
| 213 | console.log( |
| 214 | `[transcribe] Fallback audio check result for ${videoId}: hasAudio=${hasAudio}`, |
| 215 | ); |
| 216 | } |
| 217 | |
| 218 | if (!hasAudio) { |
| 219 | console.log( |
| 220 | `[transcribe] No audio track detected for ${videoId} via media server`, |
| 221 | ); |
| 222 | return null; |
| 223 | } |
| 224 | |
| 225 | audioBuffer = await extractAudioViaMediaServer(videoUrl); |
| 226 | } else { |
| 227 | hasAudio = await checkHasAudioTrack(videoUrl); |
| 228 | console.log( |
| 229 | `[transcribe] Local ffmpeg audio check for ${videoId}: hasAudio=${hasAudio}`, |
| 230 | ); |
| 231 | if (!hasAudio) { |
| 232 | return null; |
| 233 | } |
| 234 | |
| 235 | const result = await extractAudioFromUrl(videoUrl); |
| 236 |
no test coverage detected