Last active
April 16, 2021 22:23
-
-
Save tuhinpal/35d703ee8d1d76f40aa8015d9df5be6f to your computer and use it in GitHub Desktop.
Convert video to hls
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
echo "Enter input video path with extension (Ex. input.mp4)" | |
read input_path | |
echo "Enter output folder (Ex. output)" | |
read output_path | |
mkdir $output_path | |
ffmpeg -hide_banner -y -i $input_path \ | |
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k -hls_segment_filename $output_path/360p_%03d.ts $output_path/360p.m3u8 \ | |
-vf scale=w=842:h=480:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 1400k -maxrate 1498k -bufsize 2100k -b:a 128k -hls_segment_filename $output_path/480p_%03d.ts $output_path/480p.m3u8 \ | |
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 2800k -maxrate 2996k -bufsize 4200k -b:a 128k -hls_segment_filename $output_path/720p_%03d.ts $output_path/720p.m3u8 \ | |
-vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 5000k -maxrate 5350k -bufsize 7500k -b:a 192k -hls_segment_filename $output_path/1080p_%03d.ts $output_path/1080p.m3u8 | |
cd $output_path | |
echo '#EXTM3U | |
#EXT-X-VERSION:3 | |
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360 | |
360p.m3u8 | |
#EXT-X-STREAM-INF:BANDWIDTH=1400000,RESOLUTION=842x480 | |
480p.m3u8 | |
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720 | |
720p.m3u8 | |
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080 | |
1080p.m3u8' > master.m3u8 | |
echo "Done. Please check $output_path/master.m3u8" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instruction
Output quality
Output filename
master.m3u8
Credits