HaveAGitGat / Tdarr_Plugins

Tdarr Plugins
GNU General Public License v3.0
140 stars 159 forks source link

Improve: plugin Tdarr_Plugin_henk_Add_Specific_Audio_Codec.js to choose by parameter audiostream before or after original audiostream #204

Open michpas opened 2 years ago

michpas commented 2 years ago

Many files have DTS and on Oled LG 2021 and 2020, Plex starts to transcode (due to no support for DTS). I have used this plugin to keep the original soundtrack, and add an EAC3 based on DTS. This works great. However for some reason plex on picks often the 1st soundtrack (DTS) and transcoding kicks in. I have updated the script to add the new (EAC3) track prior to the DTS one. Wanted to share this and ask if the script can be modified to either allow people to choose where to place new audio stream(prior or advance) or by detault put the new audiostrack prior.

The Parameter setting

{ name: "new_audiobefore", tooltip: Please change this to "before", if you wish the new audio stream to be added prior to the original. Otherwise, leave empty \\nExample:\\n before, },

The proposd changed

for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { const currStream = file.ffProbeData.streams[i]; if (currStream.codec_type.toLowerCase() === 'audio') {

if (inputs.new_audiobefore === '') { response.preset += -map 0:a:${indexCount}? -c:a:${streamCount} copy; streamCount += 1; }

  if (inputCodecs.includes(currStream.codec_name.toLowerCase())) {
    convertCount += 1;
    let bitrate = `-b:a:${streamCount} `;
    if (inputs.custom_bitrate_input) {
      bitrate += inputs.custom_bitrate_input;
    } else if (inputs.bitrate) {
      bitrate += `${inputs.auto_adjust ? (inputs.bitrate * (currStream.channels / 2)) : inputs.bitrate}k`;
    } else {
      bitrate = '128k';
    }
    response.preset += ` -map 0:a:${indexCount}? -c:a:${streamCount} ${inputs.output_codec || 'ac3'} -b:a ${bitrate} `
      + `-metadata:s:a:${streamCount} title=" " -metadata:s:a:${streamCount} copyright=henk_asac `
      + `-disposition:a:${streamCount} 0`;
    streamCount += 1;
  }

if (inputs.new_audiobefore === 'before') { response.preset += -map 0:a:${indexCount}? -c:a:${streamCount} copy; streamCount += 1; }

 indexCount += 1;
}

}

supersnellehenk commented 2 years ago

If you'd like to open a pr, would be easier to implement than this kinda scuffed paste. :)

michpas commented 2 years ago

hi. Haven't done this before; but tried. And opened a PR with the code suggestions. Hope this is okee now and can be pulled in