stagesepx

repository·master·Indexed 19 days ago

https://github.com/williamfzc/stagesepx

A lightweight, automated video analysis tool based on image processing and machine learning. It detects and analyzes distinct stages within a video to measure durations and identify transitions, making it suitable for performance testing (e.g., app startup times), functional testing, and game testing. It utilizes SSIM for structural stability and includes a pipeline for data collection, model training, and prediction.

Tokens
4K
Snippets
14
Records
29
Agent score
66%

What's inside stagesepx

  1. What is stagesepx?

    master

    stagesepx is a lightweight, fully automated video analysis tool based on image processing and machine learning. It is designed to analyze videos and automatically split them into a series of distinct stages.

    Key capabilities include:

    • Automatic Stage Detection: Identifies stable or unstable stages within a video (e.g., detecting the difference between a click action and a page loading state).
    • Temporal Mapping: Automatically determines the time intervals for each detected stage.
    • Snapshot Generation: Provides visual snapshots (thumbnails) for each stage to help users understand what occurred during that period.
    • Zero Configuration: Requires only a video file; no pre-defined templates or prior training/learning is necessary.
    • Automated Reporting: Calculates the duration (time cost) for each stage automatically.
  2. Future development directions for stagesepx

    master

    The development roadmap for stagesepx focuses on three primary pillars:

    1. Precise Testing of Speed Types: Expanding testing scenarios for various performance metrics such as startup speed, page transition speed, and power on/off cycles.
    2. Functional Testing: Implementing testing based on video comparison. The core idea is that identical operation flows should produce identical page effects and videos. By comparing regression videos, users can verify if the page meets expectations or detect UI rendering issues during compatibility testing.
    3. AI Data Collection: Leveraging the existing classifier (which is machine learning-based) and the cutter tool. Users can use cutter to extract materials from videos to train their own AI models or use manually collected datasets for model training.

    For more details on the underlying logic, refer to the Design Philosophy and Positioning documentation.

  3. Use stagesepx as an AI processing bridge

    master

    stagesepx is designed to act as a preparation layer for AI-driven image processing. It serves as a 'bridge' that allows you to collect and prepare resources from videos without needing to handle raw video file manipulation yourself.

    Typical AI Workflow:

    1. Video Input: Provide a video containing the target actions.
    2. stagesepx Processing: Use the tool to segment or extract relevant frames/resources from the video.
    3. AI/Image Processing: Pass the extracted resources directly to your image processing or AI models for analysis.
  4. Stability and Accuracy with SSIM

    master

    Unlike tools that rely on template matching or OCR (which are sensitive to rotation, resolution, and lighting), stagesepx uses SSIM (Structural Similarity Index) for classification.

    • Robustness: By using the SSIM classifier, the tool maintains high stability against environmental interference (rotation, lighting, etc.) because it focuses on structural changes within the video context.
    • Accuracy: The tool provides high precision, with errors typically within 0.01s. Accuracy can be further improved by increasing the video's FPS (frames per second).
  5. Performance optimization via sampling

    master

    To achieve high performance, stagesepx utilizes a sampling mechanism that converts continuous time or spatial domains into discrete quantities. This is primarily used in the cutter component to accelerate the cutting process.

    • Efficiency: Using a step size of 5 frames can reduce computational load by approximately 80%.
    • Trade-off: Sampling introduces a small amount of error. If your video contains very rapid changes or if you require maximum precision, you can disable the sampling feature.

    Example log showing high-speed processing (approx. 300ms for a test video):

    2019-07-17 10:52:03.429 | INFO     | stagesepx.cutter:cut:200 - start cutting: test.mp4
    ...
    2019-07-17 10:52:03.792 | INFO     | stagesepx.cutter:cut:203 - cut finished: test.mp4
  6. Use stagesepx for performance and functional testing

    master

    stagesepx is a video analysis tool that can be applied to various testing scenarios by analyzing video content.

    Common use cases include:

    • Performance Testing: Calculating application startup speeds, page transition speeds, or measuring the duration of specific actions (e.g., time taken for a pen to enter or leave a frame).
    • Functional Testing: Using the built-in splitter to cut videos into segments, which can then be passed to image recognition tools like findit to verify functional correctness.
    • Game Testing: Analyzing gameplay videos in scenarios where traditional automated testing methods are difficult to implement.
  7. Understand the core components: Cutter, Classifier, and Hook

    master

    stagesepx is built around three primary abstractions that work together to automate video analysis:

    1. Cutter: The foundation of automation. It performs video stage segmentation and sampling. Its role is preprocessing—identifying stable intervals and extracting frames to reduce the computational cost for subsequent modules. It provides interfaces like pick_and_save to export data for external tools (e.g., Keras).
    2. Classifier: Performs high-accuracy, frame-level classification. It uses the samples provided by the Cutter to categorize frames. Classifiers can take different forms, such as machine learning models. Once a model is trained using Cutter-sampled data, it can be used directly for future analysis without manual sampling.
    3. Hook: A mechanism introduced in v0.4.2 to support frame-level image processing. All frame operations (like compression or grayscale conversion) are implemented as hooks. Hooks allow for flexible customization of the preprocessing pipeline or personalized frame operations (e.g., saving frames to a specific location).
  8. Access raw stage data as a Python object

    master

    If you need to perform secondary development or custom data processing instead of just viewing a report, you can use stagesepx as a library. By omitting the report generation, you receive a Python object containing raw data.

    This data can be converted into a dictionary where each frame contains:

    • stage: The classified category
    • timestamp: The time offset
    • frame_id: The frame number
    • video_path: Path to the source video
    • data: Additional metadata (can be null)

    Example dictionary structure:

    {
      "data": [
        {
          "data": null,
          "frame_id": 1,
          "stage": "0",
          "timestamp": 0.0,
          "video_path": "../demo.mp4"
        },
        {
          "data": null,
          "frame_id": 2,
          "stage": "0",
          "timestamp": 0.04,
          "video_path": "../demo.mp4"
        }
      ]
    }
  9. Customize frame processing with Hooks

    master

    Hooks allow you to inject custom logic into the frame-processing pipeline. When a Cutter or Classifier processes a frame, it iterates through a hook_list and applies each hook sequentially.

    Key behaviors to note:

    • Execution Order: Hooks are executed strictly in the order they are added. Be aware that hooks can interfere with one another.
    • The overwrite parameter: This parameter controls whether a hook modifies the original frame or works on a copy.

    Common built-in hooks:

    • CompressHook: Compresses frames before analysis.
    • GreyHook: Converts frames to grayscale.
    • FrameSaveHook: Saves individual frames to a specified location during the iteration process.

    You can implement your own hooks by following the patterns of these built-in versions to perform personalized frame operations.

  10. Use Classifiers for video analysis

    master

    Classifiers are used to categorize frames within a video, often leveraging sampling results from a Cutter. stagesepx provides two official classifier types:

    • SVM + HoG Classifier: Best suited for videos with complex stages. It can be trained on different video sets to improve recognition accuracy for production environments.
    • SSIM Classifier: A traditional, lightweight, and training-free option. It is ideal for simple videos with fewer stages.

    While stagesepx favors lightweight machine learning (via sklearn), you can use the output from the Cutter to train your own deep learning models for even higher accuracy.