Skip to content

Instantly share code, notes, and snippets.

@jkctech
Last active October 26, 2022 17:45
Show Gist options
  • Save jkctech/582222cd652ecacb42e3b05238be90bc to your computer and use it in GitHub Desktop.
Save jkctech/582222cd652ecacb42e3b05238be90bc to your computer and use it in GitHub Desktop.
Foscam FFMPEG video + audio streamsaver

Foscam FFMPEG video + audio streamsaver

Small mini application for recording BOTH the video and audio stream of a Foscam IP camera.

Installation

  1. Copy camera.service to /etc/systemd/system/camera.service
  2. Copy record.sh to a place you prefer.
  3. Change values in both your copied files according to the specs listed below.
  4. Restart the service daemon by running sudo systemctl daemon-reload
  5. Start the service by running sudo systemctl start camera.service
  6. Enable the service at startup by running sudo systemctl enable camera.service

Values to change

camera.service
  • WorkingDirectory: Folder to save video files to
  • ExecStart: Path to the shellscript

record.sh

  • yourusername: Username used for Foscam camera access
  • yourpassword: Pasword used for Foscam camera access
  • camip: LAN IP address of the camera (Port should probably remain on 88)
  • -segment_time: 1800
  • -stimeout: TCP I/O timeout in microseconds (3000000 = 3 seconds)
  • camera_%Y-%m-%d_%H-%M-%S.mkv: Output filename using time and datestamps
[Unit]
Description=Video Recorder
After=network.target
[Service]
Type=simple
WorkingDirectory=/path/to/save/video/files
ExecStart=/bin/bash /path/to/script/record.sh
Restart=always
RestartSec=10
KillMode=mixed
[Install]
WantedBy=multi-user.target
#!/bin/bash
ffmpeg -rtsp_transport tcp \
-stimeout 3000000 \
-i rtsp://yourusername:yourpassword@camip:88/videoMain \
-i rtsp://yourusername:yourpassword@camip:88/audio \
-f segment \
-segment_time 1800 \
-vsync vfr \
-reset_timestamps 1 \
-c copy \
-strftime 1 \
camera_%Y-%m-%d_%H-%M-%S.mkv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment