(inputMp3: string, outputPath: string, metadata: SongInfo, coverPath?: string)
| 204 | if (coverPath) { |
| 205 | args.push("-i", coverPath, "-map", "0:a", "-map", "1:v", "-disposition:v:0", "attached_pic"); |
| 206 | } |
| 207 | args.push("-metadata", `title=${metadata.title}`); |
| 208 | args.push("-metadata", `artist=${metadata.artist}`); |
| 209 | args.push("-metadata", `album=${metadata.album}`); |
| 210 | args.push("-y", outputPath); |
| 211 | |
| 212 | await execFileAsync("ffmpeg", args, { timeout: 120000 }); |
| 213 | return fs.existsSync(outputPath); |
| 214 | } catch (error) { |
| 215 | console.error("Failed to add metadata:", error); |
| 216 | return false; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | async getVideoDuration(filePath: string): Promise<number> { |
| 221 | try { |
| 222 | const { stdout } = await execFileAsync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filePath]); |
| 223 | return parseFloat(stdout.trim()) || 0; |
| 224 | } catch (error) { |
| 225 | console.error("Failed to get video duration:", error); |
| 226 | return 0; |
no test coverage detected