Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
RESOLUTION1="640x360"
BITRATE1="620000"
RESOLUTION2="854x480"
BITRATE2="1493000"
RESOLUTION3="1024x576"
BITRATE3="2131000"
RESOLUTION4="1280x720"
BITRATE4="3658000"
RESOLUTION5="1920x1080"
BITRATE5="8125000"
AUDIO_OPTS="-c:a libvo_aacenc"
VIDEO_OPTS1="-s $RESOLUTION1 -c:v libx264 -b:v $BITRATE1"
VIDEO_OPTS2="-s $RESOLUTION2 -c:v libx264 -b:v $BITRATE2"
VIDEO_OPTS3="-s $RESOLUTION3 -c:v libx264 -b:v $BITRATE3"
VIDEO_OPTS4="-s $RESOLUTION4 -c:v libx264 -b:v $BITRATE4"
VIDEO_OPTS5="-s $RESOLUTION5 -c:v libx264 -b:v $BITRATE5"
DEFAULT_VIDEO_OPTS=" -profile:v baseline -preset:v ultrafast -tune zerolatency -movflags +faststart"
OUTPUT_HLS="-hls_list_size 0 -hls_wrap 0 -start_number 0 -hls_time 5"
ffmpeg -v debug -listen 1 -i rtmp://user1:pass1@localhost:6001/live/test -y -threads 8 \
$AUDIO_OPTS $VIDEO_OPTS1 $DEFAULT_VIDEO_OPTS $OUTPUT_HLS stream_$RESOLUTION1.m3u8 \
$AUDIO_OPTS $VIDEO_OPTS2 $DEFAULT_VIDEO_OPTS $OUTPUT_HLS stream_$RESOLUTION2.m3u8 \
$AUDIO_OPTS $VIDEO_OPTS3 $DEFAULT_VIDEO_OPTS $OUTPUT_HLS stream_$RESOLUTION3.m3u8 \
$AUDIO_OPTS $VIDEO_OPTS4 $DEFAULT_VIDEO_OPTS $OUTPUT_HLS stream_$RESOLUTION4.m3u8 \
$AUDIO_OPTS $VIDEO_OPTS5 $DEFAULT_VIDEO_OPTS $OUTPUT_HLS stream_$RESOLUTION5.m3u8
echo "#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=$BITRATE1,RESOLUTION=$RESOLUTION1
stream_$RESOLUTION1.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=2,BANDWIDTH=$BITRATE2,RESOLUTION=$RESOLUTION2
stream_$RESOLUTION2.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=3,BANDWIDTH=$BITRATE3,RESOLUTION=$RESOLUTION3
stream_$RESOLUTION3.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=4,BANDWIDTH=$BITRATE4,RESOLUTION=$RESOLUTION4
stream_$RESOLUTION4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=5,BANDWIDTH=$BITRATE5,RESOLUTION=$RESOLUTION5
stream_$RESOLUTION5.m3u8
" > index.m3u8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.