Skip to content

Instantly share code, notes, and snippets.

@rubinlinux
Created March 30, 2018 18:04
Show Gist options
  • Save rubinlinux/3eabe6d4900f0a7623e4df8e616e64f5 to your computer and use it in GitHub Desktop.
Save rubinlinux/3eabe6d4900f0a7623e4df8e616e64f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
cameraName=$1
cameraUrl=$2
function usage {
echo "Usage: $0 <cameraName> <rtsp://cameraUrl>"
exit 1
}
if [ -z "$cameraName" ]; then
echo "CameraName required"
usage
fi
if [ -z "$cameraUrl" ]; then
echo "CameraUrl required"
usage
fi
while [ True ]; do
ffmpeg \
-i "$cameraUrl" `# What stream to read` \
-an `# No audio` \
-c:v copy `# Copy the video stream, dont re-encode it` \
-tune fastdecode -tune zerolatency `# Tune the video for performance` \
-pix_fmt yuv420p `# Faster than rgb`\
-level 21 \
-b:v 400K \
-r 25 -g 36 \
-f hls `# Write out an HLS stream` \
-hls_time 2 `# How much HLS to store at a time (seconds)` \
-hls_allow_cache 0 `# Send EXT-X-ALLOW-CACHE to NO in client` \
-hls_list_size 3 \
-hls_wrap 5 `# How many segments to wrap back to the first` \
-s 640x480 `# Scale the video` \
-hls_segment_filename "/var/www/stream/$cameraName%03d.ts" `# Name for ts files` \
-loglevel fatal `# Only show fatal errors` \
/var/www/stream/"$cameraName".m3u8 # Output file
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment