Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active January 26, 2026 04:10
Show Gist options
  • Select an option

  • Save prashantvc/09d125be220ab2b2edd8dfdd5c8852bf to your computer and use it in GitHub Desktop.

Select an option

Save prashantvc/09d125be220ab2b2edd8dfdd5c8852bf to your computer and use it in GitHub Desktop.

How to use record_video.sh

Pre-requisit

  • The script should be copied to the Raspberry Pi device

1. Make the script executable

Run once:

chmod +x record_video.sh

2. Run the script

Provide the recording duration in minutes:

./record_video.sh <minutes>

Example (record 5 minutes):

./record_video.sh 5

The script will create a timestamped video file in the same directory as the script:

video_YYYYMMDD_HHMMSS.mkv

Verify the video (IMPORTANT)

Open the video using VLC

On the Raspberry Pi or another machine with VLC installed:

vlc video_YYYYMMDD_HHMMSS.mkv

Or open VLC and use Media → Open File.

What to check

  • Video plays without errors
  • Duration matches the requested time
  • Resolution is 1920×1080
  • Playback is smooth (no corruption or freezing)

If the video plays correctly in VLC, the capture is confirmed to be valid.

#!/bin/bash
set -e
# -------- Usage --------
if [ $# -ne 1 ]; then
echo "Usage: $0 <duration_in_minutes>"
echo "Example: $0 5"
exit 1
fi
DURATION_MINUTES=$1
DURATION_MS=$((DURATION_MINUTES * 60 * 1000))
# -------- Timestamped output --------
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
OUTPUT_MKV="video_${TIMESTAMP}.mkv"
echo "Recording ${DURATION_MINUTES} minute(s) of Full HD video..."
echo "Output file: ${OUTPUT_MKV}"
# -------- Record directly to MKV --------
rpicam-vid \
-t ${DURATION_MS} \
--width 1920 \
--height 1080 \
--framerate 30 \
-n \
-o "${OUTPUT_MKV}"
echo "Recording complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment