Skip to content

Instantly share code, notes, and snippets.

@N02870941
Last active May 15, 2019 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N02870941/2ca8d74bf9c9875f94e99241f06f4c6d to your computer and use it in GitHub Desktop.
Save N02870941/2ca8d74bf9c9875f94e99241f06f4c6d to your computer and use it in GitHub Desktop.
Download a list of RTSP streams via URL to files
# README:
#
# Run this script as follows:
#
# ./video.sh urls.txt videos
#
# Where urls.txt is a list of RTSP links
# and videos is the directory that you would
# like to save the downloaded videos to. If
# the designated directory does not exist, it
# will be created automatically.
#
# NOTE: DO NOT APPEND a / after the directory name
file=$1
dir=$2
# Create the directory if it
# does not exist already.
create_dir() {
mkdir -p $dir
}
# Pipe each stream into a file
# in the designated output directory
download() {
# echo $1 $2
ffmpeg -i $1 -acodec copy -vcodec copy $2 < /dev/null
}
# Iterate through the input file line by line
# Download each file by URL
iterate() {
pids=""
while read url; do
filename=$(echo "$url" | sed 's:.*/::')
download $url "$dir/$filename" &
pids="$pids ${!}"
done < $file
for pid in $pids; do
wait $pid || let "RESULT=1"
done
if [ "$RESULT" == "1" ]; then
return 1
fi
}
main() {
create_dir
iterate
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment