Osciloscope integrated but video exported is broken
This commit is contained in:
@@ -351,7 +351,7 @@ export const useOfflineVideoExport = () => {
|
||||
};
|
||||
};
|
||||
|
||||
// Memory-efficient muxing using real-time playback
|
||||
// Improved muxing with better synchronization
|
||||
async function muxAudioVideo(
|
||||
videoBlob: Blob,
|
||||
audioFile: File,
|
||||
@@ -367,9 +367,9 @@ async function muxAudioVideo(
|
||||
|
||||
video.src = videoUrl;
|
||||
video.muted = true;
|
||||
video.playbackRate = 4; // Speed up playback
|
||||
video.playbackRate = 1; // Normal playback speed
|
||||
audio.src = audioUrl;
|
||||
audio.playbackRate = 4;
|
||||
audio.playbackRate = 1;
|
||||
|
||||
const cleanup = () => {
|
||||
URL.revokeObjectURL(videoUrl);
|
||||
@@ -428,21 +428,39 @@ async function muxAudioVideo(
|
||||
reject(new Error('Muxing failed'));
|
||||
};
|
||||
|
||||
let lastVideoTime = 0;
|
||||
const drawLoop = () => {
|
||||
if (video.ended || audio.ended) {
|
||||
setTimeout(() => recorder.stop(), 100);
|
||||
if (video.paused || video.ended) {
|
||||
if (video.ended || audio.ended) {
|
||||
setTimeout(() => recorder.stop(), 100);
|
||||
return;
|
||||
}
|
||||
requestAnimationFrame(drawLoop);
|
||||
return;
|
||||
}
|
||||
ctx.drawImage(video, 0, 0);
|
||||
|
||||
// Only draw when video has progressed
|
||||
if (video.currentTime !== lastVideoTime) {
|
||||
lastVideoTime = video.currentTime;
|
||||
ctx.drawImage(video, 0, 0);
|
||||
}
|
||||
requestAnimationFrame(drawLoop);
|
||||
};
|
||||
|
||||
recorder.start(100);
|
||||
|
||||
// Ensure both start at the same time
|
||||
video.currentTime = 0;
|
||||
audio.currentTime = 0;
|
||||
video.play();
|
||||
audio.play();
|
||||
drawLoop();
|
||||
|
||||
// Wait for both to be ready to play
|
||||
Promise.all([video.play(), audio.play()]).then(() => {
|
||||
drawLoop();
|
||||
}).catch(err => {
|
||||
console.error('Playback failed:', err);
|
||||
cleanup();
|
||||
reject(err);
|
||||
});
|
||||
}).catch(err => {
|
||||
cleanup();
|
||||
console.warn('Muxing failed, returning video only:', err);
|
||||
|
||||
Reference in New Issue
Block a user