From 493c80a578500f24cbd4060c934ffb9d6ea0d8cb Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 22 Nov 2020 23:31:08 +0100 Subject: [PATCH] simplify --- src/ffmpeg.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 });