Skip to content

feat: Implement seamless log merging for x264/x265 encoders#1198

Open
Miralia wants to merge 5 commits into
rust-av:masterfrom
Miralia:master
Open

feat: Implement seamless log merging for x264/x265 encoders#1198
Miralia wants to merge 5 commits into
rust-av:masterfrom
Miralia:master

Conversation

@Miralia
Copy link
Copy Markdown

@Miralia Miralia commented Jan 21, 2026

What does this PR do?

This PR introduces a robust log merging mechanism for x264 and x265 (including variants) encoders. It intercepts per-chunk log output, filters irrelevant progress noise, and synthesizes a complete, standards-compliant log file at the end of the encoding process.

Motivation

Currently, chunked encoding in Av1an fragments encoder logs, making it impossible to analyze post-encode statistics (QP distribution, frame type usage, bitrate variability) for the entire video. Users relying on these logs for quality verification currently have no way to get a unified view.

Key Changes

  • Log Interception & Filtering (context.rs):
    • Intercepts stderr from encoder processes.
    • Implements a strict whitelist filter (preserving frame [IPB]:, encoded stats) to separate valuable data from progress bar noise.
    • Enforces newline sanitization to ensure atomic log writes, preventing log line concatenation issues on disk (which previously caused massive data loss in parsing).
  • Log Merging Logic (log_merge.rs):
    • New LogMerger struct that parses and aggregates statistics from temporary chunk logs.
    • Robust Anchor Parsing: Uses semantic anchors (frame X: ... Avg QP/QP:) instead of fragile punctuation checks. This ensures compatibility across different encoder versions and builds (e.g., standard x265 vs. Mod-by-Patman) and handles format variations gracefully.
  • Output:
    • Automatically generates a {output_file}.log adjacent to the target video.
    • Calculates global statistics (Bitrate, Average QP, Global FPS) from aggregated data, avoiding reliance on inconsistent encoder summary lines.
    • Fixes Windows UNC path display issues in console output.

How to test

  1. Run an encode with logging enabled:
    av1an -i input.mkv -e x265 -v " --log-level info" -o output.mkv
  2. Observe that output.mkv.log is created.
  3. Verify the log contains sequential frame statistics (I, P, B) and a correct final summary.

Checklist

  • Tested with x265 (standard & Mod builds)
  • Tested with x264
  • Verified log integrity on Windows (UNC paths handled)
  • Code follows existing project style

Adds functionality to intercept, parse, and merge per-chunk encoder logs into a single, comprehensive log file upon encoding completion.

Key features:
- **Automatic Log Merging**: Synthesizes a unified log file from individual chunk logs, preserving the order and integrity of frame data.
- **Encoder Support**: Native support for x264 and x265 (including variants), parsing I/P/B frame statistics, QP, and bitrate/size metrics.
- **Smart Filtering**: Intercepts stderr to filter out progress bar noise while whitelisting critical frame statistics for storage.
- **Summary Generation**: Auto-calculates final encoding statistics (Global FPS, Average Bitrate, Total Duration) based on aggregated chunk data.
- **Configurable Output**: Defaults to generating a {output}.log file, or respects the user-specified log path.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 16.02374% with 283 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.97%. Comparing base (1d10e1c) to head (e2694e3).

Files with missing lines Patch % Lines
av1an-core/src/log_merge.rs 0.00% 227 Missing ⚠️
av1an-core/src/context.rs 50.76% 32 Missing ⚠️
av1an-core/src/settings.rs 51.35% 18 Missing ⚠️
av1an-core/src/encoder/mod.rs 20.00% 4 Missing ⚠️
av1an-core/src/broker.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1198      +/-   ##
==========================================
- Coverage   62.76%   60.97%   -1.79%     
==========================================
  Files          23       24       +1     
  Lines        7310     7606     +296     
==========================================
+ Hits         4588     4638      +50     
- Misses       2722     2968     +246     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread av1an-core/src/broker.rs
Arc,
},
thread::available_parallelism,
// thread::available_parallelism,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should remove these lines rather than leaving them in commented out. (line 17 as well)

Comment thread av1an-core/src/context.rs
progress_file.write_all(serde_json::to_string(get_done())?.as_bytes())?;

if let Some(ref audio_output) = audio_output {
// Line 405 in original
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this comment is very useful, let's either improve or remove it.

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