Some ffmpeg fail to return progress

https://stackoverflow.com/a/70899710
This commit is contained in:
René Preuß
2023-03-03 15:38:56 +01:00
parent 2644c30bf2
commit df803afe2b
2 changed files with 13 additions and 8 deletions

View File

@@ -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<void> {
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')