Advertisement
Guest User

Untitled

a guest
May 25th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # README:
  2. #
  3. # Run this script as follows:
  4. #
  5. # ./video.sh urls.txt videos
  6. #
  7. # Where urls.txt is a list of RTSP links
  8. # and videos is the directory that you would
  9. # like to save the downloaded videos to. If
  10. # the designated directory does not exist, it
  11. # will be created automatically.
  12. #
  13. # NOTE: DO NOT APPEND a / after the directory name
  14.  
  15. file=$1
  16. dir=$2
  17.  
  18. # Create the directory if it
  19. # does not exist already.
  20. create_dir() {
  21. mkdir -p $dir
  22. }
  23.  
  24. # Pipe each stream into a file
  25. # in the designated output directory
  26. download() {
  27. # echo $1 $2
  28. ffmpeg -i $1 -acodec copy -vcodec copy $2 < /dev/null
  29. }
  30.  
  31. # Iterate through the input file line by line
  32. # Download each file by URL
  33. iterate() {
  34. pids=""
  35.  
  36. while read url; do
  37. filename=$(echo "$url" | sed 's:.*/::')
  38. download $url "$dir/$filename" &
  39. pids="$pids ${!}"
  40. done < $file
  41.  
  42. for pid in $pids; do
  43. wait $pid || let "RESULT=1"
  44. done
  45.  
  46. if [ "$RESULT" == "1" ]; then
  47. return 1
  48. fi
  49. }
  50.  
  51. main() {
  52. create_dir
  53. iterate
  54. }
  55.  
  56. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement