Zum Inhalt

Schlagwort: ffmpeg

DIY Surveillance Camera Recording

my crontab:

# start recording on boot
@reboot sleep 10; /usr/local/bin/startrecord.sh &> /dev/null

# restart every 10 minutes to create a new file
*/10 * * * * killall ffmpeg ; sleep 5 ; /usr/local/bin/startrecord.sh &> /dev/null

# purge old recordings
0 */6 * * * find /data/office-kamera -type f -mtime +12 -delete

/usr/local/bin/startrecord.sh

#!/bin/bash

#cam1
/usr/bin/ffmpeg \
 -rtsp_transport tcp -i rtsp://user:password@10.0.100.21:554/11 \
 -c:v mpeg2video -b:v 16M -bufsize 16M -maxrate 16M /data/office-kamera/$(date +\%Y-\%m-\%d.\%H-\%M).cam1.mpg \
 -c:a mp2 -ac 1 -ab 64k -ar 44100 \
 -y -update 1 -r 3 -f image2 -q:v 10 -vf "scale=iw/2:ih/2,transpose=2" /var/www/html/cam/cam1.jpg \
  &>/tmp/cam1.log &

Important: We use mpeg2 for a purpose! Forget matroska/h264/hs65. If your recording stops the hard way (power outage, crashing ffmpeg process, rising of the dead), no file trailer is written and you can NOT play or reconstruct your video when using mp4. For that reason we choose mpeg2, because you can still view fragments from a 20 year old CD-R that has been through a blender, or if you drop a thermonuclear weapon on your hard drive.

This will also put image frames to /var/www/html/cam/, where you can host a HTML document that displays your image and refreshes it via javascript if you like.

Finding you cameras RTSP URL is key. Just google "camera model rtsp url". If you have any questions feel free to ask. Consider donating via paypal if it works for you;)

1 Comment

Create a video clip from a set of images using ffmpeg

imagine your image folder looks like this:

rephlex@hera:[~/Schreibtisch/gna]: ls -1 * | head
G0037679.JPG
G0037680.JPG
G0037681.JPG
G0037682.JPG
G0037683.JPG
G0037684.JPG
G0037685.JPG
G0037686.JPG
G0037687.JPG
G0037688.JPG

[…]

This is the command you're looking for:

ffmpeg -framerate 25 -start_number 37679 -i G00%05d.JPG -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4

Leave a Comment

Mit Linux und ffmpeg zu Youtube streamen

VBR="3500k" # bitrate
FPS="30" # framerate
KEYFRAMEINT="40" # keyframe interval
QUAL="medium" # ffpmeg quality preset
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" # youtube rtmp url
KEY="XXXX-XXXX-XXXX-XXXX"

sudo modprobe snd_aloop
alsactl restore
while true
do

ffmpeg -err_detect explode -thread_queue_size 16384 \
-f alsa -ac 2 -i pulse \
-f v4l2 -video_size 864×480 -thread_queue_size 16384 -i /dev/video1 -deinterlace \
\
-vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $KEYFRAMEINT -b:v $VBR \
-acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k \
-f flv "$YOUTUBE_URL/$KEY"

sleep 5
done

Leave a Comment