* @brief Get media file duration and metadata (callback version) * * @param file_path [in] Path to media file * @param callback [in] Function(err, result) * - err: Error if operation failed * - result: Object with duration, file_type, mime_type * * @note Uses ffprobe for metadata ex
(file_path, callback)
| 95 | * @note Validates media type before processing |
| 96 | */ |
| 97 | function get_media_duration_callback(file_path, callback) { |
| 98 | is_media_file_callback(file_path, (err, is_media) => { |
| 99 | if (err) { |
| 100 | return callback(err); |
| 101 | } |
| 102 | |
| 103 | if (!is_media) { |
| 104 | return callback(new Error('Not a supported media file')); |
| 105 | } |
| 106 | |
| 107 | ffprobe.ffprobe(file_path, (err, metadata) => { |
| 108 | if (err) { |
| 109 | console.error('FFprobe Error:', { |
| 110 | message: err.message, |
| 111 | code: err.code, |
| 112 | file_path: file_path |
| 113 | }); |
| 114 | return callback(err); |
| 115 | } |
| 116 | |
| 117 | const duration = metadata.format?.duration || 0; |
| 118 | |
| 119 | callback(null, { |
| 120 | duration: duration, |
| 121 | file_type: path.extname(file_path), |
| 122 | mime_type: mime.lookup(file_path) |
| 123 | }); |
| 124 | }); |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | |
| 129 |
no test coverage detected