Socket
Socket
Sign inDemoInstall

ffmpeg-progressbar-cli

Package Overview
Dependencies
30
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

lib/predict-progressbar-width.js

5

lib/formatter.js

@@ -86,8 +86,9 @@ 'use strict'

* @param {String} fraction - Fraction
* @param {String=} pad - Pad character
* @returns {String} - percentage
*/
let fractionToPercentage = (fraction) => {
let fractionToPercentage = (fraction, pad = '0') => {
// console.debug('fractionToPercentagePad')
return String(Math.round(fraction * 100)).padStart(2, '0')
return String(Math.round(fraction * 100)).padStart(3, pad)
}

@@ -94,0 +95,0 @@

180

lib/main.js

@@ -25,2 +25,3 @@ #!/usr/bin/env node

const os = require('os')
const readline = require('readline')
const path = require('path')

@@ -38,3 +39,2 @@

const which = require('which')
const windowSize = require('window-size')

@@ -48,2 +48,3 @@ /**

const parseFFmpegLog = require('./parse-ffmpeg-log')
const predictProgressbarWidth = require('./predict-progressbar-width')
const formatter = require('./formatter')

@@ -67,45 +68,13 @@ const theme = require('./theme')

/**
* Calculate the progress bars' text components width (fixed width)
* @returns {Number} - String length
*/
let approximateBarTextWidth = () => {
// console.debug('approximateBarTextWidth()')
// TEXT LABEL WIDTH
// 🎬 Rendering 12
// BAR_FILENAME_LENGTH 10
// | {percentagePad}% | ETA {etaTimecode} 20
const barTextWidth = 12 + Number(BAR_FILENAME_LENGTH) + 20
const correctionFactor = 4
return barTextWidth - correctionFactor
}
/**
* Calculate the progress bars' beam width (variable width)
* @returns {Number} - String length
* @typedef {ChildProcess} Task
* @inherits {NodeJS.EventEmitter}
* @property {NodeJS.ReadableStream} stdout - stdout Stream
* @property {NodeJS.ReadableStream} stderr - stderr Stream
* @property {NodeJS.WritableStream} stdin - stdin Stream
* @property {function} on - NodeJS.EventEmitter.on
*/
let approximateBarBeamWidth = () => {
// console.debug('approximateBarBeamWidth()')
const barBeamWidth = (windowSize.get().width - approximateBarTextWidth()) * BAR_BEAM_RATIO
return Math.floor(barBeamWidth)
}
/**
* Calculate the progress bars' beam total width
* @returns {Number} - String length
*/
let approximateBarWidth = () => {
// console.debug('approximateBarWidth()')
return approximateBarTextWidth() + approximateBarBeamWidth()
}
/**
* Primary Task

@@ -119,10 +88,22 @@ * This task runs the FFmpeg commands provided.

const progressbarWidth = predictProgressbarWidth.beam(Number(BAR_FILENAME_LENGTH), BAR_BEAM_RATIO)
/**
* Create Progress Bar
* @type {progressBar}
*/
const bar = progressBar({
barsize: approximateBarBeamWidth()
barsize: progressbarWidth
})
/** @type {Boolean} */
/**
* Startup status
* @type {Boolean}
*/
let didStart = false
/** @type {String} */
/**
* Last error log
* @type {String}
*/
let lastError

@@ -133,7 +114,13 @@

// Spawn main task
/**
* Main Task
* @type {Task}
*/
const mainTask = childProcess.spawn(ffmpegFilepath, ffmpegPrimaryTaskArgsList)
/** @listens ChildProcess.stdout#data */
mainTask.stdout.on('data', (data) => {
/**
* Handles mainTask.stdout
* @param {Buffer|String} data - FFmpeg Live Log Output Buffer
*/
let onData = (data) => {
if (!didStart) {

@@ -155,9 +142,18 @@ // Bar::start()

// Bar::update() (noncritical errors are written to Bar.annotation)
bar.update(currentTimeMs, null, !!lastError ? theme.error(ellipsize(lastError, approximateBarWidth() + 7)) : null)
bar.update(currentTimeMs, null, !!lastError ? theme.error(ellipsize(lastError, progressbarWidth + 7)) : null)
// DEBUG
// console.debug('progress (ms)', progressMilliseconds, 'duration (ms)', durationMilliseconds, 'fraction', (progressMilliseconds / durationMilliseconds))
})
}
/** @listens ChildProcess.stderr#data */
/**
* @fires mainTask#onData
* @interface mainTask.stdout
*/
mainTask.stdout.on('data', onData)
/**
* @fires mainTask#onData
* @interface mainTask.stderr
*/
mainTask.stderr.on('data', (data) => {

@@ -169,12 +165,10 @@ // Error: Persist last line fo error logs to lastError

/** @interface Process.ReadStream<ChildProcess.WritableStream> */
/**
* @interface Process.ReadStream<ChildProcess.WritableStream>
*/
process.stdin.pipe(mainTask.stdin)
/** @listens ChildProcess#exit */
mainTask.on('exit', (code, signal) => {
// DEBUG
// console.debug('mainTask#exit', 'code:', code, 'signal:', signal)
})
/** @listens ChildProcess#close */
/**
* @listens mainTask#close
*/
mainTask.on('close', (code, signal) => {

@@ -202,30 +196,61 @@ // DEBUG

// Spawn prep task
/**
* Preparation Task
*/
const prepTask = childProcess.spawn(ffmpegFilepath, ffmpegPreparationTaskArgsList)
/** @type {Number} */
let duration
/**
* Duration of output file
* @type {Number}
*/
let outputDuration
/** @type {String} */
let output
/**
* Name of output file
* @type {String}
*/
let outputFilename
/** @type {String} */
/**
* Last error log
* @type {String}
*/
let lastError
/**
* Question status
* @type {Boolean}
*/
let didShowQuestion = false
/**
* Handles prepTask.stdout
* @param {Buffer|String} data - FFmpeg Live Log Output Buffer
*/
let onData = (data) => {
data = data.toString()
if (parseFFmpegLog.duration(data)) { duration = parseFFmpegLog.duration(data) }
if (parseFFmpegLog.output(data)) { output = parseFFmpegLog.output(data) }
if (parseFFmpegLog.duration(data)) { outputDuration = parseFFmpegLog.duration(data) }
if (parseFFmpegLog.output(data)) { outputFilename = parseFFmpegLog.output(data) }
if (duration && output) {
// SIGKILL sent: preparation task succeeded
if (outputDuration && outputFilename) {
if (didShowQuestion) {
readline.moveCursor(process.stderr, 0, -1)
readline.clearLine(process.stderr, 0)
}
// Send SIGKILL: preparation task succeeded
prepTask.kill('SIGKILL')
startPrimaryTask(duration, output)
startPrimaryTask(outputDuration, outputFilename)
}
}
/** @listens ChildProcess.stdout#data */
/**
* @fires prepTask#onData
* @interface prepTask.stdout
*/
prepTask.stdout.on('data', onData)
// TODO: Better error handling in prep task!
/** @listens ChildProcess.stderr#data */
/**
* @fires prepTask#onData
* @interface prepTask.stderr
*/
prepTask.stderr.on('data', (data) => {

@@ -236,2 +261,3 @@ if ((parseFFmpegLog.question(data.toString()))) {

process.stdout.write(' ')
didShowQuestion = true
} else {

@@ -245,12 +271,10 @@ // Error: Persist last line fo error logs to lastError

/** @interface Process.ReadStream<ChildProcess.WritableStream> */
/**
* @interface Process.ReadStream<ChildProcess.WritableStream>
*/
process.stdin.pipe(prepTask.stdin)
/** @listens ChildProcess#exit */
prepTask.on('exit', (code, signal) => {
// DEBUG
// console.debug('prepTask#exit', 'code:', code, 'signal:', signal)
})
/** @listens ChildProcess#close */
/**
* @listens prepTask#close
*/
prepTask.on('close', (code, signal) => {

@@ -257,0 +281,0 @@ // DEBUG

@@ -18,3 +18,3 @@ 'use strict'

appRootPath.setPath(path.join(__dirname, '..'))
const CliProgress = require('cli-progress')
const CliProgress = require('@sidneys/cli-progress')
const moment = require('moment')

@@ -121,3 +121,3 @@ /* eslint-disable no-unused-vars */

const updatePayload = {
percentagePad: formatter.fractionToPercentage(progressBar.value / progressBar.total),
percentagePad: formatter.fractionToPercentage(progressBar.value / progressBar.total, ' '),
etaTimecode: convertSecondsToTimecode(progressBar.eta.eta)

@@ -135,4 +135,12 @@ }

/**
* @typedef {Object} progressBar
* @extends {CliProgress}
* @property {function} bar
* @property {function} start
* @property {function} update
*/
/**
* @param {Object} options - Progress Bar options
* @exports progress-bar
* @exports progressBar
* @returns {Object}

@@ -139,0 +147,0 @@ */

{
"name": "ffmpeg-progressbar-cli",
"version": "1.3.0",
"version": "1.4.0",
"description": "A colored progress bar for FFmpeg. Simply use `ffmpeg-bar` instead of `ffmpeg`.",

@@ -40,5 +40,5 @@ "license": "MIT",

"dependencies": {
"@sidneys/cli-progress": "^2.2.0",
"app-root-path": "^2.1.0",
"chalk": "^2.4.1",
"cli-progress": "git+https://github.com/sidneys/Node.CLI-Progress.git#feature/bar-annotation-property",
"ellipsize": "^0.1.0",

@@ -53,3 +53,3 @@ "ini": "^1.3.5",

"devDependencies": {
"docdash": "^0.4.0",
"docdash": "^1.0.0",
"eslint": "^5.4.0",

@@ -56,0 +56,0 @@ "jsdoc": "^3.5.5"

@@ -69,3 +69,3 @@ # ffmpeg-progressbar-cli [![npm](https://img.shields.io/npm/v/ffmpeg-progressbar-cli.svg?style=flat-square)](https://npmjs.com/package/ffmpeg-progressbar-cli)

The share of (available) horizontal display real estate the progress bar beam should occupy *(default: 0.9)*
The share of (available) horizontal display real estate the progress bar beam should occupy *(default: 0.75)*

@@ -72,0 +72,0 @@ ###### Example

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc