mirror of
https://github.com/bitinflow/rerun-encoder.git
synced 2026-03-13 13:46:00 +00:00
Some ffmpeg fail to return progress
https://stackoverflow.com/a/70899710
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user