Skip to content

Implement low bitrate HDR logic for video encoding - #4

Merged
mjc merged 10 commits into
mainfrom
feature/low-bitrate-hdr-logic
Sep 17, 2025
Merged

mjc merged 10 commits into
mainfrom
feature/low-bitrate-hdr-logic

Conversation

@mjc

@mjc mjc commented Sep 17, 2025

Copy link
Copy Markdown
Owner

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

  • Add HDR requirement: Only HDR videos with bitrate < 5 Mbps are marked as encoded
  • Update state machine: Videos meeting criteria transition directly from →
  • Comprehensive tests: Added test coverage for all HDR/bitrate combinations
  • State transitions: Updated valid transitions to allow direct →

Logic

Videos are automatically marked as encoded (skip encoding) if:

  1. Bitrate < 5,000,000 bps (5 Mbps) AND
  2. HDR field is not nil (contains HDR metadata like "HDR10")

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:

  • Low bitrate HDR → encoded
  • High bitrate HDR → analyzed
  • Low bitrate non-HDR → analyzed
  • Boundary conditions and edge cases

- 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.
Copilot AI review requested due to automatic review settings September 17, 2025 16:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_analysis to encoded
  • Updates state machine to allow direct needs_analysisencoded and analyzedencoded transitions
  • 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

Comment thread lib/reencodarr/media/video_state_machine.ex Outdated
Comment thread lib/reencodarr/media/video_state_machine.ex Outdated
- Convert bitrate from bps to Mbps for clearer log messages
- Update log message to accurately reflect HDR requirement
- Format decimal places for better readability
@mjc
mjc requested a review from Copilot September 17, 2025 17:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread lib/reencodarr/media/video_state_machine.ex
mjc added 8 commits September 17, 2025 11:27
- 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
mjc merged commit 89daba7 into main Sep 17, 2025
1 check passed
@mjc
mjc deleted the feature/low-bitrate-hdr-logic branch September 17, 2025 18:03
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants