Last active
November 7, 2024 01:48
-
-
Save noboomu/771871fcb989c31bc231614beb6ce422 to your computer and use it in GitHub Desktop.
Revisions
-
noboomu revised this gist
Nov 7, 2024 . 1 changed file with 22 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,54 +15,36 @@ mkdir $VIDEO_NAME cd $VIDEO_NAME cp ../$1 . ffmpeg -i $1 \ -filter_complex \ "[0:v]split=3[v1][v2][v3]; \ [v1]scale=w=1280:h=768[v1out]; \ [v2]scale=w=800:h=480[v2out]; \ [v3]scale=w=600:h=360[v3out]" \ -map [v1out] -b:v:0 2800k -maxrate:v:0 2996k -bufsize:v:0 4200k -c:v:0 libx265 -threads 12 -cpu-used 4 -movflags +faststart -preset veryfast -g 48 -sc_threshold 0 \ -map [v2out] -b:v:1 1400k -maxrate:v:1 1498k -bufsize:v:1 2100k -c:v:1 libx265 -threads 12 -cpu-used 4 -movflags +faststart -preset veryfast -g 48 -sc_threshold 0 \ -map [v3out] -b:v:2 800k -maxrate:v:2 898k -bufsize:v:2 900k -c:v:2 libx265 -threads 12 -cpu-used 4 -movflags +faststart -preset veryfast -g 48 -sc_threshold 0 \ -f hls \ -hls_time 2 \ -hls_playlist_type vod \ -hls_segment_type fmp4 \ -hls_flags split_by_time \ -master_pl_name master.m3u8 \ -var_stream_map "v:0 v:1 v:2" \ -hls_segment_filename "rendition_%v/segment_%03d.m4s" \ rendition_%v/playlist.m3u8 echo "Rendition streams generated" IMAGE_NAME="$VIDEO_NAME"-poster.jpg echo "image name $IMAGE_NAME" ffmpeg -i $1 -vf "select=eq(n\,0)" -q:v 2 -frames:v 1 $IMAGE_NAME jpegoptim -q -m50 $IMAGE_NAME rm $1
-
noboomu created this gist
Nov 5, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/bin/bash # arg 1 is filename arg 2 is output directory FILENAME=$1 VIDEO_NAME=`echo "${FILENAME%.*}"` echo "Generating renditions for $VIDEO_NAME" [ -d "$VIDEO_NAME" ] && rm -rf "$VIDEO_NAME" mkdir $VIDEO_NAME cd $VIDEO_NAME cp ../$1 . ffmpeg -i $1 -vf scale=1280:720 -c:v libx264 -b:v 2500k -an 720p.mp4 ffmpeg -i $1 -vf scale=854:480 -c:v libx264 -b:v 1500k -an 480p.mp4 ffmpeg -i $1 -vf scale=640:360 -c:v libx264 -b:v 800k -an 360p.mp4 echo "Renditions created. Encoding..." resolutions=("720p" "480p" "360p") for resolution in "${resolutions[@]}"; do echo "generating $resolution stream" mkdir ./$resolution cd ./$resolution ffmpeg -i "../$resolution.mp4" \ -c:v libx264 -preset veryfast -tune zerolatency \ -g 60 -sc_threshold 0 \ -hls_time 2 \ -hls_flags split_by_time \ -hls_segment_type fmp4 \ -hls_playlist_type vod \ -hls_segment_filename "./$resolution_%03d.m4s" \ "$resolution.m3u8" cd .. done echo "Rendition streams generated" IMAGE_NAME="$VIDEO_NAME"-poster.jpg echo "image name $IMAGE_NAME" ffmpeg -i $1 -vf "select=eq(n\,0)" -q:v 2 -frames:v 1 $IMAGE_NAME jpegoptim -q -m50 $IMAGE_NAME rm -rf *.mp4 echo "#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720 720p/720p.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=854x480 480p/480p.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360 360p/360p.m3u8" > master.m3u8