parent
dd5022beb8
commit
5080dd63fa
@ -0,0 +1,4 @@
|
||||
# Todo
|
||||
[ ] Investigate using mkvmerge instead of ffmpeg in Set Subtitle Dispositions By Title to stop increase in file size (https://www.reddit.com/r/ffmpeg/comments/wsogpl/removing_subtitle_track_results_in_a_bigger_file/)
|
||||
[ ] Plugin to strip PGA subs if ASS exists
|
||||
[ ] Plugin to move first audio track in language to first audio track
|
||||
@ -0,0 +1,83 @@
|
||||
/* eslint max-len: 0, no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
const details = () => ({
|
||||
id: 'Tdarr_Plugin_gabehf_Remove_PGS_If_ASS_Exists',
|
||||
Stage: 'Pre-processing',
|
||||
Name: 'Remove PGS Subs if ASS Subs Exist',
|
||||
Type: 'Subtitle',
|
||||
Operation: 'Transcode',
|
||||
Description:
|
||||
'Removes all PGS subtitles if any SubStationAlpha subtitles are found in the container.',
|
||||
Version: '1.0',
|
||||
Tags: 'pre-processing,ffmpeg,subtitle only',
|
||||
Inputs: [],
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const plugin = (file, librarySettings, inputs, otherArguments) => {
|
||||
let languages = [];
|
||||
const lib = require('../methods/lib')();
|
||||
|
||||
const response = {
|
||||
processFile: false,
|
||||
preset: '',
|
||||
container: `.${file.container}`,
|
||||
handBrakeMode: false,
|
||||
FFmpegMode: true,
|
||||
reQueueAfter: false,
|
||||
infoLog: '',
|
||||
};
|
||||
|
||||
// Check if file is a video. If it isn't then exit plugin.
|
||||
if (file.fileMedium !== 'video') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('File is not video');
|
||||
response.infoLog += '☒File is not video \n';
|
||||
response.processFile = false;
|
||||
return response;
|
||||
}
|
||||
|
||||
// Set up required variables.
|
||||
let ffmpegCommandInsert = '';
|
||||
let subtitleIdx = 0;
|
||||
let convert = false;
|
||||
let assExists = false;
|
||||
let pgsExists = false;
|
||||
let tmpInfoLog = ""
|
||||
|
||||
for (let i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||
try {
|
||||
if (file.ffProbeData.streams[i].codec_type.toLowerCase() === 'subtitle') {
|
||||
// for debug
|
||||
response.infoLog += `☒Subtitle stream 0:s:${subtitleIdx} - ${file.ffProbeData.streams[i].tags.title} - ${file.ffProbeData.streams[i].codec_name} \n`
|
||||
if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'ass') {
|
||||
assExists = true;
|
||||
} else if (file.ffProbeData.streams[i].codec_name.toLowerCase() === 'hdmv_pgs_subtitle') {
|
||||
pgsExists = true;
|
||||
// prepare to remove pgs subtitle stream
|
||||
ffmpegCommandInsert += `-map -0:s:${subtitleIdx} `;
|
||||
tmpInfoLog += `☒Subtitle stream detected as PGS when SubStationAlpha subtitles exists. Removing subtitle stream 0:s:${subtitleIdx} - ${file.ffProbeData.streams[i].tags.title} - ${file.ffProbeData.streams[i].codec_name}. \n`;
|
||||
}
|
||||
subtitleIdx += 1;
|
||||
}
|
||||
} catch (err) {
|
||||
// Error
|
||||
}
|
||||
}
|
||||
|
||||
// only convert when both types of subs exist
|
||||
convert = pgsExists && assExists;
|
||||
|
||||
// Convert file if convert variable is set to true.
|
||||
if (convert === true) {
|
||||
response.processFile = true;
|
||||
response.preset = `, -map 0 ${ffmpegCommandInsert}-c copy -max_muxing_queue_size 9999`;
|
||||
response.container = `.${file.container}`;
|
||||
response.reQueueAfter = true;
|
||||
response.infoLog += tmpInfoLog;
|
||||
} else {
|
||||
response.processFile = false;
|
||||
response.infoLog += "☑File doesn't contain subtitle tracks that require modification.\n";
|
||||
}
|
||||
return response;
|
||||
};
|
||||
module.exports.details = details;
|
||||
module.exports.plugin = plugin;
|
||||
Loading…
Reference in new issue