# Horse Stall Data Acquisition System: A Scalable and Reliable Audio-Visual Recording and Transfer Framework

> A scalable embed system records synchronized audio and video of horses overnight, enabling AI-driven behavior analysis.

## Overview
The “Tekoälyä Talleille” project aims to develop an AI system capable of recognizing abnormal sounds made by horses. To support this, we have developed a data collection framework for the seven-horse section at Rauhalahti Riding School. The system utilizes low-cost Raspberry Pi devices, reliable Linux tooling, and a structured scheduled recording and data transfer mechanism to ensure data readiness for acoustic behavior modeling and video analysis.

## System Architecture and Capabilities
The system is designed for continuous, automated operation, capturing synchronized audio and video data from 7:00 PM to 9:00 AM in 30-minute intervals.

**Key Capabilities:**
*   **Continuous Recording:** Daily 30-minute interval recordings between 7:00 PM and 9:00 AM.
*   **Synchronized Capture:** Support for 1-2 USB microphones and 1-2 USB cameras per unit.
*   **Efficient Compression:** Automated video compression to accommodate rural network constraints.
*   **Automated Transfer:** Daily file transfers to a central Savonia NVIDIA DGX server.
*   **Scalability:** Plug-and-play deployment across multiple Raspberry Pi units.

## Hardware and Connectivity
*   **Processing Unit:** Raspberry Pi 5 Model B.
*   **Audio:** Rode Videomic Go II.
*   **Video:** Arducam 2MP IMX462 Day and IR Night Vision USB Camera.
*   **Storage:** 128 GB microSD card for temporary local storage.
*   **Connectivity:** Wi-Fi or Ethernet. In remote locations, mobile WAN solutions are utilized, including the ZTE MU5001 4G/5G or Advantech ICR-4400 routers.

## Software and Automation
The system runs on Raspberry Pi OS Lite, utilizing the following stack:
*   **Capture:** `ffmpeg`
*   **Automation:** `systemd` timers and services
*   **Transfer:** `rsync` over SSH
*   **Process Management:** `flock` to prevent process overlap
*   **Configuration:** Bash and GitLab

### Recording Logic
Audio is captured in mono .flac format (16kHz) to preserve quality for AI research. Video is captured in grayscale at 640×480 resolution and 15 fps, encoded with H.264.

**Example Audio Command:**
```bash
ffmpeg -f pulse -i "$MIC_NAME" -ac 1 -ar 16000 -t $DURATION -c:a flac "$AUDIO_FILE"
```

**Example Video Command:**
```bash
ffmpeg -f v4l2 -framerate 15 -video_size 640x480 -i "$CAM_DEV" -vf format=gray -t $DURATION -c:v libx264 -preset ultrafast "$VIDEO_FILE"
```

### Compression and Transfer
To optimize bandwidth, video files are compressed using a slower `ffmpeg` preset and a lower Constant Rate Factor (CRF) value, reducing file sizes from ~370 MiB to ~35 MiB. Transfers are managed by `rsync` over SSH, with staggered start times for each Raspberry Pi unit to manage network load.

## Data Volume Estimates
Based on 7 camera-microphone pairs recording 30-minute intervals:
*   **Total Sessions:** 168 audio and 168 video files per night.
*   **Audio Volume:** ~3.36 GiB.
*   **Compressed Video Volume:** ~5.88 GiB.
*   **Total Expected Daily Transfer:** ~9.24 GiB.

## Project Team
*   **Osman Torunoglu**, RDI Specialist, DigiCenter – osman.torunoglu@savonia.fi
*   **Johannes Geisler**, RDI Specialist, DigiCenter – johannes.geisler@savonia.fi
*   **Finlay Hare**, RDI Project Worker, DigiCenter – finlay.hare@savonia.fi
*   **Aki Happonen**, Digital Development Manager, DigiCenter – aki.happonen@savonia.fi
*   **Heli Suomala**, Project Manager and Expert, Finnish Horse Information Centre – heli.suomala@hevostietokeskus.fi

*This work is part of the “Tekoälyä talleille” project at Savonia University of Applied Sciences and is licensed under CC BY-SA 4.0.*