11import ffmpeg from "fluent-ffmpeg" ;
22import * as fs from "fs" ;
33import * as path from "path" ;
4- import * as cliProgress from "cli-progress" ;
54import { type Encoder } from "./types.js" ;
65import { logError } from "../logger/index.js" ;
76
8- const progressBar = new cliProgress . SingleBar ( {
9- format : `Processing | {bar} | {percentage}%` ,
10- barCompleteChar : "\u2588" ,
11- barIncompleteChar : "\u2591" ,
12- hideCursor : true ,
13- } ) ;
14-
15- const createDir = (
16- reject : ( reason ?: Error ) => void ,
17- silent : boolean ,
18- output : string ,
19- ) => {
7+ const createDir = ( reject : ( reason ?: Error ) => void , output : string ) => {
208 try {
219 const outDir = path . dirname ( output ) ;
2210 if ( ! fs . existsSync ( outDir ) ) {
@@ -49,9 +37,6 @@ const createFilter = (backgroundVideo: {
4937 ] ;
5038} ;
5139
52- const percent : ( percent ?: number ) => number = ( percent ) =>
53- percent ? parseFloat ( ( percent as number ) . toFixed ( 2 ) ) : 0 ;
54-
5540const outputOptions = [
5641 "-preset veryfast" ,
5742 "-crf 24" ,
@@ -63,8 +48,8 @@ const outputOptions = [
6348
6449const encoder : Encoder = ( config ) =>
6550 new Promise ( ( resolve , reject ) => {
66- const { frameStream, output, backgroundVideo, fps, silent = true } = config ;
67- createDir ( reject , silent , output ) ;
51+ const { frameStream, output, backgroundVideo, fps } = config ;
52+ createDir ( reject , output ) ;
6853
6954 const outputStream = fs . createWriteStream ( output ) ;
7055 const command = ffmpeg ( ) ;
@@ -87,25 +72,12 @@ const encoder: Encoder = (config) =>
8772 command . complexFilter ( [ ...createFilter ( backgroundVideo ) ] , "tmp" ) ;
8873
8974 command . output ( outputStream ) ;
90- // command.size(`${width}x${height}`);
91-
92- command . on ( "start" , ( ) => {
93- if ( ! silent ) progressBar . start ( 100 , 0 ) ;
94- } ) ;
9575
9676 command . on ( "end" , ( ) => {
97- if ( ! silent ) progressBar . stop ( ) ;
98- if ( ! silent ) console . log ( "Processing complete..." ) ;
9977 resolve ( { path : output , stream : outputStream } ) ;
10078 } ) ;
10179
102- command . on ( "progress" , ( progress ) => {
103- if ( ! silent ) progressBar . update ( percent ( progress . percent ) ) ;
104- } ) ;
105-
10680 command . on ( "error" , ( err : Error ) => {
107- if ( ! silent )
108- console . log ( "An error occured while processing," , err . message ) ;
10981 reject ( new Error ( err . message ) ) ;
11082 } ) ;
11183
0 commit comments