Skip to content

Instantly share code, notes, and snippets.

@WeaponMan
Last active October 23, 2021 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WeaponMan/cbfc9408390e95d6623403dcd4e58342 to your computer and use it in GitHub Desktop.
Save WeaponMan/cbfc9408390e95d6623403dcd4e58342 to your computer and use it in GitHub Desktop.
Gstreamer HLS multiple quality, creates 3 hls playlists (480p@30, 720p@30, 1080p@30) from RSTP source
# if your system doesnt have faac in repos (eg. Debian) replace it with voaacenc
gst-launch-1.0 rtspsrc location="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" latency=10000 name=source \
source. ! queue ! "application/x-rtp, media=(string)video" ! rtph264depay ! h264parse ! nvh264dec ! tee name=video \
source. ! queue ! "application/x-rtp, media=(string)audio" ! rtpmp4gdepay ! decodebin ! audioconvert ! audioresample ! faac bitrate=128000 ! "audio/mpeg,rate=(int)44100" ! tee name=audio \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=842, height=480,framerate=30/1" ! nvh264enc bitrate=1280 ! "video/x-h264,profile=(string)baseline" ! mux480. \
audio. ! queue ! mux480. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1280, height=720,framerate=30/1" ! nvh264enc bitrate=2560 ! "video/x-h264,profile=(string)baseline" ! mux720. \
audio. ! queue ! mux720. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1920, height=1080,framerate=30/1" ! nvh264enc bitrate=5120 ! "video/x-h264,profile=(string)baseline" ! mux1080. \
audio. ! queue ! mux1080. \
mpegtsmux name=mux480 ! hlssink playlist-location=stream-480p.m3u8 location=segment-480p.%d.ts target-duration=5 \
mpegtsmux name=mux720 ! hlssink playlist-location=stream-720p.m3u8 location=segment-720p.%d.ts target-duration=5 \
mpegtsmux name=mux1080 ! hlssink playlist-location=stream-1080p.m3u8 location=segment-1080p.%d.ts target-duration=5
# if your system doesnt have faac in repos (eg. Debian) replace it with voaacenc
gst-launch-1.0 rtspsrc location="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" latency=10000 name=source \
source. ! queue ! "application/x-rtp, media=(string)video" ! rtph264depay ! decodebin ! tee name=video \
source. ! queue ! "application/x-rtp, media=(string)audio" ! rtpmp4gdepay ! decodebin ! audioconvert ! audioresample ! faac bitrate=128000 ! "audio/mpeg,rate=(int)44100" ! tee name=audio \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=842, height=480,framerate=30/1" ! x264enc speed-preset=veryfast tune=zerolatency bitrate=1280 ! "video/x-h264,profile=(string)baseline" ! mux480. \
audio. ! queue ! mux480. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1280, height=720,framerate=30/1" ! x264enc speed-preset=veryfast tune=zerolatency bitrate=2560 ! "video/x-h264,profile=(string)baseline" ! mux720. \
audio. ! queue ! mux720. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1920, height=1080,framerate=30/1" ! x264enc speed-preset=veryfast tune=zerolatency bitrate=5120 ! "video/x-h264,profile=(string)baseline" ! mux1080. \
audio. ! queue ! mux1080. \
mpegtsmux name=mux480 ! hlssink playlist-location=stream-480p.m3u8 location=segment-480p.%d.ts target-duration=5 \
mpegtsmux name=mux720 ! hlssink playlist-location=stream-720p.m3u8 location=segment-720p.%d.ts target-duration=5 \
mpegtsmux name=mux1080 ! hlssink playlist-location=stream-1080p.m3u8 location=segment-1080p.%d.ts target-duration=5
# if your system doesnt have faac in repos (eg. Debian) replace it with voaacenc
GST_VAAPI_ALL_DRIVERS=1 gst-launch-1.0 rtspsrc location="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" latency=10000 name=source \
source. ! queue ! "application/x-rtp, media=(string)video" ! rtph264depay ! h264parse ! vaapih264dec ! tee name=video \
source. ! queue ! "application/x-rtp, media=(string)audio" ! rtpmp4gdepay ! decodebin ! audioconvert ! audioresample ! faac bitrate=128000 ! "audio/mpeg,rate=(int)44100" ! tee name=audio \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=842, height=480,framerate=30/1" ! vaapih264enc bitrate=1280 ! "video/x-h264,profile=(string)baseline" ! mux480. \
audio. ! queue ! mux480. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1280, height=720,framerate=30/1" ! vaapih264enc bitrate=2560 ! "video/x-h264,profile=(string)baseline" ! mux720. \
audio. ! queue ! mux720. \
video. ! queue ! videoconvert ! videoscale ! videorate ! "video/x-raw,width=1920, height=1080,framerate=30/1" ! vaapih264enc bitrate=5120 ! "video/x-h264,profile=(string)baseline" ! mux1080. \
audio. ! queue ! mux1080. \
mpegtsmux name=mux480 ! hlssink playlist-location=stream-480p.m3u8 location=segment-480p.%d.ts target-duration=5 \
mpegtsmux name=mux720 ! hlssink playlist-location=stream-720p.m3u8 location=segment-720p.%d.ts target-duration=5 \
mpegtsmux name=mux1080 ! hlssink playlist-location=stream-1080p.m3u8 location=segment-1080p.%d.ts target-duration=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment