@@ -142,24 +142,42 @@ const extractAudioFromVideo = async (
142
142
EventId : number ,
143
143
videoUrl : string
144
144
) : Promise < string > => {
145
- const tmpFilePath = `/tmp/hearing-${ EventId } -${ Date . now ( ) } .wav `
145
+ const tmpFilePath = `/tmp/hearing-${ EventId } -${ Date . now ( ) } .m4a `
146
146
147
- // Stream directly from URL to MP3
147
+ // Stream directly from URL and copy audio codec
148
148
await new Promise < void > ( ( resolve , reject ) => {
149
149
ffmpeg ( videoUrl )
150
150
. noVideo ( )
151
151
. 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
+ } )
155
167
. save ( tmpFilePath )
156
168
} )
157
169
158
170
// Upload the audio file
159
171
const bucket = admin . storage ( ) . bucket ( )
160
- const audioFileName = `hearing-${ EventId } -${ Date . now ( ) } .wav `
172
+ const audioFileName = `hearing-${ EventId } -${ Date . now ( ) } .m4a `
161
173
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
+ } )
163
181
164
182
// Clean up temporary file
165
183
await fs . promises . unlink ( tmpFilePath )
0 commit comments