%PDF- %PDF-
Direktori : /home/waritko/ |
Current File : //home/waritko/dashdir.sh |
#!/bin/bash # THIS SCRIPT CONVERTS EVERY MP4 (IN THE CURRENT FOLDER AND SUBFOLDER) TO A MULTI-BITRATE VIDEO IN MP4-DASH # For each file "videoname.mp4" it creates a folder "dash_videoname" containing a dash manifest file "stream.mpd" and subfolders containing video segments. # Explanation: # https://rybakov.com/blog/ # Validation tool: # http://dashif.org/conformance.html # MDN reference: # https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Setting_up_adaptive_streaming_media_sources # Add the following mime-types (uncommented) to .htaccess: # AddType video/mp4 m4s # AddType application/dash+xml mpd # Use type="application/dash+xml" # in html when using mp4 as fallback: # <video data-dashjs-player loop="true" > # <source src="/walking/walking.mpd" type="application/dash+xml"> # <source src="/walking/walking.mp4" type="video/mp4"> # </video> # DASH.js # https://github.com/Dash-Industry-Forum/dash.js set -x MYDIR=$(dirname $(readlink -f ${BASH_SOURCE[0]})) SAVEDIR=$(pwd) # Check programs if [ -z "$(which ffmpeg)" ]; then echo "Error: ffmpeg is not installed" exit 1 fi if [ -z "$(which MP4Box)" ]; then echo "Error: MP4Box is not installed" exit 1 fi #cd "$MYDIR" #find ./ -maxdepth 1 -type f \( -name "*.mov" -or -name "*.mp4" \) | { #for f in $TARGET_FILES #while read f; #do fe=$(basename "$1") # fullname of the file f="${fe%.*}" # name without extension if [ ! -d "${f}" ]; then #if directory does not exist, convert echo "Converting \"$f\" to multi-bitrate video in MPEG-DASH" mkdir "${f}" ffmpeg -y -i "${fe}" -c:a aac -b:a 96k -vn "${f}_audio.m4a" ffmpeg -y -i "${fe}" -preset slow -tune film -r 25 -vsync -1 -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -b:v 5000k -maxrate 7500k -bufsize 12000k -pix_fmt yuv420p -f mp4 "${f}_5000.mp4" ffmpeg -y -i "${fe}" -preset slow -tune film -r 25 -vsync -1 -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -b:v 3000k -maxrate 4500k -bufsize 6000k -pix_fmt yuv420p -vf "scale=-2:1080" -f mp4 "${f}_3000.mp4" ffmpeg -y -i "${fe}" -preset slow -tune film -r 25 -vsync -1 -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -b:v 1200k -maxrate 1800k -bufsize 2400k -pix_fmt yuv420p -vf "scale=-2:720" -f mp4 "${f}_1200.mp4" ffmpeg -y -i "${fe}" -preset slow -tune film -r 25 -vsync -1 -write_tmcd 0 -an -c:v libx264 -x264opts 'keyint=25:min-keyint=25:no-scenecut' -b:v 400k -maxrate 600k -bufsize 1000k -pix_fmt yuv420p -vf "scale=-2:540" -f mp4 "${f}_400.mp4" # static file for ios and old browsers ffmpeg -y -i "${fe}" -preset slow -tune film -r 25 -vsync -1 -write_tmcd 0 -c:a aac -b:a 160k -c:v libx264 -b:v 2000k -maxrate 3000k -bufsize 4000k -pix_fmt yuv420p -f mp4 "${f}/${f}.mp4" rm -f ffmpeg*log* # if audio stream does not exist, ignore it if [ -e "${f}_audio.m4a" ]; then MP4Box -dash 2000 -rap -frag-rap -bs-switching no -profile "onDemand" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1200.mp4" "${f}_400.mp4" "${f}_audio.m4a" -out "${f}/${f}.mpd" rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1200.mp4" "${f}_400.mp4" "${f}_audio.m4a" else MP4Box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "onDemand" "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1200.mp4" "${f}_400.mp4" -out "${f}/${f}.mpd" rm "${f}_5000.mp4" "${f}_3000.mp4" "${f}_1200.mp4" "${f}_400.mp4" fi # create a jpg for poster. Use imagemagick or just save the frame directly from ffmpeg is you don't have mozcjpeg installed. #ffmpeg -i "${fe}" -ss 00:00:00 -vframes 1 -qscale:v 10 -n -f image2 - | mozcjpeg -progressive -quality 2,35 -quant-table 2 -outfile "${f}"/"${f}".jpg ffmpeg -i "${fe}" -ss 00:00:00 -vframes 1 -qscale:v 10 -n -f image2 "${f}"/"${f}".jpg convert "${f}"/"${f}".jpg -resize 256x256 "${f}"/"${f}_thumb".jpg fi #done #} cd "$SAVEDIR"