Last active
April 24, 2024 22:29
-
-
Save signalwerk/5eaddbd2825501e4ea61784efbf84a31 to your computer and use it in GitHub Desktop.
Convert a video to HLS format with multiple resolutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Convert a video to HLS format with multiple resolutions | |
# Usage: ./convert.sh input.mp4 | |
# current version: | |
# https://gist.github.com/signalwerk/5eaddbd2825501e4ea61784efbf84a31 | |
# for more complex converting see also | |
# https://gist.github.com/mrbar42/ae111731906f958b396f30906004b3fa | |
set -e | |
# delete old files | |
rm -f master.m3u8 | |
rm -rf v360p | |
rm -rf v480p | |
rm -rf v720p | |
rm -rf v1080p | |
echo "Converting $1" | |
# for mute videos | |
ffmpeg -i "$1" \ | |
-map 0:v -map 0:a -map 0:v -map 0:a -map 0:v -map 0:a -map 0:v -map 0:a \ | |
-c:v libx264 -crf 22 \ | |
-c:a aac -b:a 128k \ | |
-filter:v:0 "scale=-2:360" -maxrate:v:0 800k -bufsize:v:0 1600k \ | |
-filter:v:1 "scale=-2:480" -maxrate:v:1 1500k -bufsize:v:1 3000k \ | |
-filter:v:2 "scale=-2:720" -maxrate:v:2 3000k -bufsize:v:2 6000k \ | |
-filter:v:3 "scale=-2:1080" -maxrate:v:3 5000k -bufsize:v:3 10000k \ | |
-var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p v:3,a:3,name:1080p" \ | |
-preset fast -hls_list_size 10 -threads 0 -f hls \ | |
-hls_playlist_type vod \ | |
-hls_time 1 -hls_flags independent_segments \ | |
-master_pl_name "master.m3u8" \ | |
-hls_segment_filename "v%v/segment_%04d.ts" \ | |
-y "v%v/stream.m3u8" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment