MCPcopy
hub / github.com/CapSoftware/Cap / extractAudioToBuffer

Function extractAudioToBuffer

apps/web/lib/audio-extract.ts:111–154  ·  view source on GitHub ↗
(videoUrl: string)

Source from the content-addressed store, hash-verified

109}
110
111export async function extractAudioToBuffer(videoUrl: string): Promise<Buffer> {
112 const ffmpeg = getFfmpegPath();
113 const ffmpegArgs = [
114 "-i",
115 videoUrl,
116 "-vn",
117 "-acodec",
118 "libmp3lame",
119 "-b:a",
120 "128k",
121 "-f",
122 "mp3",
123 "-pipe:1",
124 ];
125
126 return new Promise((resolve, reject) => {
127 const proc = spawn(ffmpeg, ffmpegArgs, { stdio: ["pipe", "pipe", "pipe"] });
128
129 const chunks: Buffer[] = [];
130 let stderr = "";
131
132 proc.stdout?.on("data", (chunk: Buffer) => {
133 chunks.push(chunk);
134 });
135
136 proc.stderr?.on("data", (data: Buffer) => {
137 stderr += data.toString();
138 });
139
140 proc.on("error", (err: Error) => {
141 reject(new Error(`Audio extraction failed: ${err.message}`));
142 });
143
144 proc.on("close", (code: number | null) => {
145 if (code === 0) {
146 resolve(Buffer.concat(chunks));
147 } else {
148 reject(
149 new Error(`Audio extraction failed with code ${code}: ${stderr}`),
150 );
151 }
152 });
153 });
154}
155
156export async function convertWavToMp3(wavBuffer: Buffer): Promise<Buffer> {
157 const ffmpeg = getFfmpegPath();

Callers 1

Calls 4

getFfmpegPathFunction · 0.85
rejectFunction · 0.85
onMethod · 0.80
resolveFunction · 0.70

Tested by

no test coverage detected