Skip to content

Conversation

@richiemcilroy
Copy link
Member

@richiemcilroy richiemcilroy commented Dec 29, 2025

Switches from fragmented MP4 on Windows to fragmented M4S

Greptile Summary

Replaces Windows fragmented MP4 recording with M4S (MPEG-DASH) segments by introducing WindowsFragmentedM4SMuxer and WindowsFragmentedM4SCameraMuxer. The new implementation leverages the existing SegmentedVideoEncoder which uses FFmpeg's DASH muxer to produce an init.mp4 initialization segment plus timestamped segment_NNN.m4s media segments.

Key changes:

  • Added crates/recording/src/output_pipeline/win_fragmented_m4s.rs with ~700 lines implementing both screen and camera muxers
  • Updated capture_pipeline.rs to use WindowsFragmentedM4SMuxer instead of WindowsSegmentedMuxer for fragmented Windows recordings
  • Fixed Windows path handling in segmented_stream.rs by converting backslashes to forward slashes for FFmpeg compatibility
  • Both muxers implement frame drop tracking, pause state handling, and proper encoder thread lifecycle management
  • Uses H264Preset::Ultrafast with 3-second segment duration by default

Confidence Score: 4/5

  • Safe to merge with minor risk - well-structured implementation that reuses proven components
  • The implementation follows established patterns from the macOS M4S muxer and reuses the battle-tested SegmentedVideoEncoder. The Windows path fix is correct. However, the large new file (~700 lines) has similar duplicate code between screen and camera muxers that could potentially be refactored. No critical bugs detected.
  • Pay close attention to win_fragmented_m4s.rs during testing - verify frame drop behavior and encoder thread cleanup work correctly under various recording scenarios

Important Files Changed

Filename Overview
crates/recording/src/output_pipeline/win_fragmented_m4s.rs New Windows M4S muxer implementation with screen and camera support, uses SegmentedVideoEncoder for fragmented output
crates/enc-ffmpeg/src/mux/segmented_stream.rs Added Windows path normalization for FFmpeg DASH muxer (backslash to forward slash conversion)
crates/recording/src/capture_pipeline.rs Switched Windows fragmented recording from WindowsSegmentedMuxer to WindowsFragmentedM4SMuxer with simplified config

Sequence Diagram

sequenceDiagram
    participant App as Desktop App
    participant Pipeline as Capture Pipeline
    participant Muxer as WindowsFragmentedM4SMuxer
    participant Encoder as SegmentedVideoEncoder
    participant FFmpeg as FFmpeg DASH Muxer
    participant Disk as File System

    App->>Pipeline: Start recording (fragmented=true)
    Pipeline->>Muxer: Setup muxer with config
    Muxer->>Disk: Create segments directory
    
    loop Video frames
        App->>Pipeline: Send video frame
        Pipeline->>Muxer: send_video_frame()
        
        alt First frame
            Muxer->>Encoder: start_encoder()
            Encoder->>FFmpeg: Initialize DASH muxer
            Note over Encoder,FFmpeg: Set init_seg_name="init.mp4"<br/>Set media_seg_name with forward slashes
            FFmpeg->>Disk: Create init.mp4
            Encoder->>Encoder: Spawn encoder thread
        end
        
        Muxer->>Encoder: Queue frame via channel
        Encoder->>Encoder: Convert D3D11 frame to FFmpeg
        Encoder->>FFmpeg: queue_frame()
        
        alt Segment boundary detected
            FFmpeg->>Disk: Write segment_NNN.m4s
            Encoder->>Encoder: Update manifest.json
        end
    end
    
    App->>Pipeline: Stop recording
    Pipeline->>Muxer: finish()
    Muxer->>Encoder: Send None (stop signal)
    Encoder->>Encoder: Join encoder thread
    Encoder->>FFmpeg: flush() and write_trailer()
    FFmpeg->>Disk: Finalize segments
    Encoder->>Disk: Write final manifest.json
    Muxer-->>Pipeline: Done
Loading

@greptile-apps
Copy link

greptile-apps bot commented Dec 29, 2025

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@richiemcilroy richiemcilroy merged commit d7673fb into main Dec 29, 2025
16 checks passed
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