diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 454e2784..bf525c43 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -337,13 +337,6 @@ export async function cutMultiple({ return outFiles; } -// TODO merge with getFormatData -export async function getDuration(filePath) { - // https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds - const { stdout } = await runFfprobe(['-i', filePath, '-show_entries', 'format=duration', '-print_format', 'json']); - return parseFloat(JSON.parse(stdout).format.duration); -} - export async function tryReadChaptersToEdl(filePath) { try { const { stdout } = await runFfprobe(['-i', filePath, '-show_chapters', '-print_format', 'json']); @@ -366,6 +359,20 @@ export async function tryReadChaptersToEdl(filePath) { } } +export async function getFormatData(filePath) { + console.log('getFormatData', filePath); + + const { stdout } = await runFfprobe([ + '-of', 'json', '-show_format', '-i', filePath, + ]); + return JSON.parse(stdout).format; +} + + +export async function getDuration(filePath) { + return parseFloat((await getFormatData(filePath)).duration); +} + export async function html5ify({ filePath, outPath, video, audio, onProgress }) { console.log('Making HTML5 friendly version', { filePath, outPath, video, audio });