SHARE
TWEET

Untitled

a guest Jun 16th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MYDIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
  2. SAVEDIR=$(pwd)
  3.  
  4. # Check programs
  5. if [ -z "$(which ffmpeg)" ]; then
  6.     echo "Error: ffmpeg is not installed"
  7.     exit 1
  8. fi
  9.  
  10. if [ -z "$(which MP4Box)" ]; then
  11.     echo "Error: MP4Box is not installed"
  12.     exit 1
  13. fi
  14.  
  15. cd "$MYDIR"
  16.  
  17. TARGET_FILES=$(find ./ -maxdepth 1 -type f ( -name "*.mov" -or -name "*.mp4" ))
  18. for f in $TARGET_FILES
  19. do
  20.   fe=$(basename "$f") # fullname of the file
  21.   f="${fe%.*}" # name without extension
  22.  
  23.   if [ ! -d "${f}" ]; then #if directory does not exist, convert
  24.     echo "Converting "$f" to multi-bitrate video in MPEG-DASH"
  25.  
  26.     mkdir "${f}"
  27.  
  28.     ffmpeg -y -i "${fe}" -c:a aac -b:a 192k -vn "${f}_audio.m4a"
  29.  
  30.  
  31.     ffmpeg -y -i "${fe}" -preset slow -tune film -vsync passthrough -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -crf 23 -maxrate 800k -bufsize 2000k -pix_fmt yuv420p -vf "scale=-2:720" -f mp4  "${f}_800.mp4"
  32.     # static file for ios and old browsers and mobile safari
  33.     ffmpeg -y -i "${fe}" -preset slow -tune film -movflags +faststart -vsync passthrough -write_tmcd 0 -c:a aac -b:a 160k -c:v libx264  -crf 23 -maxrate 1400 -bufsize 3000k -pix_fmt yuv420p -f mp4 "${f}/${f}.mp4"
  34.  
  35.  
  36.     rm -f ffmpeg*log*
  37.     # if audio stream does not exist, ignore it
  38.     if [ -e "${f}_audio.m4a" ]; then
  39.         MP4Box -dash-strict 2000 -rap -frag-rap  -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a" -out "${f}/${f}.mpd"
  40.         rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" "${f}_audio.m4a"
  41.     else
  42.         MP4Box -dash-strict 2000 -rap -frag-rap  -bs-switching no -profile "dashavc264:live" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4" -out "${f}/${f}.mpd"
  43.         rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1500.mp4" "${f}_800.mp4" "${f}_400.mp4"
  44.     fi
  45.     # create a jpg for poster. Use imagemagick or just save the frame directly from ffmpeg is you don't have cjpeg installed.
  46.     ffmpeg -i "${fe}" -ss 00:00:00 -vframes 1  -qscale:v 10 -n -f image2 - | cjpeg -progressive -quality 75 -outfile "${f}"/"${f}".jpg
  47.  
  48.     fi
  49.  
  50. done
  51.  
  52. cd "$SAVEDIR"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top