Created
December 21, 2021 21:47
-
-
Save GaussianWonder/60607c2caeb0bb9f26b9f9c704138729 to your computer and use it in GitHub Desktop.
Script to convert real time RTSP input into multiple files. FFMPEG needed. Useful for IP cameras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
print_help () { | |
echo "-h|--host HOST" | |
echo "-p|--port PORT" | |
echo "--path PATH" | |
echo "-U|--user USER" | |
echo "-P|--password PASSWORD" | |
echo "t|--time SPLIT INTERVAL" | |
echo " 00:00:10 (10 seconds)" | |
echo " 8 (8 seconds)" | |
echo "-o|--output FILE NAME" | |
} | |
OUT="output%03d.mov" | |
POSITIONAL=() | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-h|--host) | |
CAM_HOST="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-p|--port) | |
CAM_PORT="$2" | |
shift # past argument | |
shift # past value | |
;; | |
--path) | |
CAM_PATH="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-U|--user) | |
CAM_USER="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-P|--password) | |
CAM_PASSWORD="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-t|--time) | |
SPLIT_TIME="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-o|--out|--output) | |
OUT="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
print_help | |
exit 1 | |
;; | |
esac | |
done | |
URI="rtsp://$CAM_USER:$CAM_PASSWORD@$CAM_HOST:$CAM_PORT/$CAM_PATH" | |
echo "Compiled URI: $URI" | |
FFMPEG_CMD="ffmpeg -i $URI -c copy -map 0 -segment_time $SPLIT_TIME -reset_timestamps 1 -f segment $OUT" | |
echo "Executing $FFMPEG_CMD" | |
# sh $FFMPEG_CMD | |
ffmpeg -i $URI -c copy -map 0 -segment_time $SPLIT_TIME -reset_timestamps 1 -f segment $OUT | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment