This commit is contained in:
youngq 2024-09-23 13:37:53 +08:00
parent c9362fc14d
commit b86c4230bb
1 changed files with 65 additions and 72 deletions

View File

@ -573,14 +573,14 @@ const Meeting: React.FC = () => {
const outputFilePath = mp4Path.replace('_beforehanlder',''); // 输出文件路径 const outputFilePath = mp4Path.replace('_beforehanlder',''); // 输出文件路径
const command = `${ffmpegPath} -i "${inputFilePath}" -vcodec copy -acodec copy "${outputFilePath}"`; const command = `${ffmpegPath} -i "${inputFilePath}" -vcodec copy -acodec copy "${outputFilePath}"`;
exec(command, (error, stdout, stderr) => { exec(command, (error:any, stdout:any, stderr:any) => {
if (error) { if (error) {
console.error('Error executing ffmpeg command:', error); console.error('Error executing ffmpeg command:', error);
return; return;
} }
// 删除输入文件 // 删除输入文件
fs.unlink(inputFilePath, (err) => { fs.unlink(inputFilePath, (err:any) => {
if (err) { if (err) {
console.error('Error deleting input file:', err); console.error('Error deleting input file:', err);
} else { } else {
@ -1075,52 +1075,45 @@ const Meeting: React.FC = () => {
window.electron.getSources().then(async (sources: any) => { window.electron.getSources().then(async (sources: any) => {
const screenId = sources[0].id; const screenId = sources[0].id;
const stream = await navigator.mediaDevices.getUserMedia({ const stream = await navigator.mediaDevices.getUserMedia({
audio: { audio: {
mandatory: { mandatory: {
chromeMediaSource: 'desktop', chromeMediaSource: 'desktop',
chromeMediaSourceId: screenId, chromeMediaSourceId: screenId,
} }
}, } as any,
video: { video: {
mandatory: { mandatory: {
chromeMediaSource: 'desktop', chromeMediaSource: 'desktop',
chromeMediaSourceId: screenId, chromeMediaSourceId: screenId,
} }
} } as any
}); });
// 获取所有音频输入设备 // 获取所有音频输入设备
const devices = await navigator.mediaDevices.enumerateDevices(); const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputDevices = devices.filter(device => device.kind === 'audioinput' && const audioInputDevices = devices.filter(device => device.kind === 'audioinput' &&
device.deviceId !== 'default' && device.deviceId !== 'default' &&
device.deviceId !== 'communications' ); device.deviceId !== 'communications');
// 使用Web Audio API来捕获系统声音和麦克风声音将它们合并到同一个MediaStream中。 // 使用Web Audio API来捕获系统声音和麦克风声音将它们合并到同一个MediaStream中。
const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); const audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();
const systemSoundSource = audioCtx.createMediaStreamSource(stream); const systemSoundSource = audioCtx.createMediaStreamSource(stream);
const systemSoundDestination = audioCtx.createMediaStreamDestination(); const systemSoundDestination = audioCtx.createMediaStreamDestination();
systemSoundSource.connect(systemSoundDestination); systemSoundSource.connect(systemSoundDestination);
// 录制所有音频输入设备 // 录制所有音频输入设备
audioInputDevices.forEach( async device=>{ audioInputDevices.forEach(async device => {
const micStream = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: device.deviceId } }}); const micStream = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: device.deviceId } } });
setMediaStream(micStream);
const micSoundSource = audioCtx.createMediaStreamSource(micStream); const micSoundSource = audioCtx.createMediaStreamSource(micStream);
micSoundSource.connect(systemSoundDestination); micSoundSource.connect(systemSoundDestination);
}) })
// 合并音频流与视频流 // 合并音频流与视频流
const combinedSource = new MediaStream([...stream.getVideoTracks(), ...systemSoundDestination.stream.getAudioTracks()]); const combinedSource = new MediaStream([...stream.getVideoTracks(), ...systemSoundDestination.stream.getAudioTracks()]);
// 开始录制 // 开始录制
const recorder = new MediaRecorder(combinedSource, { const mediaRecorder = new MediaRecorder(combinedSource, {
mimeType: 'video/webm;codecs=vp9,opus', mimeType: 'video/webm;codecs=vp9,opus',
videoBitsPerSecond: 1.5e6, videoBitsPerSecond: 1.5e6,
}); });
setRecorder(mediaRecorder);
setMediaStream(combinedSource);
setRecorder(recorder);
}); });
} catch (error: any) { } catch (error: any) {
if (error.code === 'ENOENT') { if (error.code === 'ENOENT') {