Table of contents

This script will automatically send a timelapse of your camera from Shinobi to a Telegram group/chat. Make sure to add your Telegram bot's token and chat_id

You need to have ffmpeg installed on your machine. You can create your bot using @botfather on Telegram.

To find the chat_id create a new group, add the bot to id and open:

https://api.telegram.org/bot<TOKEN>/getUpdates

There you will be able to find the chat_id. Enjoy!

#!/bin/bash

# Set the directory containing the JPG stills
still_dir="/mnt/somewhere/CCTV/Shinobi/OBGHAYuAu7/xaTYrUYZN58000_timelapse"

# Get the date from the optional argument or use the current date
if [[ -n "$1" ]]; then
    date_arg="$1"
else
    date_arg=$(date -d "yesterday" +"%Y-%m-%d")
fi

# Replace the date in the directory path
video_dir="${still_dir}/${date_arg}"

# Create the output video path
output_file="${video_dir}/timelapse.mp4"
output_thumb="${video_dir}/thumb.jpg"

# Create the video from JPG stills using ffmpeg
ffmpeg -y -framerate 20 -pattern_type glob -i "${video_dir}/*.jpg" -vf "scale=1280:720" -c:v libx265 -pix_fmt yuvj420p -color_range jpeg -max_muxing_queue_size 1024 -threads 16 "${output_file}"

# Create a thumbnail
ffmpeg -y -ss 00:00:20 -i "${output_file}" -vf "scale=320:180" -vframes 1 "${output_thumb}"

# Compute duration in seconds
duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "${output_file}")
total_seconds=$(echo "$duration" | awk -F '.' '{print $1}')

# Send the video via Telegram API
telegram_token="<your telegram token>"
chat_id="<your chat id>"

curl -F "caption=${date_arg}" -F "chat_id=${chat_id}" -F "video=@${output_file}" -F "width=1280" -F "height=720" -F "thumb=@${output_thumb}" -F "duration=${total_seconds}" "https://api.telegram.org/bot${telegram_token}/sendVideo"

You can then setup a cronjob for it:

# Camera timelapse video Telegram bot
15 13 * * * /bin/bash /home/user/tg_timelapse.sh
💡
Don't forget to chmod +x tg_timelapse.sh
GitHub - ShinobiCCTV/Shinobi: :zap: Shinobi Pro - The Next Generation in Open-Source Video Management Software with support for over 6000 IP and USB Cameras
:zap: Shinobi Pro - The Next Generation in Open-Source Video Management Software with support for over 6000 IP and USB Cameras - ShinobiCCTV/Shinobi