Skip to content

Commit fc1043a

Browse files
authored
Merge pull request #1828 from boazsender/automated-transcriptions
Improve ffmpeg logic and file handling.
2 parents 52fb08f + 5a5d99f commit fc1043a

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

functions/src/events/scrapeEvents.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,42 @@ const extractAudioFromVideo = async (
142142
EventId: number,
143143
videoUrl: string
144144
): Promise<string> => {
145-
const tmpFilePath = `/tmp/hearing-${EventId}-${Date.now()}.wav`
145+
const tmpFilePath = `/tmp/hearing-${EventId}-${Date.now()}.m4a`
146146

147-
// Stream directly from URL to MP3
147+
// Stream directly from URL and copy audio codec
148148
await new Promise<void>((resolve, reject) => {
149149
ffmpeg(videoUrl)
150150
.noVideo()
151151
.audioCodec("copy")
152-
.format("wav")
153-
.on("end", () => resolve())
154-
.on("error", reject)
152+
.format("mp4")
153+
.on("start", commandLine => {
154+
console.log(`Spawned FFmpeg with command: ${commandLine}`)
155+
})
156+
.on("progress", progress => {
157+
console.log(`Processing: ${progress.percent}% done`)
158+
})
159+
.on("end", () => {
160+
console.log("FFmpeg processing finished successfully")
161+
resolve()
162+
})
163+
.on("error", err => {
164+
console.error("FFmpeg error:", err)
165+
reject(err)
166+
})
155167
.save(tmpFilePath)
156168
})
157169

158170
// Upload the audio file
159171
const bucket = admin.storage().bucket()
160-
const audioFileName = `hearing-${EventId}-${Date.now()}.wav`
172+
const audioFileName = `hearing-${EventId}-${Date.now()}.m4a`
161173
const file = bucket.file(audioFileName)
162-
await file.save(tmpFilePath)
174+
175+
const fileContent = await fs.promises.readFile(tmpFilePath)
176+
await file.save(fileContent, {
177+
metadata: {
178+
contentType: "audio/mp4"
179+
}
180+
})
163181

164182
// Clean up temporary file
165183
await fs.promises.unlink(tmpFilePath)

0 commit comments

Comments
 (0)