en-US/about_ConvertVTTAssets.help.txt
TOPIC about_ConvertVTTAssets SHORT DESCRIPTION Enterprise-grade PowerShell module for Foundry VTT asset optimization with modular architecture, parallel processing, complete undo capability, and professional reporting. LONG DESCRIPTION ConvertVTTAssets v1.6.0 provides comprehensive asset optimization for Foundry Virtual Tabletop with enterprise-scale performance, modular architecture, and safety features. The module transforms media assets through intelligent conversion (WebM/WebP) and filename sanitization while maintaining quality and supporting transparency. Features parallel processing for 3-4x performance improvement, chunked memory management for 50,000+ files, complete undo capability, and professional HTML reporting. Version 1.6.0 represents a major architectural evolution with 10-module design, ThreadJob-based parallel processing, comprehensive undo system, and enterprise-grade memory management. Developed through collaboration between human expertise and AI assistance to create a production-ready solution for large-scale asset optimization. PREREQUISITES PowerShell Requirements: - PowerShell 7.0+ recommended for full functionality including parallel processing - Windows PowerShell 5.1 minimum (sequential processing only) - ThreadJob module (auto-loaded in PowerShell 7+) External Tools: - FFmpeg and FFprobe must be installed and available in system PATH - Download from: https://www.gyan.dev/ffmpeg/builds/ - Alternatively, specify paths using -FfmpegPath and -FfprobePath parameters System Requirements: - Windows 10/11 or Windows Server 2016+ - 4GB RAM minimum, 8GB+ recommended for parallel processing - Multi-core CPU recommended for optimal parallel performance - Sufficient disk space for converted files (typically 40-50% of source size) MODULE ARCHITECTURE ConvertVTTAssets v1.6.0 uses a clean modular architecture with 10 components: Core Components: - ConvertVTTAssets.psd1: Module manifest with metadata - ConvertVTTAssets.psm1: Main loader and module interface - ConvertVTTAssets.Core.ps1: Parallel processing engine (PowerShell 7+) Private Functions (Internal): - SharedHelpers.ps1: Core utility functions and FFmpeg integration - ReportGeneration.ps1: Professional HTML reporting system - FilenameHelpers.ps1: Filename sanitization and validation - ProcessingHelpers.ps1: Enterprise-scale processing and memory management Public Functions (User Interface): - Convert-ToWebM.ps1: Animated content conversion - Convert-ToWebP.ps1: Static image conversion - Optimize-FileNames.ps1: Filename and directory sanitization - Undo-FileNameOptimization.ps1: Complete rollback capability Benefits of Modular Design: - Enhanced maintainability with focused responsibilities - Professional code organization with comprehensive documentation - Scalable architecture supporting enterprise requirements - Clear separation between public interface and internal logic FUNCTIONS Optimize-FileNames Comprehensive filename and directory sanitization for web server compatibility with enterprise-scale performance, undo capability, and professional reporting. Parameters: -Root <string> Source directory (default: "." | any valid path) -SpaceReplacement <string> Space handling (default: "Underscore" | "Dash" | "Remove") -ThrottleLimit <int> Parallel thread count (default: 8 | range: 1-32) -ChunkSize <int> Items per chunk (default: 1000 | range: 100-50,000) Switch Parameters: -RemoveMetadata [switch] Remove content in brackets/parentheses -LowercaseExtensions [switch] Force extensions to lowercase -PreserveCase [switch] Keep original case (default converts to lowercase) -ExpandAmpersand [switch] Replace & with 'and' instead of underscore -NoRecurse [switch] Only process root directory -Parallel [switch] Enable parallel processing (PowerShell 7+ only) -GenerateReport [switch] Create HTML preview report without making changes -Silent [switch] Suppress progress output -Force [switch] Overwrite existing files -WhatIf [switch] Preview changes without applying Optional Parameters: -LogPath <string> Log file path (format: .csv or .json) -UndoLogPath <string> Save undo information for rollback -ReportPath <string> Custom path for HTML report -IncludeExt <string[]> Array of extensions to include -ExcludeExt <string[]> Array of extensions to exclude Character Transformation Rules: - Spaces: converted to underscores, dashes, or removed - Apostrophes ('): removed completely - Brackets [], parentheses (), braces {}: converted to dashes - Colons (:): converted to dashes - Ampersands (&): converted to underscores or 'and' - Special characters (!@#$%^~`): removed - Reserved Windows names: detected and flagged - Long filenames: truncated with warnings NEW in v1.6.0: - Complete undo system with JSON-based logs - Professional HTML report generation with risk assessment - Parallel processing with configurable thread throttling - Chunked memory management for enterprise-scale operations - Two-phase validation system for safe operations Undo-FileNameOptimization Complete rollback capability for filename optimization operations with validation, dependency tracking, and comprehensive error handling. Required Parameters: -UndoLogPath <string> Path to undo log file (JSON format) Switch Parameters: -Force [switch] Overwrite conflicts during restoration -Silent [switch] Suppress progress output -WhatIf [switch] Preview undo operations without applying Optional Parameters: -BackupUndoLogPath <string> Create backup of undo log before processing Key Features: - Two-phase validation: file integrity + conflict detection - Smart dependency tracking for directory operations - Comprehensive error reporting with partial rollback support - Backup creation option for additional safety - Complete audit trail of undo operations Safety Features: - File integrity validation before undo - Conflict detection and resolution - Dependency tracking for proper restoration order - Comprehensive logging of undo operations - Backup and rollback capabilities Convert-ToWebM Convert animated images and videos to WebM format with VP9/AV1 codecs, alpha channel preservation, and enterprise-scale parallel processing. Parameters: -Root <string> Source directory (default: "." | any valid path) -MaxFPS <int> Maximum framerate (default: 30 | range: 1-240) -MaxWidth <int> Maximum width pixels (default: 1920 | range: 64-8192) -Codec <string> Video codec (default: "vp9" | "av1") -AlphaMode <string> Alpha handling (default: "auto" | "force" | "disable") -MaxBitrateKbps <int> Bitrate ceiling (default: 0 - no limit | any positive integer) -ThrottleLimit <int> Simultaneous conversions (default: 4 | range: 1-64) -FfmpegPath <string> FFmpeg executable path (default: "ffmpeg" | any valid path) -FfprobePath <string> FFprobe executable path (default: "ffprobe" | any valid path) Switch Parameters: -NoRecurse [switch] Only process root directory -Parallel [switch] Enable multi-threaded processing (PowerShell 7+ only) -Force [switch] Re-convert even if destination exists -DeleteSource [switch] Send originals to Recycle Bin after conversion -Silent [switch] Suppress progress output -WhatIf [switch] Preview what would be converted Optional Parameters: -OutputRoot <string> Destination directory (mirrors source structure) -AlphaBackground <string> Background color when disabling alpha (e.g., '#000000') -LogPath <string> Log file path (format: .csv or .json) -IncludeExt <string[]> Additional extensions to process -ExcludeExt <string[]> Extensions to skip Supported Input Formats: .gif, .webp (animated), .mp4, .m4v, .mov, .mkv, .apng Key Features: - VP9 (default) and AV1 codec support for optimal compression - Automatic alpha channel detection and preservation - FPS capping for performance optimization (1-240 fps) - Width limiting for file size control (64-8192 pixels) - Audio stripping for smaller file sizes - CRF-based quality encoding for consistent results - Parallel processing for 3-4x performance improvement Convert-ToWebP Convert static images to WebP format with configurable quality settings, lossless/lossy options, and enterprise-scale parallel processing. Parameters: -Root <string> Source directory (default: "." | any valid path) -Quality <int> Compression quality (default: 80 | range: 1-100) -MaxWidth <int> Maximum width pixels (default: 4096 | range: 64-8192) -ThrottleLimit <int> Simultaneous conversions (default: 4 | range: 1-64) -FfmpegPath <string> FFmpeg executable path (default: "ffmpeg" | any valid path) -FfprobePath <string> FFprobe executable path (default: "ffprobe" | any valid path) Switch Parameters: -Lossless [switch] Enable lossless compression (ignores Quality setting) -NoRecurse [switch] Only process root directory -Parallel [switch] Enable multi-threaded processing (PowerShell 7+ only) -Force [switch] Re-convert even if destination exists -DeleteSource [switch] Send originals to Recycle Bin after conversion -Silent [switch] Suppress progress output -WhatIf [switch] Preview what would be converted Optional Parameters: -OutputRoot <string> Destination directory (mirrors source structure) -LogPath <string> Log file path (format: .csv or .json) -IncludeExt <string[]> Additional extensions to process -ExcludeExt <string[]> Extensions to skip Supported Input Formats: .png, .jpg, .jpeg, .tif, .tiff, .bmp Key Features: - Lossy and lossless compression modes - Automatic transparency preservation for PNG sources - Quality control with 1-100 range (higher = better quality) - Width limiting for file size control (64-8192 pixels) - Batch processing with intelligent skip logic - Parallel processing for 3-4x performance improvement RECOMMENDED WORKFLOW For optimal Foundry VTT asset preparation, follow this enterprise workflow: 1. Generate Preview Report (Risk Assessment): Optimize-FileNames -Root "D:\FoundryAssets" -RemoveMetadata -GenerateReport 2. Review HTML Report: - Examine proposed changes and risk warnings - Validate time estimates and resource requirements - Confirm settings meet organizational standards 3. Sanitize Filenames with Undo Capability: Optimize-FileNames -Root "D:\FoundryAssets" -RemoveMetadata -UndoLogPath "undo.json" 4. Convert Animated Content with Parallel Processing: Convert-ToWebM -Root "D:\FoundryAssets" -OutputRoot "D:\Optimized" -Parallel 5. Convert Static Images with Parallel Processing: Convert-ToWebP -Root "D:\FoundryAssets" -OutputRoot "D:\Optimized" -Parallel 6. Rollback if Needed: Undo-FileNameOptimization -UndoLogPath "undo.json" PERFORMANCE & SCALABILITY Version 1.6.0 introduces enterprise-grade performance optimizations: Parallel Processing Benefits: - 3-4x speed improvement with ThreadJob engine - Configurable thread throttling (1-32 threads) - Automatic fallback for PowerShell 5.1 - Resource-aware processing with system monitoring Memory Management Features: - Chunked processing for 50,000+ files without memory exhaustion - O(chunk_size) memory usage instead of O(n) for scalability - Configurable chunk sizes (100-50,000 items) based on available RAM - Forced garbage collection between chunks for long operations Benchmark Results (1,000 files): Sequential Processing (v1.5.2): ~17 minutes Parallel Processing (v1.6.0): ~4 minutes Performance Improvement: 4.25x faster Enterprise Configuration Guidelines: High-Performance Server (32 cores, 64GB RAM): -Parallel -ThrottleLimit 24 -ChunkSize 5000 Standard Workstation (8 cores, 16GB RAM): -Parallel -ThrottleLimit 6 -ChunkSize 1000 Limited Resources (4 cores, 8GB RAM): -Parallel -ThrottleLimit 3 -ChunkSize 500 PROFESSIONAL REPORTING Generate comprehensive HTML reports before making changes: Report Features: - Professional HTML formatting suitable for stakeholder sharing - Complete change preview with before/after comparisons - Risk assessment with color-coded warning system (High/Medium/Low) - Time estimation algorithms for operation planning - Settings documentation for audit trails - Interactive summary dashboard with key metrics Report Generation: # Generate report with automatic naming Optimize-FileNames -Root "D:\Assets" -GenerateReport # Custom report path for organizational standards Optimize-FileNames -Root "D:\Assets" -GenerateReport -ReportPath "preview.html" Report Contents: - Summary statistics and operation metrics - Detailed item-by-item change listings - Risk warnings and potential conflicts - Time estimates and resource requirements - Complete settings documentation - Professional styling for business presentations UNDO SYSTEM Complete rollback capability for filename operations: Undo Log Creation: # Automatic undo log generation during optimization Optimize-FileNames -Root "D:\Assets" -UndoLogPath "undo.json" Undo Operations: # Basic rollback with validation Undo-FileNameOptimization -UndoLogPath "undo.json" # With backup creation for additional safety Undo-FileNameOptimization -UndoLogPath "undo.json" -BackupUndoLogPath "backup.json" # Preview undo operations without applying Undo-FileNameOptimization -UndoLogPath "undo.json" -WhatIf Undo System Features: - Complete operation reversal with file integrity validation - Two-phase validation: integrity checking + conflict detection - Smart dependency tracking for directory operations - Comprehensive error reporting with partial rollback support - JSON-based logs with operation metadata and timestamps - Backup creation option for additional safety measures PROGRESS TRACKING Real-time progress information with enterprise-grade feedback: Standard Progress Output: [25%] Processing 1/4: animated_token.gif ✓ Converted: animated_token.webm (Size reduction: -73.5%) ⚠ Skipped: Already up-to-date ✗ Failed: Error message details Filename Optimization Progress: [50%] Checking 5/10: [Dir] player's handbook ✓ Renamed: player's handbook → players_handbook ✓ Already optimized: optimized_file.png Parallel Processing Progress: Processing file chunk 3/10 (30%) [75%] File 750/1000: large_map.png Engine: ThreadJob (WebM) | ThrottleLimit=8 Memory Management Feedback: Discovered 50,000 files for processing Processing in 50 chunks of 1000 files Memory usage after cleanup: 245.3 MB Use -Silent switch to suppress progress output and display only summary results. LOGGING CAPABILITIES Comprehensive logging with flexible output formats: Log Format Determination (by file extension): .csv → CSV format (tabular, Excel-compatible) .json → JSON format (nested structure with full details) other → Defaults to CSV format for compatibility Logging Examples: -LogPath "D:\Logs\conversions.csv" # Creates CSV log -LogPath "D:\Logs\conversions.json" # Creates JSON log -LogPath "D:\Logs\conversions.log" # Creates CSV log (default) Conversion Log Contents: - Timestamp for each conversion operation - Source and destination file paths - Conversion status (Converted/Skipped/Failed/WhatIf) - Processing duration in seconds - File sizes before and after conversion - Size reduction percentage and bytes saved - Codec, quality, and settings used - Detailed error messages for failed operations Filename Optimization Log Contents: - Timestamp for each rename operation - Item type (File/Directory) and processing status - Original and new paths with full directory structure - Original and new names for comparison - Operation status with detailed error reporting - Settings used (RemoveMetadata, SpaceReplacement, etc.) - Undo operation ID for rollback capability - Dependency tracking for complex directory operations EXAMPLES Complete Enterprise Workflow with v1.6.0 Features: # 1. Generate comprehensive preview report Optimize-FileNames ` -Root "D:\EnterpriseAssets" ` -RemoveMetadata ` -GenerateReport ` -ReportPath "D:\Reports\asset_analysis.html" # 2. Apply optimizations with undo capability and parallel processing Optimize-FileNames ` -Root "D:\EnterpriseAssets" ` -RemoveMetadata ` -UndoLogPath "D:\Logs\undo.json" ` -Parallel ` -ThrottleLimit 16 ` -ChunkSize 2000 # 3. Convert animated content with enterprise settings Convert-ToWebM ` -Root "D:\EnterpriseAssets" ` -OutputRoot "D:\Optimized" ` -MaxFPS 24 ` -MaxWidth 1920 ` -Codec vp9 ` -Parallel ` -ThrottleLimit 8 ` -LogPath "D:\Logs\webm_conversion.json" # 4. Convert static images with quality optimization Convert-ToWebP ` -Root "D:\EnterpriseAssets" ` -OutputRoot "D:\Optimized" ` -Quality 85 ` -MaxWidth 4096 ` -Parallel ` -ThrottleLimit 8 ` -LogPath "D:\Logs\webp_conversion.json" # 5. Rollback filename changes if needed Undo-FileNameOptimization ` -UndoLogPath "D:\Logs\undo.json" ` -BackupUndoLogPath "D:\Backups\undo_backup.json" Foundry VTT Optimized Workflow: # Sanitize filenames for web server compatibility Optimize-FileNames -Root "D:\FoundryAssets" -RemoveMetadata -SpaceReplacement Underscore # Convert animated maps and tokens Convert-ToWebM -Root "D:\FoundryAssets" -OutputRoot "D:\Optimized" -MaxFPS 24 -Parallel # Convert static images with appropriate quality Convert-ToWebP -Root "D:\FoundryAssets" -OutputRoot "D:\Optimized" -Quality 85 -Parallel Advanced Filename Sanitization: # Remove metadata and expand ampersands with custom settings Optimize-FileNames ` -Root "D:\ComplexAssets" ` -RemoveMetadata ` -ExpandAmpersand ` -SpaceReplacement Dash ` -PreserveCase ` -LogPath "D:\Logs\filename_changes.csv" High-Performance Batch Conversion: # Convert large video library with optimal settings Convert-ToWebM ` -Root "D:\VideoLibrary" ` -OutputRoot "D:\OptimizedVideos" ` -MaxFPS 30 ` -MaxWidth 1920 ` -Codec av1 ` -Parallel ` -ThrottleLimit 12 ` -DeleteSource ` -LogPath "D:\Logs\batch_conversion.json" FILENAME TRANSFORMATION EXAMPLES Character Handling Demonstrations: Default Behavior: "player's handbook.pdf" → "players_handbook.pdf" "map [night time].png" → "map-night_time.png" "token (v2).webp" → "token-v2.webp" "maps & tokens/" → "maps_tokens/" "chapter 1: intro.txt" → "chapter_1-intro.txt" "file!!!.jpg" → "file.jpg" With -RemoveMetadata Switch: "map [night time].png" → "map.png" "token (v2).webp" → "token.webp" "file(1920x1080-gridless).jpg" → "file.jpg" "document [final version].pdf" → "document.pdf" With -ExpandAmpersand Switch: "maps & tokens/" → "maps_and_tokens/" "D&D Campaign.txt" → "d_and_d_campaign.txt" "Heroes & Villains.pdf" → "heroes_and_villains.pdf" With -SpaceReplacement Dash: "my awesome map.png" → "my-awesome-map.png" "character sheet template.pdf" → "character-sheet-template.pdf" With -PreserveCase Switch: "README.md" → "README.md" (instead of "readme.md") "MyCharacter.json" → "MyCharacter.json" (instead of "mycharacter.json") PERFORMANCE OPTIMIZATION Guidelines for optimal performance across different hardware configurations: Thread Configuration Recommendations: - Set -ThrottleLimit to (CPU cores - 2) for optimal performance - Use -Parallel with PowerShell 7+ for maximum benefit - Monitor system resources during processing - Adjust based on other running applications Memory Management Strategies: - For 10,000+ files, use chunked processing with appropriate -ChunkSize - Adjust -ChunkSize based on available RAM (1000 default works for most systems) - Monitor memory usage during large operations - Use conservative settings for systems with limited resources Asset-Specific Optimization Settings: Battle Maps: -MaxWidth 2560 -MaxFPS 24 -Quality 80-85 Animated Tokens: -MaxWidth 512 -MaxFPS 30 -Quality 85-90 Static Tokens: -MaxWidth 512 -Quality 85-90 Portraits: -MaxWidth 1024 -Quality 85-90 UI Elements: -MaxWidth 512 -Quality 90-95 Background Art: -MaxWidth 4096 -Quality 80-85 File Organization Best Practices: - Run Optimize-FileNames first to ensure web compatibility - Process similar asset types together for consistent settings - Use -OutputRoot to preserve originals during conversion - Review logs before using -DeleteSource for safety - Group assets by size/complexity for optimal batch processing TROUBLESHOOTING Common Issues and Solutions: "ffmpeg not found" Error: - Ensure FFmpeg is installed and in system PATH - Use -FfmpegPath parameter to specify full executable path - Verify installation with: ffmpeg -version "Cannot be loaded because running scripts is disabled": - Run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - This allows local scripts while blocking unsigned remote scripts Parallel Processing Not Working: - Verify PowerShell 7+ installation: $PSVersionTable.PSVersion - Ensure ThreadJob module availability: Get-Module ThreadJob -ListAvailable - Check for ThreadJob import errors in verbose output Memory Issues with Large File Sets: # Reduce memory usage with conservative settings Optimize-FileNames -Root "D:\HugeLibrary" -Parallel -ChunkSize 500 -ThrottleLimit 4 Files Not Converting: - Verify file extensions match supported formats or use -IncludeExt - Test individual files with: ffprobe "path\to\file" - Check source and destination directory permissions - Review log files for specific error messages Filename Optimization Issues: - Use -WhatIf to preview changes before applying them - Generate reports with -GenerateReport for risk assessment - Some characters are illegal in Windows and cannot exist in filenames - Directories are processed before files to maintain path integrity Undo Operations Failing: - Verify undo log file exists and contains valid JSON - Ensure files haven't been moved or deleted since optimization - Use -Force parameter to override file conflicts - Review detailed validation errors in console output - Check file permissions for rename operations NOTES Development and Architecture: Authors: Andres Yuhnke, Claude (Anthropic), ChatGPT (OpenAI) Version: 1.6.0 (Current) License: MIT License Architecture: Modular design with 10 focused components Version 1.6.0 Evolution: This release represents a major architectural transformation developed through collaboration between human domain expertise and AI-assisted development. The parallel processing engine, undo system, professional reporting, and enterprise memory management were implemented by Claude (Anthropic) to create a production-ready solution for large-scale asset optimization operations. Foundry VTT Integration: Filename sanitization follows official Foundry VTT media guidelines for optimal web server compatibility. Character handling rules are based on extensive testing with various web server configurations and Foundry VTT deployment scenarios. Foundry VTT Media Guide: https://foundryvtt.com/article/media/ Dependencies and Credits: FFmpeg Team: Provides the core media conversion engine ThreadJob Module: Enables parallel processing capabilities PowerShell Community: Inspiration for modular architecture patterns Enterprise Considerations: - Tested with file sets exceeding 50,000 items - Memory usage scales with chunk size, not total file count - Comprehensive logging suitable for audit requirements - Professional reporting for stakeholder communication - Complete rollback capability for operational safety SEE ALSO External Resources: FFmpeg Documentation: https://ffmpeg.org/documentation.html Foundry VTT Official Site: https://foundryvtt.com/ Foundry VTT Media Guide: https://foundryvtt.com/article/media/ PowerShell 7 Downloads: https://github.com/PowerShell/PowerShell Module Resources: PowerShell Gallery: https://www.powershellgallery.com/packages/ConvertVTTAssets GitHub Repository: https://github.com/andresyuhnke/ConvertVTTAssets Issue Tracker: https://github.com/andresyuhnke/ConvertVTTAssets/issues PowerShell Help System: Get-Help Convert-ToWebM -Detailed Get-Help Convert-ToWebP -Detailed Get-Help Optimize-FileNames -Detailed Get-Help Undo-FileNameOptimization -Detailed |