HaveAGitGat / Tdarr_Plugins

Tdarr Plugins
GNU General Public License v3.0
135 stars 151 forks source link

"stream size" keep old size after transcoding #101

Closed Nosirus closed 9 months ago

Nosirus commented 3 years ago

I try to start again from scratch my plugins by taking inspiration from the great work done by others (I start in coding) but I have a problem with ffmpeg, some mkv keeps the statistics after transcoding, like the stream size. (it seems that handbrake doesn't have this problem.)

it seemed to me that "-map 0 -map_metadata:g -1" solved this problem but not and -map_metadata -1 makes me lose languages...

I refuse no help ! see same suggestion :)

function details() { return { id: "Tdarr_Plugin_b38x_Nosirus_h265_aac_no_meta", Stage: "Pre-processing", Name: "Nosirus h265, aac, no meta, subs kept", Type: "Video", Description:[Contains built-in filter] If the file is not in h265 it will be trancoded into h265 with FFmpeg using the following command '-e x265 -q 22 --encoder-preset slow --all-audio --all-subtitles copy:aac -E fdk_aac -Q 4 -x aq-mode=3'. If no aac, aac track will be added. Subtitles are kept. Metadata is removed.\n\n `, Version: "1.01", Link: "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_b38x_Nosirus_h265_aac_no_meta.js", Tags: "pre-processing,ffmpeg,h265,", }; }

function plugin(file) { var response = { processFile: false, preset: "", container: ".mkv", handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, infoLog: "", };

if (file.fileMedium !== "video") {
    response.processFile = false;
    response.infoLog += "☒ File is not a video! \n";
return response;
} else {
    response.infoLog += "☑ File is a video! \n";

    var videoIdx = 0;
    var extraArguments = "";
    var img = false;

    for (var i = 0; i < file.ffProbeData.streams.length; i++) {
        if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") {
            if (file.ffProbeData.streams[i].codec_name == "mjpeg" || file.ffProbeData.streams[i].codec_name == "png" || file.ffProbeData.streams[i].codec_name == "bmp") {
                img = true;
                extraArguments += ` -map -v:${videoIdx} `;
            }
        videoIdx++;
        }
    }

    if (img === true) {
        response.processFile = true;
        response.preset += `, -map 0 -c copy ${extraArguments} `;
        response.infoLog += "☒ The file has an image, removing! \n";
    return response;
    } else {
        response.infoLog += "☑ File doesn't contain any unwanted image! \n";

        if (file.ffProbeData.streams[0].codec_type != "video") {
            response.processFile = true;
            response.preset = `, -map 0:v? -map 0:a? -map 0:s? -map 0:d? -map 0:t? -c copy`
            response.infoLog += "☒ Video is not in the first stream! \n"
        return response
        } else {
            response.infoLog += "☑ File has video in first stream! \n"
            if (file.ffProbeData.streams[0].codec_name == "hevc") {
                response.processFile = false;
                response.infoLog += "☑ File is already in hevc! \n";
            } else {
                if (file.video_resolution === "480p" || file.video_resolution === "576p") {
                    var crf = 22
                } else if (file.video_resolution === "720p") {
                    var crf = 24
                } else if (file.video_resolution === "1080p") {
                    var crf = 26
                }
                response.processFile = true;
                response.preset = `, -map 0 -c copy -c:v:0 libx265 -preset:v ultrafast -pix_fmt yuv420p10le -crf ${crf} -x265-params "aq-mode=3:no-sao=1:me=3:subme=5:rd=4:bframes=8:rc-lookahead=80:deblock=-2\-2:no-info=1" -max_muxing_queue_size 1024 `;
                response.infoLog += `☒ File is ${file.video_resolution} but is not hevc, will be transcoded in crf ${crf}! \n`;
            }
        }
    }

var audioIdx = -1;
var ffmpegCommandInsert = "";
var hasnonAACTrack = false;

for (var i = 0; i < file.ffProbeData.streams.length; i++) {
    try {
        if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
            audioIdx++;
        }
    } catch (err) {}
    try {
        if (file.ffProbeData.streams[i].codec_name !== "aac" && file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
            ffmpegCommandInsert += `-c:a:${audioIdx} libfdk_aac -profile:a aac_he -vbr 3 -signaling implicit `;
            hasnonAACTrack = true;
        }
    } catch (err) {}
}
var ffmpegCommand = `-fflags +genpts, -map 0 -c copy ${ffmpegCommandInsert} `;

if (hasnonAACTrack == true) {
    response.processFile = true;
    response.preset = ffmpegCommand;
    response.infoLog += "☒ File has audio which is not in aac! \n";
return response;
} else {
    response.infoLog += "☑ All audio streams are in aac! \n";
}

if (file.ffProbeData.streams[0].codec_name == "hevc" && hasnonAACTrack == false && file.container != "mkv") {
    response.processFile = true;
    response.preset = `, -map 0 -c copy`;
    response.infoLog += "☒ File is not in mkv container! \n";
return response;
} else {
    response.infoLog += "☑ File is in mkv container! \n";
}

if (file.meta.Title != undefined) {
    response.processFile = true;
    response.preset = `, -metadata title="" -metadata comment="" -map 0 -c copy `;
    response.infoLog += "☒ File has title metadata \n";
return response;
} else {
    response.infoLog += "☑ File has no title metadata \n";
}
    response.infoLog += "☑ File meets conditions! \n";
return response;
}

}

module.exports.details = details; module.exports.plugin = plugin;`

Nosirus commented 3 years ago

I will always need help with this problem.

I tried to run "Tdarr_Plugin_JB69_JBHEVCQSZ_PostFix" but without success, can the language of the tracks be retrieved and then reintegrated?

I thought of "var lang = file.ffProbeData.streams[i].MediaLanguageCode;" something like this for each stream (audio and subtitle)

HaveAGitGat commented 9 months ago

Reopen if needed