@@ -25,7 +25,6 @@ function getFfmpegPath(): string {
2525
2626 for ( const path of candidatePaths ) {
2727 if ( existsSync ( path ) ) {
28- console . log ( `[audio-extract] Found FFmpeg at: ${ path } ` ) ;
2928 cachedFfmpegPath = path ;
3029 return path ;
3130 }
@@ -46,31 +45,23 @@ export async function extractAudioFromUrl(
4645 videoUrl : string ,
4746) : Promise < AudioExtractionResult > {
4847 const ffmpeg = getFfmpegPath ( ) ;
49- const outputPath = join ( tmpdir ( ) , `audio-${ randomUUID ( ) } .m4a ` ) ;
48+ const outputPath = join ( tmpdir ( ) , `audio-${ randomUUID ( ) } .mp3 ` ) ;
5049
5150 const ffmpegArgs = [
5251 "-i" ,
5352 videoUrl ,
5453 "-vn" ,
5554 "-acodec" ,
56- "aac " ,
55+ "libmp3lame " ,
5756 "-b:a" ,
5857 "128k" ,
5958 "-f" ,
60- "ipod" ,
61- "-movflags" ,
62- "+faststart" ,
59+ "mp3" ,
6360 "-y" ,
6461 outputPath ,
6562 ] ;
6663
6764 return new Promise ( ( resolve , reject ) => {
68- console . log (
69- "[audio-extract] FFmpeg started:" ,
70- ffmpeg ,
71- ffmpegArgs . join ( " " ) ,
72- ) ;
73-
7465 const proc = spawn ( ffmpeg , ffmpegArgs , { stdio : [ "pipe" , "pipe" , "pipe" ] } ) ;
7566
7667 let stderr = "" ;
@@ -80,28 +71,24 @@ export async function extractAudioFromUrl(
8071 } ) ;
8172
8273 proc . on ( "error" , ( err : Error ) => {
83- console . error ( "[audio-extract] FFmpeg error:" , err ) ;
8474 fs . unlink ( outputPath ) . catch ( ( ) => { } ) ;
8575 reject ( new Error ( `Audio extraction failed: ${ err . message } ` ) ) ;
8676 } ) ;
8777
8878 proc . on ( "close" , ( code : number | null ) => {
8979 if ( code === 0 ) {
90- console . log ( "[audio-extract] Audio extraction complete" ) ;
9180 resolve ( {
9281 filePath : outputPath ,
93- mimeType : "audio/mp4 " ,
82+ mimeType : "audio/mpeg " ,
9483 cleanup : async ( ) => {
9584 try {
9685 await fs . unlink ( outputPath ) ;
97- console . log ( "[audio-extract] Cleaned up temp file:" , outputPath ) ;
9886 } catch { }
9987 } ,
10088 } ) ;
10189 } else {
102- console . error ( "[audio-extract] FFmpeg stderr:" , stderr ) ;
10390 fs . unlink ( outputPath ) . catch ( ( ) => { } ) ;
104- reject ( new Error ( `Audio extraction failed with code ${ code } ` ) ) ;
91+ reject ( new Error ( `Audio extraction failed with code ${ code } : ${ stderr } ` ) ) ;
10592 }
10693 } ) ;
10794 } ) ;
@@ -114,13 +101,11 @@ export async function extractAudioToBuffer(videoUrl: string): Promise<Buffer> {
114101 videoUrl ,
115102 "-vn" ,
116103 "-acodec" ,
117- "aac " ,
104+ "libmp3lame " ,
118105 "-b:a" ,
119106 "128k" ,
120107 "-f" ,
121- "ipod" ,
122- "-movflags" ,
123- "+frag_keyframe+empty_moov" ,
108+ "mp3" ,
124109 "-pipe:1" ,
125110 ] ;
126111
@@ -139,17 +124,14 @@ export async function extractAudioToBuffer(videoUrl: string): Promise<Buffer> {
139124 } ) ;
140125
141126 proc . on ( "error" , ( err : Error ) => {
142- console . error ( "[audio-extract] FFmpeg error:" , err ) ;
143127 reject ( new Error ( `Audio extraction failed: ${ err . message } ` ) ) ;
144128 } ) ;
145129
146130 proc . on ( "close" , ( code : number | null ) => {
147131 if ( code === 0 ) {
148- console . log ( "[audio-extract] Audio extraction to buffer complete" ) ;
149132 resolve ( Buffer . concat ( chunks ) ) ;
150133 } else {
151- console . error ( "[audio-extract] FFmpeg stderr:" , stderr ) ;
152- reject ( new Error ( `Audio extraction failed with code ${ code } ` ) ) ;
134+ reject ( new Error ( `Audio extraction failed with code ${ code } : ${ stderr } ` ) ) ;
153135 }
154136 } ) ;
155137 } ) ;
@@ -159,8 +141,7 @@ export async function checkHasAudioTrack(videoUrl: string): Promise<boolean> {
159141 let ffmpeg : string ;
160142 try {
161143 ffmpeg = getFfmpegPath ( ) ;
162- } catch ( err ) {
163- console . error ( "[audio-extract] FFmpeg binary not found:" , err ) ;
144+ } catch {
164145 return false ;
165146 }
166147 const ffmpegArgs = [ "-i" , videoUrl , "-hide_banner" ] ;
@@ -176,15 +157,12 @@ export async function checkHasAudioTrack(videoUrl: string): Promise<boolean> {
176157 stderr += data . toString ( ) ;
177158 } ) ;
178159
179- proc . on ( "error" , ( err : Error ) => {
180- console . error ( "[audio-extract] FFmpeg error:" , err ) ;
160+ proc . on ( "error" , ( ) => {
181161 resolve ( false ) ;
182162 } ) ;
183163
184164 proc . on ( "close" , ( ) => {
185- const hasAudio = / S t r e a m # \d + : \d + .* A u d i o : / . test ( stderr ) ;
186- console . log ( `[audio-extract] Video has audio track: ${ hasAudio } ` ) ;
187- resolve ( hasAudio ) ;
165+ resolve ( / S t r e a m # \d + : \d + .* A u d i o : / . test ( stderr ) ) ;
188166 } ) ;
189167 } ) ;
190168}
0 commit comments