1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| const fs = require('fs') const { exec,spawn } = require('child_process'); init() function init(){ fs.readFile(`./out/ts.key`,{encoding:"utf-8"},(error,res)=>{ if(error){ console.log('读取key文件错误:',err); }else{ const str = res.toString() var val = '' for(key of str){ val += key.charCodeAt().toString(16) } console.log('转换后的16进制:',val,'源数据:',str); CmdPlay(val) } }) }
function CmdPlay(val){ console.log('url',__filename,__dirname); exec(__dirname+'/merge.bat',(error,stdout,stderr)=>{ console.log('merge.bat:',error,stdout,stderr); if(!error){ console.log('合并视频并移动'); let params = [ 'aes-128-cbc', '-d', '-in', './out/__.mp4', '-out', './outPut.mp4', '-nosalt', '-iv', '00000000000000000000000000000000', '-K', val ] const outputStream = fs.createWriteStream(__dirname+ 'output.mp4'); const openssl = spawn('openssl',params) openssl.stdout.pipe(outputStream); openssl.stderr.pipe(process.stdout); openssl.on('error', (err) => { console.log('openssl执行错误:',err); }); openssl.on('close', (code) => { console.log('openssl执行结束:',code,'解码成功');
exec(__dirname+'/delete.bat',(error,stdout,stderr)=>{}) }); openssl.on('exit', (code) => { console.log('openssl执行退出:',code); }); }else{ console.log('合并视频失败'); } }) }
|