Electron:實時獲取文件轉(zhuǎn)換百分比:我想運行命令ffmpeg -i video.mp4(示例)將視頻轉(zhuǎn)換為另一種格式。但我想獲得在流程輸出中流式傳輸?shù)霓D(zhuǎn)換百分比,并在我的 Electron App 或 NodeJS 中獲取它。我已經(jīng)嘗試了所有方法:spawn fork exec并且所有方法都將過程輸出的最后一行返回給我。我想要一個已寫入的每一行的實時流,以顯示進度百分比。我試過了:叉const {fork} = require('child_process') const forked = fork('ffmpeg -i video.mp4'); forked.on('message', (msg) => { console.log(msg);})執(zhí)行備選方案 1const execFile = require('child_process').execFile; execFile('ffmpeg -i video.mp4', [], (e, stdout, stderr) => { if (e instanceof Error){ console.error(e); } console.log('stdout ', stdout) console.log('stderr ', stderr);})執(zhí)行備選方案 2const exec = require('child_process').exec; exec('ffmpeg -i video.mp4', (error, stdout, stderr) => { console.log(stdout); });/*EXEC Alternative 2*/const exec = require('child_process').exec;const proccessing = exec('ffmpeg -i video.mp4');proccessing.stdout.on('data', function(data) { console.log(data); });proccessing.stdout.pipe(process.stdout);產(chǎn)卵const spawn = require('child_process').spawn,const processing = spawn('ffmpeg -i video.mp4');processing .stdout.on('data', function (data) { console.log('stdout: ' + data.toString());});processing .stderr.on('data', function (data) { console.log('stderr: ' + data.toString());});processing .on('exit', function (code) { console.log('code ' + code.toString());});概括:??目標:在控制臺得到這個結(jié)果10% converted15% converted20% converted100% converted...?錯誤:我得到的是:100% converted//Sometimes I get an empty string because it is the last line of the .exe script在標記為重復(fù)之前,我確定在 STACKOVERFLOW 中沒有一個答案適合我
Electron 和 NodeJS:與實時流異步執(zhí)行 shell 命令
白衣染霜花
2023-04-01 15:39:36