Skip to content

Instantly share code, notes, and snippets.

@kythin
Created May 26, 2014 06:54
Show Gist options
  • Save kythin/e72180fe3054bddd89bf to your computer and use it in GitHub Desktop.
Save kythin/e72180fe3054bddd89bf to your computer and use it in GitHub Desktop.
RTMP to JPG Timelapse Capture Bash Script
#!/bin/bash
##
# RTMP to JPEG timelapse script
# github.com/kythin
#
# Simple script to take an RTMP streaming url and save a jpeg every 10 seconds.
#
# Requires 'ffmpeg' and 'rtmpdump'
# apt-get install ffmpeg rtmpdump
#
##
STREAM='STREAM ID HERE'
RTMPURL='RTMP URL GOES HERE'
OUTDIR='~/caps'
TIME=$(date +"%Y%m%d_%H%M%S")
mkdir -p $OUTDIR
rtmpdump -v -r $RTMPURL -y $STREAM -o $OUTDIR/1.flv -B 1
ffmpeg -i $OUTDIR/1.flv -ss 00:00:01 -an -r 1 -vframes 1 -s 800x600 -y $OUTDIR/$TIME.jpg
echo "Waiting until next run..."
sleep 10
./cap.sh
exit;
@kythin
Copy link
Author

kythin commented May 27, 2014

From here you can edit the script to run once, and use a cron to run it every minute, or whatever. You could also expose it through a php script and then query that script whenever you want it to take a snapshot - say from a button on the webcam feed on the website? Hmmm...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment