test win codec fix

This commit is contained in:
Siddharth
2025-11-24 17:11:37 -07:00
parent 7129d55f86
commit 188ba94aad
7 changed files with 94 additions and 57 deletions
@@ -49,41 +49,32 @@ export default function VideoEditor() {
// Helper to convert file path to proper file:// URL
const toFileUrl = (filePath: string): string => {
console.log('[VIDEO-EDITOR] Converting path to URL:', filePath);
// Normalize path separators to forward slashes
const normalized = filePath.replace(/\\/g, '/');
console.log('[VIDEO-EDITOR] Normalized path:', normalized);
// Check if it's a Windows absolute path (e.g., C:/Users/...)
if (normalized.match(/^[a-zA-Z]:/)) {
const fileUrl = `file:///${normalized}`;
console.log('[VIDEO-EDITOR] Windows file URL:', fileUrl);
return fileUrl;
}
// Unix-style absolute path
const fileUrl = `file://${normalized}`;
console.log('[VIDEO-EDITOR] Unix file URL:', fileUrl);
return fileUrl;
};
useEffect(() => {
async function loadVideo() {
try {
console.log('[VIDEO-EDITOR] Loading video...');
const result = await window.electronAPI.getRecordedVideoPath();
console.log('[VIDEO-EDITOR] getRecordedVideoPath result:', result);
if (result.success && result.path) {
const videoUrl = toFileUrl(result.path);
console.log('[VIDEO-EDITOR] Setting video path:', videoUrl);
setVideoPath(videoUrl);
} else {
console.error('[VIDEO-EDITOR] Failed to get video path:', result.message);
setError(result.message || 'Failed to load video');
}
} catch (err) {
console.error('[VIDEO-EDITOR] Error loading video:', err);
setError('Error loading video: ' + String(err));
} finally {
setLoading(false);
@@ -95,7 +86,6 @@ export default function VideoEditor() {
function togglePlayPause() {
const playback = videoPlaybackRef.current;
const video = playback?.video;
console.log('Toggle play/pause:', { hasVideo: !!video, isPlaying, action: isPlaying ? 'pause' : 'play' });
if (!playback || !video) return;
if (isPlaying) {
+30 -4
View File
@@ -205,7 +205,7 @@ export class VideoExporter {
const metadata: EncodedVideoChunkMetadata = {
decoderConfig: {
codec: this.config.codec || 'avc1.640033',
codec: this.config.codec || 'avc1.64001f',
codedWidth: this.config.width,
codedHeight: this.config.height,
description: this.videoDescription,
@@ -230,9 +230,9 @@ export class VideoExporter {
},
});
const codec = this.config.codec || 'avc1.640033';
const codec = this.config.codec || 'avc1.64001f';
this.encoder.configure({
const encoderConfig: VideoEncoderConfig = {
codec,
width: this.config.width,
height: this.config.height,
@@ -241,7 +241,33 @@ export class VideoExporter {
latencyMode: 'realtime',
bitrateMode: 'variable',
hardwareAcceleration: 'prefer-hardware',
} as VideoEncoderConfig);
};
try {
console.log('[VideoExporter] Configuring encoder with hardware acceleration...', {
codec,
resolution: `${this.config.width}x${this.config.height}`,
bitrate: this.config.bitrate,
framerate: this.config.frameRate,
});
this.encoder.configure(encoderConfig as VideoEncoderConfig);
console.log('[VideoExporter] Hardware encoder configured successfully');
} catch (error) {
console.warn('[VideoExporter] Hardware encoding failed, falling back to software encoding...', error);
// Fallback to software encoding if hardware fails
encoderConfig.hardwareAcceleration = 'prefer-software';
try {
this.encoder.configure(encoderConfig as VideoEncoderConfig);
console.log('[VideoExporter] Software encoder configured successfully');
} catch (softwareError) {
console.error('[VideoExporter] Software encoding also failed:', softwareError);
throw new Error(`Failed to initialize video encoder: ${softwareError instanceof Error ? softwareError.message : String(softwareError)}`);
}
}
}
cancel(): void {