# Testing with Video Files

The file player allows you to run the entire system without cameras by feeding recorded video files into the shared memory pipeline. This is essential for:

- Initial setup — verify the system works before connecting cameras
- Training operators — practice distance measurement with known jumps
- Tuning motion detection — adjust thresholds using repeatable test data
- Grid line calibration — calibrate anchor points from reference footage
- Development — test code changes without hardware

## Step-by-Step: Full Pipeline from Files

### 1. Prepare Video Files

You need one video file per camera feed. These can be:

- MP4/MKV/AVI recordings from the actual cameras
- Raw YUV420 files captured previously
- Any video file that Media Foundation can decode

Tip: For best results, use recordings from the same camera positions where the system will be deployed. This allows you to calibrate grid lines during testing.

### 2. Determine Frame Offsets

If your three video files were not started at the same moment, you need frame offsets to synchronize them. Find a visible event (e.g., a jumper crossing a reference point) in all three feeds and count the frame difference.

Example: if the same event appears at frame 8167 in feed 0, frame 6015 in feed 1, and frame 5032 in feed 2:

    Feed 0 offset: 8167
    Feed 1 offset: 6015
    Feed 2 offset: 5032

### 3. Start the File Players

Open three command prompts and run one file player per feed:

    bin\fileplayer.exe 0 videos\camera_bottom.mp4 8167
    bin\fileplayer.exe 1 videos\camera_middle.mp4 6015
    bin\fileplayer.exe 2 videos\camera_top.mp4 5032

Each player writes frames at 60fps into its feed's shared memory buffer.

### 4. Start Motion Detection

Open three more command prompts:

    bin\motion.exe 0 settings.txt
    bin\motion.exe 1 settings.txt
    bin\motion.exe 2 settings.txt

Or use the controller: click Start All (but do not start capture processes, since file players replace them).

### 5. Start the Video Generator

    bin\videogen.exe settings.txt

### 6. Start the Viewer

    bin\viewer.exe settings.txt

You should now see the merged video output with the ability to scroll through frames and measure distances.

## Using the Controller for File Playback

You can also manage file playback through the controller, but you need to start the file players manually from the command line (the controller's Start Capture buttons launch `capture.exe`, not `fileplayer.exe`). A typical workflow:

1. Start file players manually in command prompts (Step 3 above)
2. Launch `controller.exe settings.txt`
3. On the Processes tab, start Motion 0/1/2, VideoGen, and Viewer

## Single-Feed Testing

For quick testing with just one camera, you can run a single feed:

    bin\fileplayer.exe 1 test_video.mp4
    bin\motion.exe 1 settings.txt
    bin\viewer.exe settings.txt

The viewer will show whatever is in the output buffer. Without videogen, you can still navigate the raw feed frames.

## Looping Playback

The file player exits when it reaches the end of the file. To loop continuously, restart the players. The circular buffer retains the last 520 frames (~8.7 seconds), so there will be a brief gap when the player restarts.

## Troubleshooting File Playback

Problem | Solution
--- | ---
Black screen in viewer | Verify file players are running and writing frames. Check log output for errors.
Feeds out of sync | Adjust frame offsets. Find a common reference event in all three feeds.
Motion not triggering | Check `feed_motion_on` settings. Verify motion regions cover the jumper's path. Try lower `min_blob_sizes`.
Video file not supported | Convert to MP4 (H.264) using FFmpeg: `ffmpeg -i input.avi -c:v libx264 output.mp4`
File player exits immediately | Check the file path exists. Verify the video file is not corrupted.

## See Also

- File Player — command reference
- Motion Detection Tuning
- Grid Line Calibration
- Quick Start