Files
tdarr-plugs/agent_notes/audio_review.md
Tdarr Plugin Developer aa71eb96d7 Initial commit: Tdarr plugin stack
Plugins:
- misc_fixes v2.8: Pre-processing, container remux, stream conforming
- stream_organizer v4.8: English priority, subtitle extraction, SRT conversion
- combined_audio_standardizer v1.13: AAC/Opus encoding, downmix creation
- av1_svt_converter v2.22: AV1 video encoding via SVT-AV1

Structure:
- Local/ - Plugin .js files (mount in Tdarr)
- agent_notes/ - Development documentation
- Latest-Reports/ - Error logs for analysis
2025-12-15 11:33:36 -08:00

4.6 KiB
Raw Blame History

Audio Standardizer Plugin - Code Review

🔴 Critical Issues

1. Quality preset bitrate display is incorrect (Line 623-624)

response.infoLog += `  Stereo downmix bitrate: ${stereoBitrate}kbps (calculated: 2 × ${inputs.bitrate_per_channel})\\n`;
  • Displays inputs.bitrate_per_channel which could be 'auto' or 'original' (not a number)
  • Should show actual numerical value used

2. Missing validation for preset quality (Line 261)

const preset = QUALITY_PRESETS[inputs.quality_preset];
if (!preset) {
  return inputs; // Silent failure
}
  • Should log warning if preset not found

🟡 Medium Issues

3. Inconsistent emoji usage in logs

  • Mix of ☑️ (check) for errors and successes
  • Use for errors, for success, for info

4. Unused small_size preset has incorrect Opus bitrate

small_size: {
  opus_bitrate_per_channel: '48',  // 48kbps is very low for Opus
  • Opus minimum bitrate should be 64kbps for acceptable quality
  • 48kbps may produce poor audio

5. Duplicate bitrate calculation in downmix (Lines 319, 590)

const stereoBitrate = calculateBitrate(inputs, 2, null); // Line 319
...
const stereoBitrate = calculateBitrate(inputs, 2, null); // Line 590
  • Calculate once and reuse

6. No minimum bitrate threshold

  • Unlike video plugin, no floor for calculated bitrates
  • Could result in unusable <16kbps audio with certain inputs

7. Opus compression level hardcoded (Line 299)

-compression_level 10
  • Could be exposed as input option (0-10 range)
  • Higher = slower but better quality

🟢 Potential Improvements

8. Add audio sample rate handling

  • No validation or handling of unusual sample rates
  • Could add resampling option (48kHz standard for streaming)

9. Add language/title metadata preservation

  • Currently only adds "2.0 Downmix" title
  • Should preserve original audio titles and language tags

10. Add normalization option

  • EBU R128 loudness normalization would be useful
  • Common for streaming content

11. Version bump needed

  • After fixes, increment from 1.04

12. Add channel layout validation for Opus incompatible layouts

  • Currently only logs layout compatibility
  • Could warn user before processing

13. Improve auto bitrate calculation

const targetBitrate = 64 * channels; // Line 236
  • 64kbps may be overkill for mono/stereo
  • Could use: Math.max(32, Math.min(96, 48 * Math.log2(channels + 1)))

14. Add AAC profile selection

  • Currently uses default AAC-LC
  • Could expose AAC-LC vs AAC-HE vs AAC-HEv2

15. Add 5.1 → 5.1 downmix from 7.1

  • Currently only creates 2ch from 6ch/8ch
  • Missing 8ch → 6ch downmix option

📋 Redundancies

16. Duplicate COMPATIBLE_CODECS array (Line 171)

  • Already defined as constants
  • Use CODECS.AAC, CODECS.OPUS, CODECS.LIBOPUS directly everywhere

17. Redundant opus codec check (Lines 530-537)

if (!streamNeedsTranscode) {
  streamNeedsTranscode = true; // Redundant assignment
}
  • Can simplify logic

18. Empty lines (415-416)

  • Two blank lines in validation function

🔧 Optimizations

19. Use Set for OPUS_INCOMPATIBLE_LAYOUTS

const OPUS_INCOMPATIBLE_LAYOUTS = new Set([...]);
  • Faster lookups with .has() vs .includes()

20. Cache regex for star removal

  • Currently creates new slice operation each iteration
  • Minor but could optimize

21. Reduce try-catch blocks

  • Three separate try-catch blocks (Lines 474, 525, 585)
  • Could consolidate error handling

🎯 Priority Fixes Table

Priority Line(s) Issue Fix
🔴 High 623-624 Incorrect bitrate display Show numerical value
🔴 High 261-264 Silent preset failure Add warning log
🟡 Medium throughout Inconsistent emoji Standardize: ⚠️
🟡 Medium 212 Low Opus bitrate Change 48 → 64 kbps
🟡 Medium 319, 590 Duplicate calculation Calculate once
🟡 Medium - No minimum bitrate Add 32kbps floor
🟢 Low - No sample rate handling Add resampling option
🟢 Low - Missing metadata Preserve titles/languages
🟢 Low 171 Redundant array Use constants directly
🟢 Low 299 Hardcoded compression Expose as option

Summary

Total Issues Found: 20
Critical: 2
Medium: 5
Low/Enhancement: 13

Most pressing fixes:

  1. Fix bitrate display in final summary
  2. Add minimum bitrate threshold (32kbps)
  3. Fix small_size preset Opus bitrate (48 → 64 kbps)
  4. Standardize emoji usage
  5. Add preset failure warning