diff --git a/services/worker/src/ffmpeg/executor.js b/services/worker/src/ffmpeg/executor.js index 6465950..1da4c5f 100644 --- a/services/worker/src/ffmpeg/executor.js +++ b/services/worker/src/ffmpeg/executor.js @@ -16,23 +16,33 @@ export const runFFmpeg = async (args, options = {}) => { } }; +const runFFprobe = async (args) => { + try { + const { stdout } = await execFileAsync('ffprobe', args); + return { stdout }; + } catch (error) { + throw new Error(`FFprobe error: ${error.message}\nStderr: ${error.stderr}`); + } +}; + export const getMediaDuration = async (inputPath) => { const args = [ '-v', 'error', '-show_entries', 'format=duration', - '-of', 'default=noprint_wrappers=1:nokey=1:noinvalidchars=1', + '-of', 'default=noprint_wrappers=1:nokey=1', inputPath, ]; - const { stdout } = await runFFmpeg(args); + const { stdout } = await runFFprobe(args); return parseFloat(stdout.trim()); }; export const extractFrameAtTime = async (inputPath, outputPath, timeCode) => { const args = [ - '-i', inputPath, '-ss', timeCode, + '-i', inputPath, '-vframes', '1', '-q:v', '2', + '-y', outputPath, ]; await runFFmpeg(args); @@ -55,6 +65,7 @@ export const transcodeVideo = async (inputPath, outputPath, options = {}) => { '-c:a', audioCodec, '-b:a', audioBitrate, '-movflags', '+faststart', + '-y', outputPath, ]; @@ -67,6 +78,7 @@ export const trimSegment = async (inputPath, outputPath, inPoint, outPoint) => { '-ss', inPoint, '-to', outPoint, '-c', 'copy', + '-y', outputPath, ]; await runFFmpeg(args); @@ -78,6 +90,7 @@ export const concatSegments = async (segmentListFile, outputPath) => { '-safe', '0', '-i', segmentListFile, '-c', 'copy', + '-y', outputPath, ]; await runFFmpeg(args);