Send Video to Telegram Bot Using Raspberry Pi Camera

Want to send a video to Telegram Bot?


Do you want to send a video to the telegram bot using a raspberry pi? In this tutorial, we record a video using Raspberry Pi camera and send the video to the Telegram bot. The default video file recorded by Raspberry Pi by default is an H264 file. Telegram cannot play this type of video file. So, we need to convert the video to an mp4 file before we send it to the Telegram bot.


This video shows how to get make a simple security system that can record a video using Raspberry Pi Camera and send it to telegram bot.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python3 sample program for sending a video to telegram. You can use it with Thonny Python IDE.

import telepot
from picamera import PiCamera
import RPi.GPIO as GPIO
import time
from time import sleep
import datetime
from telepot.loop import MessageLoop
from subprocess import call
PIR = 4
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 25
motion = 0
motionNew = 0
def handle(msg):
global telegramText
global chat_id
chat_id = msg['chat']['id']
telegramText = msg['text']
print('Message received from ' + str(chat_id))
if telegramText == '/start':
bot.sendMessage(chat_id, 'Security camera is activated.')#Put your welcome note here
while True:
bot = telepot.Bot('1225028462:AAE5Kvalk2pRVWkF8nGNvO8B9cq5E_j7ip8')
def main():
global chat_id
global motion
global motionNew
if GPIO.input(PIR) == 1:
print("Motion detected")
motion = 1
if motionNew != motion:
motionNew = motion
elif GPIO.input(PIR) == 0:
print("No motion detected")
motion = 0
if motionNew != motion:
motionNew = motion
def sendNotification(motion):
global chat_id
if motion == 1:
filename = "./video_" + (time.strftime("%y%b%d_%H%M%S"))
camera.start_recording(filename + ".h264")
command = "MP4Box -add " + filename + '.h264' + " " + filename + '.mp4'
call([command], shell=True)
bot.sendVideo(chat_id, video = open(filename + '.mp4', 'rb'))
bot.sendMessage(chat_id, 'The motion sensor is triggered!')
while 1:

view raw
hosted with ❤ by GitHub

Thank You


Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

1 thought on “Send Video to Telegram Bot Using Raspberry Pi Camera”

  1. hei i just try using mq2 sensor module but the result is flip
    when input 1 the value is “no gas leaked”

    and when input is 0 the value is “gas leaked”

    can you help me?

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top