From df803afe2bbdf0d5fa2281859b7c68aae3d63934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Fri, 3 Mar 2023 15:38:56 +0100 Subject: [PATCH] Some ffmpeg fail to return progress https://stackoverflow.com/a/70899710 --- electron/rerun-manager/encoder.ts | 19 ++++++++++++------- package.json | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/electron/rerun-manager/encoder.ts b/electron/rerun-manager/encoder.ts index a5ab71d..377599d 100644 --- a/electron/rerun-manager/encoder.ts +++ b/electron/rerun-manager/encoder.ts @@ -3,8 +3,6 @@ import {EncoderListeners, EncoderOptions, Settings, User, Video} from "../../sha import * as fs from "fs"; import axios, {AxiosInstance} from "axios"; -const ffmpeg = require('fluent-ffmpeg') - export class Encoder { private readonly id: string; private readonly input: string; @@ -42,18 +40,25 @@ export class Encoder { async encode(): Promise { this.listeners.onStart(this.id) - const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path; + const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path + console.log('ffmpegPath', ffmpegPath) + const ffmpeg = require('fluent-ffmpeg') ffmpeg.setFfmpegPath(ffmpegPath) - + let totalTime = 0; ffmpeg(this.input) .outputOptions(this.getOutputOptions()) .output(this.output) .on('start', () => { console.log('start') }) - .on('progress', (progress) => { - console.log('progress', progress) - this.listeners.onProgress(this.id, progress.percent) + .on('codecData', data => { + totalTime = parseInt(data.duration.replace(/:/g, '')) + }) + .on('progress', progress => { + const time = parseInt(progress.timemark.replace(/:/g, '')) + const percent = (time / totalTime) * 100 + console.log('progress', percent) + this.listeners.onProgress(this.id, percent) }) .on('end', async () => { console.log('end') diff --git a/package.json b/package.json index 6ef68f5..65da8bf 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rerun-encoder", "private": true, "productName": "Rerun Encoder", - "version": "1.0.2", + "version": "1.0.3", "description": "Official Rerun Encoder App for Rerun Manager", "main": "dist-electron/main/index.js", "scripts": {