Skip to content

Instantly share code, notes, and snippets.

@shal
Created March 18, 2020 16:33
Show Gist options
  • Save shal/96a741b1e94037c9f5361c0295fb563a to your computer and use it in GitHub Desktop.
Save shal/96a741b1e94037c9f5361c0295fb563a to your computer and use it in GitHub Desktop.
#!/bin/bash
update_system() {
apt-get update && apt-get -y upgrade
}
download_video() {
wget --progress=dot -O input.mp4 "https://hls-jmind-test.s3.eu-central-1.amazonaws.com/example/full_2160p_60fps.mp4"
}
check_for_program() {
local program
program="${1}"
printf "Checking for ${program}\\n "
command -v "${program}"
if [[ "${?}" -ne 0 ]]; then
printf "${program} is not installed, exiting\\n"
exit 1
fi
}
install_ffmpeg() {
apt-get -y install ffmpeg
}
# Update system.
update_system
# Install ffmpeg.
install_ffmpeg
# Check if ffmpeg successfully installed.
check_for_program "ffmpeg"
# download_video
start=`date +%s`
mkdir media
# ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 0 -i input.mp4 -c:a copy -c:v hevc_nvenc media/1080p.m3u8
ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 0 -i input.mp4 \
-vf scale_npp=640:360 -c:v hevc_nvenc -hls_time 4 -hls_playlist_type vod -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k media/360p.m3u8 \
-vf scale_npp=842:480 -c:v hevc_nvenc -hls_time 4 -hls_playlist_type vod -b:v 1400k -maxrate 1498k -bufsize 2100k -b:a 128k media/480p.m3u8 \
-vf scale_npp=1280:720 -c:v hevc_nvenc -hls_time 4 -hls_playlist_type vod -b:v 2800k -maxrate 2996k -bufsize 4200k -b:a 128k media/720p.m3u8 \
-vf scale_npp=1920:1080: -c:v hevc_nvenc -hls_time 4 -hls_playlist_type vod -b:v 5000k -maxrate 5350k -bufsize 7500k -b:a 192k media/1080p.m3u8
end=`date +%s`
duration=$((end-start))
echo "Execution time: ${duration}s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment