Browse Source

fix(quick-003): use full audio duration when videoDuration is 0

When videoDuration is 0 (unknown at call time), prepareAudioAsync was
computing targetDuration as max(0.1, 0) = 0.1 seconds, truncating the
audio to 100ms. Now computes the actual decoded audio duration from
buffers and uses that when videoDuration <= 0.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 5 months ago
parent
commit
6787c60889
  1. 9
      src/hooks/useAudioMixing.ts

9
src/hooks/useAudioMixing.ts

@ -117,7 +117,14 @@ export async function prepareAudioAsync(
const sampleRate = decodedBuffers[0].sampleRate;
const channels = decodedBuffers[0].numberOfChannels;
const targetDuration = Math.max(MINIMUM_AUDIO_DURATION, videoDuration);
// Compute the total decoded audio duration from buffers
const decodedDuration = decodedBuffers.reduce((sum, buf) => sum + buf.length, 0) / sampleRate;
// If videoDuration is 0 (unknown), use the full audio duration
const targetDuration = videoDuration > 0
? Math.max(MINIMUM_AUDIO_DURATION, videoDuration)
: Math.max(MINIMUM_AUDIO_DURATION, decodedDuration);
const totalSamples = Math.max(1, Math.floor(targetDuration * sampleRate));
onProgress?.({ message: 'Processing audio...', progress: 60 });

Loading…
Cancel
Save