Created
March 26, 2022 11:31
-
-
Save Haruroid/c0b1d01be507bef9ddfef0a927c48cf6 to your computer and use it in GitHub Desktop.
俺的enc.js豪華版 for EPGStation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//字幕,多チャンネルに対応 | |
const spawn = require('child_process').spawn; | |
const ffmpeg = process.env.FFMPEG; | |
const input = process.env.INPUT; | |
const output = process.env.OUTPUT; | |
const analyzedurationSize = '10M'; // Mirakurun の設定に応じて変更すること | |
const probesizeSize = '32M'; // Mirakurun の設定に応じて変更すること | |
const maxMuxingQueueSize = 1024; | |
const dualMonoMode = 'main'; | |
const videoHeight = parseInt(process.env.VIDEORESOLUTION, 10); | |
const isDualMono = parseInt(process.env.AUDIOCOMPONENTTYPE, 10) == 2; | |
const audioBitrate = '225k'; | |
const preset = 'veryfast'; | |
const codec = 'libx264'; | |
const crf = 20; | |
const name = process.env.NAME; | |
const judge_dual = name.includes('[解]') || name.includes('[二]') || name.includes('[多]'); | |
const args = ['-y','-fix_sub_duration' , '-analyzeduration', analyzedurationSize, '-probesize', probesizeSize]; | |
// input 設定 | |
Array.prototype.push.apply(args,['-i', input]); | |
// メタ情報を先頭に置く | |
Array.prototype.push.apply(args,['-movflags', 'faststart']); | |
// 字幕データを含めたストリームをすべてマップ | |
if(judge_dual){ | |
Array.prototype.push.apply(args, ['-map', '0:v','-map', '0:a:0?','-map', '0:a:1?', '-map', '0:s?' ]); | |
}else{ | |
Array.prototype.push.apply(args, ['-map', '0:v','-map', '0:a:0?','-map', '0:s?' ]); | |
} | |
Array.prototype.push.apply(args, ['-ignore_unknown', '-max_muxing_queue_size', maxMuxingQueueSize ]); | |
// video filter 設定 | |
let videoFilter = 'yadif'; | |
Array.prototype.push.apply(args, ['-vf', videoFilter]); | |
// その他設定 | |
Array.prototype.push.apply(args,[ | |
'-preset', preset, | |
'-aspect', '16:9', | |
'-c:v', codec, | |
'-crf', crf, | |
'-f', 'mp4', | |
'-c:a', 'aac', | |
'-ar', '48000', | |
'-ab', audioBitrate, | |
'-c:s', 'mov_text', | |
output | |
]); | |
let str = ''; | |
for (let i of args) { | |
str += ` ${ i }` | |
} | |
console.error(str); | |
const child = spawn(ffmpeg, args); | |
child.stderr.on('data', (data) => { console.error(String(data)); }); | |
child.on('error', (err) => { | |
console.error(err); | |
throw new Error(err); | |
}); | |
process.on('SIGINT', () => { | |
child.kill('SIGINT'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment