Implement low bitrate HDR logic for video encoding - #4
Merged
Merged
Conversation
- Add HDR requirement to low bitrate detection: only HDR videos < 5 Mbps skip encoding - Update video state machine to automatically mark qualifying videos as encoded - Add comprehensive test coverage for HDR/bitrate combinations - Update valid state transitions to allow direct needs_analysis -> encoded This ensures only genuinely efficient HDR content skips the expensive encoding process while maintaining quality for non-HDR content.
There was a problem hiding this comment.
Pull Request Overview
This PR implements selective video encoding logic that automatically skips encoding for HDR videos with low bitrates (< 5 Mbps), as these are likely already efficiently encoded.
- Adds low bitrate HDR detection logic to transition videos directly from
needs_analysistoencoded - Updates state machine to allow direct
needs_analysis→encodedandanalyzed→encodedtransitions - Comprehensive test coverage for all HDR/bitrate combinations and edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/reencodarr/media/video_state_machine.ex |
Implements low bitrate HDR detection logic and updates valid transitions |
test/reencodarr/media/video_state_machine_test.exs |
Adds comprehensive test coverage and updates existing tests to avoid new logic |
- Convert bitrate from bps to Mbps for clearer log messages - Update log message to accurately reflect HDR requirement - Format decimal places for better readability
- Add build cache for _build directory with proper cache keys - Cache ab-av1 binary to avoid repeated downloads and compilation - Cache apt packages to speed up tool installation - Update to actions/cache@v4 for better performance - Add mediainfo to installed tools for completeness - Separate deps compilation from project compilation for better caching - Add code quality checks (format, credo) to CI pipeline - Use more specific cache keys based on mix.lock and source files
- Add bitrate > 0 guard to low_bitrate?/1 function to prevent division by zero - Add comprehensive test for zero bitrate HDR videos - Ensure zero bitrate videos are properly handled and validated - Test confirms zero bitrate fails validation as expected (invalid bitrate)
- Update nixpkgs to latest version for improved package availability
- Exclude /var/cache/apt/archives/partial and lock files from cache - These files have permission restrictions that prevent caching - Maintains apt package caching while avoiding permission errors
- Cache apt packages to ~/apt-cache (user-writable directory) - Configure apt to use custom cache directory via APT_CONFIG - Avoids permission issues with system directories - Maintains performance benefits of package caching
- Skip installation of man pages and documentation to speed up package install - Add DEBIAN_FRONTEND=noninteractive to avoid interactive prompts - Use --no-install-recommends to reduce package bloat - Remove duplicate apt-get commands that were accidentally added - Should significantly reduce CI build time for package installation
- Use awalsh128/cache-apt-pkgs-action@v1 for reliable apt package caching - Removes complex manual cache directory and permission handling - Eliminates need for custom APT_CONFIG and DEBIAN_FRONTEND setup - Action handles all optimization and caching automatically - Should resolve previous apt caching failures and improve CI reliability
- Remove PostgreSQL installation and setup steps since migrated to SQLite - Remove PostgreSQL wait/ready check that was adding unnecessary delay - SQLite databases are created automatically when tests run - Should further reduce CI build time and complexity
mjc
added a commit
that referenced
this pull request
Mar 5, 2026
Create TestPatterns module to eliminate duplicated test utilities: - Consolidated create_test_video() functions across 12+ test files - Unified find_flag_indices(), find_flag_value(), match_return_value() helpers - Centralized video creation patterns (HDR, Opus, 4K, Atmos variants) - Added comprehensive argument validation and assertion helpers - Eliminated ~300 lines of duplicated test helper code Also refactored DashboardFormatters to use delegation pattern: - Replace duplicated formatting functions with defdelegate - Consolidate format_fps, format_count, format_eta implementations - Eliminate format function duplication across multiple modules This addresses the #4 highest-impact duplication pattern identified in the analysis by creating single source of truth for test utilities.
mjc
added a commit
that referenced
this pull request
Mar 5, 2026
Implement low bitrate HDR logic for video encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements selective video encoding logic that automatically skips encoding for HDR videos with low bitrates, as these are likely already efficiently encoded.
Changes
Logic
Videos are automatically marked as encoded (skip encoding) if:
This ensures only genuinely efficient HDR content skips the expensive encoding process while maintaining quality for non-HDR content or higher bitrate HDR content.
Testing
All existing tests pass + 8 new tests covering: