Skip to content

video_analyzer always fails on a static screen: the live scrcpy MKV is still 0 bytes #248

Open

Description

@HaticeSarp

Summary

video_analyzer cannot analyze the current recording segment while the
device screen is static. scrcpy emits frames only when the screen changes, so
on a static screen the little data it produces stays buffered and the live
recording.mkv remains 0 bytes on disk. render_timeline_clip then fails
on every attempt with EBML header parsing failed, and the tool returns
Failed to trim video segment after retries.

This hits hardest when the agent needs it most: it calls video_analyzer to
ask "did the screen react to my tap?", which is exactly the case where the
screen did not change.

The final recording is fine - once scrcpy stops, the file is flushed and valid.
Only analysis of the active segment is affected.

Environment

  • Artemis 351ca84 (main) - recording code unchanged in our fork
  • scrcpy 5.0.1 (Homebrew); also reproduced with the official scrcpy 4.1 release
  • ffmpeg: the imageio_ffmpeg bundled binary (ffmpeg-macos-aarch64-v9.0)
  • macOS 26.6.2, arm64
  • Device: HUAWEI STK-L21, Android 10, real device over USB

Steps to reproduce

  1. Start a Flash run on a screen that does not change, e.g. a welcome screen
    whose button does nothing when tapped.
  2. Let the agent call video_analyzer for a recent time range.
  3. Every trim attempt fails; the agent loses 1-4 minutes per call.

Minimal reproduction without Artemis, using the same command
build_scrcpy_record_command builds:

scrcpy --serial <serial> --no-window --record live.mkv --record-format mkv \
  --video-bit-rate 2M --capture-orientation=@ &
sleep 8
stat -f %z live.mkv                           # 0 on a static screen
ffmpeg -v error -i live.mkv -f null -         # EBML header parsing failed

Measurements

Same device, same command, 8 s into the recording:

┌─────────────────────────────────────────────┬─────────────┬────────────────────┬─────────────────┐
│           Screen during recording           │ Size at 8 s │ Live file readable │ Size after stop │
├─────────────────────────────────────────────┼─────────────┼────────────────────┼─────────────────┤
│ Static                                      │ 0 B         │ No                 │ 38 KB           │
├─────────────────────────────────────────────┼─────────────┼────────────────────┼─────────────────┤
│ Changing (notification shade opened/closed) │ 512 KB      │ Yes                │ 1 MB            │
├─────────────────────────────────────────────┼─────────────┼────────────────────┼─────────────────┤
│ Static (repeat)                             │ 0 B         │ No                 │ 38 KB           │
└─────────────────────────────────────────────┴─────────────┴────────────────────┴─────────────────┘

The scrcpy version is not the cause: 4.1 and 5.0.1 behave the same.

Log excerpt

❌ Failed to render analyzer timeline clip (code 183): ffmpeg version 9.0 ...
[in#0 @ 0x...] Format matroska,webm detected only with low score of 1, misdetection possible!
[in#0 @ 0x...] EBML header parsing failed
Error opening input file .../web_<ts>_<id>/recording.mkv.
⚠ ffmpeg trim attempt 1 failed, retrying in 0.5s...
...
❌ Error executing tool 'extract_segment_metadata': Failed to get video segment: Failed to trim video segment after retries

In one run the analyzer issued 100+ failing ffmpeg calls before the agent
moved on.

Where it happens

artemis/controllers/unified_controller.py (~L193-L215): the active segment
mkv_path is appended to timeline_segments whenever mkv_path.exists(),
regardless of whether it holds any data; render_timeline_clip
(artemis/utils/video.py ~L467) then fails on it, and the loop retries three
times with the same empty file.

Note that remux_recording_to_mp4 (artemis/utils/video.py L213) already
guards against exactly this with
if not source_path.exists() or source_path.stat().st_size == 0: return False
- the same check is simply missing where the active segment is appended.

Possible fixes

1. Roll the segment before analysis. The recording supervisor already
   knows how to stop scrcpy, finalize the segment and start the next one
   (Rolling screen recording segment after ...). Doing that on demand before
   video_analyzer trims the active segment would give it a flushed, valid
   file.
2. Treat an empty active segment as a signal, not an error. If the live
   file is 0 bytes (or unreadable) and no frames arrived since the last
   segment, tell the agent "the screen did not change in this range" - which
   is the answer it was looking for - instead of failing.
3. At minimum, skip the empty active segment and do not retry with the same
   empty file.

Happy to test a fix on this device.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions