Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. #!/bin/bash
  2. # 01/14/11
  3. # ./autopad_spaces.sh /full/path/to/directory
  4. # ./autopad_spaces.sh /full/path/to/media
  5. # ./autopad_spaces.sh ./relative/path/to/media
  6. #A playlist.txt file is created where the command is run from (will be changed in next version)
  7. #playlist.txt file can be edited manually with a text editor or anything
  8. #Make sure you are "priveleged" enough to write symlinks in the directory from which you are # running this script
  9. #
  10. #To-do
  11. #add ustream compatibility
  12. #test huge playlists and possibly code to compensate
  13. #possibly move the ffmpeg to a subshell so that the main shell can be used by the user to view and edit the playlist or something
  14. #possibly add extra variables to compensate for special options to be passed directly to ffmpeg
  15. #possibly write a test to check for subtitles and autoselect english when an option is passed
  16.  
  17. ##########-=DEFAULTS=-#########
  18. channel="kingdomheartsforever"
  19. username=""
  20. password=""
  21.  
  22. x264Preset=$2
  23. if [ "$x264Preset" = "" ]; then
  24. x264Preset="faster"
  25. fi
  26. ################################
  27.  
  28. #########-=Functions and Declarations=-##########
  29. #Declare an array for the playlist and initialize the playcount variable
  30. declare -a playlist
  31. playcount="0"
  32.  
  33. #Function to initially generate the playlist when command is called with a directory
  34. function listGen
  35. {
  36. echo "generating playlist"
  37. ls -1 "$moviePath" | grep -i -e "\.avi$" -e "\.mkv$" -e "\.mpeg$" -e "\.mpg$" -e "\.mov$" > playlist.txt
  38. }
  39.  
  40. #Function to refresh the playlist between playback from whatever is in the textfile. Allows for the user to manually edit playlist.txt and add or remove files
  41. function listRefresh
  42. {
  43. #Initialize entry variable and playlist array
  44. entry="0"
  45. unset playlist
  46. #Loop to sequentially populate array line by line from the playlist.txt file
  47. while read lolname; do
  48. playlist[$entry]=$lolname
  49. # echo $entry": "${playlist[$entry]}
  50. let entry++
  51. done < playlist.txt
  52. echo "Currently Playing File: "$playcount"/"${#playlist[@]}
  53. # echo ${playlist[@]}
  54. }
  55. #################################################
  56.  
  57. ##########-=Input File Analysis=-###########
  58. moviePath=$1
  59.  
  60. #Test if input is a normal file
  61. if [ -f "$moviePath" ]; then
  62. echo "Reading moviePath as ${moviePath##*.} file"
  63. #Test if file is a textfile and if so overwrite playlist.txt
  64. if [ ${moviePath##*.} = "txt" ]; then
  65. echo "loading txt file as playlist"
  66. cat $moviePath > playlist.txt
  67. else
  68. #If file is assumed to be a normal video file normalize the data so that the listRefresh function can also
  69. #be used normally. That way a user can launch the script with one file but then add to the playlist manually
  70. echo ${moviePath##*/} > playlist.txt
  71. moviePath=$(echo ${moviePath%/*})
  72. fi
  73. #Test if input is a directory
  74. elif [ -d "$moviePath" ]; then
  75. echo "Reading moviePath as directory"
  76. #Call playlist generation function
  77. listGen
  78. else
  79. #Input failed tests for file and directory
  80. echo "$moviePath not identified as either file or directory"
  81. exit
  82. fi
  83. #Normalize moviePath variable just to be safe
  84. moviePath=$(echo "$moviePath/")
  85. #Initialize playlist array from playlist.txt file
  86. listRefresh
  87. ############################################
  88.  
  89.  
  90.  
  91. ##############-=Individual File Playback=-###############
  92. #Main loop for stream playback
  93. #Checks if the amount of files played is less than the amount of files loaded into the playlist array
  94. while [ $playcount -lt ${#playlist[@]} ] ; do
  95.  
  96. #Creates a temp file to pull video width and height from while being useful for debugging
  97. ffprobe -show_streams "$moviePath${playlist[$playcount]}" > /tmp/probetmp.txt
  98.  
  99. width=$(cat /tmp/probetmp.txt | grep width | sed 's/width=//')
  100. height=$(cat /tmp/probetmp.txt | grep height | sed 's/height=//')
  101.  
  102. #Special test for checking of the video is widescreen to send it to the server in that way
  103. #Can be commented out if not necessary or problematic
  104. #Do not comment out nested tests
  105. if [ "$(echo "scale=0; (1000*$width*9)/($height*16)" | bc)" -ge "1000" ];then
  106. mode="widescreen" #variable for debugging
  107. scaleFactor=$(echo "scale=0; $width*9/16" | bc)
  108. padTotal=$(echo "scale=0; $scaleFactor - $height" | bc)
  109. padPixel=$(echo "scale=0; $padTotal/2" | bc)
  110. #Two different formats for setting the padding, switch if problematic
  111. #padString=" -padtop "$padPixel" -padbottom "$padPixel
  112. padString=" -vf pad="$width":"$scaleFactor":0:"$padPixel":black"
  113. else
  114. #Test for checking if the video needs padding on the top and bottom
  115. if [ "$(echo "scale=0; $width*3/4" | bc)" -gt "$height" ]; then
  116. mode="letterbox" #variable for debugging
  117. scaleFactor=$(echo "scale=0; $width*3/4" | bc)
  118. padTotal=$(echo "scale=0; $scaleFactor - $height" | bc)
  119. padPixel=$(echo "scale=0; $padTotal/2" | bc)
  120. #Two different formats for setting the padding, switch if problematic
  121. #padString=" -padtop "$padPixel" -padbottom "$padPixel
  122. padString=" -vf pad="$width":"$scaleFactor":0:"$padPixel":black"
  123. else
  124. #Padding to be added on the left and right if all other tests failed
  125. mode="tallscreen" #variable for debugging
  126. scaleFactor=$(echo "scale=0; $height*4/3" | bc)
  127. padTotal=$(echo "scale=0; $scaleFactor - $width" | bc)
  128. padPixel=$(echo "scale=0; $padTotal/2" | bc)
  129. #Two different formats for setting the padding, switch if problematic
  130. #padString="-padleft "$padPixel" -padright "$padPixel
  131. padString=" -vf pad="$scaleFactor":"$height":"$padPixel":0:black"
  132. fi
  133. fi
  134.  
  135.  
  136. #A bunch of output for debugging and whatnot
  137. echo "width: $width"
  138. echo "height: $height"
  139. echo "scaleFactor: $scaleFactor"
  140. echo "mode: $mode"
  141. echo "Widescreen test number: $(echo "scale=0; (1000*$width*9)/($height*16)" | bc)"
  142. echo "padTotal: $padTotal"
  143. echo "padPixel: $padPixel"
  144. echo "x264Preset: $x264Preset"
  145. echo "*****************************************"
  146. echo "PLAYING FILE ${playlist[$playcount]}"
  147. echo "*****************************************"
  148. # echo $moviePath
  149.  
  150. #To maybe help with server side stream detection which sometimes fails with quick disconnect/reconnects
  151. sleep 5
  152.  
  153. #ffmpeg command
  154. #ffmpeg -i "$moviePath${playlist[$playcount]}" -re -acodec libmp3lame -ar 44100 -ac 2 -vcodec libx264 -vpre $x264Preset -f flv $padString -threads 0 "rtmp://fme.mogulus.com/mogulus/$channel/username=$username/password=$password/isAutoLive=true/autoVOD=true/autoRecord=false app=mogulus/$channel/username=$username/password=$password/isAutoLive=true/autoRecord=false tcurl=rtmp://fme.mogulus.com/mogulus/$channel/username=$username/password=$password/isAutolive=true/autoRecord=false swfUrl=rtmp://publish.livestream.com/mogulus/$channel/username=$username/password=$password/isAutolive=true/autoRecord=false flashver=FME/2.5\20(compatible;\20FMSc/0.9) live=true"
  155.  
  156. let playcount++
  157. #Refresh the playlist array from the playlist.txt file after playback
  158. listRefresh
  159. done
  160. #########################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement