Skip to content

Instantly share code, notes, and snippets.

@N02870941 N02870941/video.sh
Last active May 15, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.