# Implementation Plan - Misc Fixes "Megamix" ## Goal Integrate functionality from `Migz1Remux`, `MigzImageRemoval`, and `lmg1_Reorder_Streams` into `Tdarr_Plugin_misc_fixes.js`. ## Proposed Changes ### 1. New Inputs | Name | Type | Default | Description | |------|------|---------|-------------| | `target_container` | String | `mkv` | Output container (mkv/mp4) | | `force_conform` | Boolean | `true` | Drop incompatible streams (e.g. mov_text in MKV) | | `remove_image_streams` | Boolean | `true` | Remove MJPEG/PNG/GIF video streams | | `ensure_video_first` | Boolean | `true` | Reorder streams: Video → Audio → Subtitles | | `fix_ts_timestamps` | Boolean | `true` | (Existing) Fix TS timestamp issues | ### 2. Logic Flow 1. **Load Inputs** & Defaults. 2. **Determine Action Needed**: * Compare `file.container` vs `inputs.target_container`. * Check `fix_ts_timestamps` (TS/AVI/MPG). 3. **Stream Analysis Loop**: * **Image Removal**: IF `remove_image_streams`: * Check `codec_name` (mjpeg, png, gif). * Add `-map -0:idx` to drop list. * **Conform**: IF `force_conform`: * **MKV**: Drop `mov_text`, `eia_608`, `timed_id3`, `data` streams. * **MP4**: Drop `hdmv_pgs_subtitle`, `eia_608`, `subrip` (srt?), `timed_id3`. * *Note: Migz drops srt (subrip) for MP4? FFmpeg supports tx3g, maybe not srt in mp4 in older versions? I'll stick to Migz logic but allow srt if modern.* -> *Migz explicitly drops 'subrip' for MP4. I will follow Migz logic for safety but might note it.* 4. **Construct Command**: * **Pre-input args**: * If TS/AVI/MPG: `-fflags +genpts`. * If TS & `fix_ts_timestamps`: `-fflags +genpts+igndts -avoid_negative_ts make_zero`. * **Mapping**: * If `ensure_video_first`: `-map 0:v? -map 0:a? -map 0:s? -map 0:d? -map 0:t?` * Else: `-map 0` * **Drops**: Append `-map -0:idx` for all dropped streams. * **Container**: Set output container to `target_container`. ### 3. Execution * Execute if: * Container mismatch. * Dropping streams (extraArguments > 0). * Fixing timestamps (TS/AVI). * Reordering needed? (Maybe always run if "Video First" is on and we want to enforce it). ## Verification Plan * Check TS files (ensure flags still apply). * Check MKV targets (ensure mov_text dropped). * Check MP4 targets (ensure pgs dropped). * Check image removal.