Skip to content

Instantly share code, notes, and snippets.

@rmueller
Created March 12, 2019 20:58
Show Gist options
  • Save rmueller/29f47a1b7f5723a88319154c9bd4ca36 to your computer and use it in GitHub Desktop.
Save rmueller/29f47a1b7f5723a88319154c9bd4ca36 to your computer and use it in GitHub Desktop.
#!/bin/bash
######################################################################
##
## [Camera Broadcaster Script]
##
## Can achive 200ms delay when playing from Flash via RTMP
##
######################################################################
# Keyframe Interval in seconds; make sure this is less than 500 frames otherwise a keyframe will be added
keyint_secs="1";
# Video Bitrate
bitrate="2000k";
buffsize="2000k";
rate="-minrate $bitrate -maxrate $bitrate -bufsize $buffsize"
# Video Capture -timestamps abs
video_source="-fflags +nobuffer -f v4l2 -framerate 30 -video_size '640x360' -input_format mjpeg -i /dev/video0"
#video_source="-f x11grab -framerate 30 -video_size '1280x720' -i :0.0"
video_codec="-vf format=yuv420p -c:v libx264 -b:v $bitrate -preset:v ultrafast -profile:v main -tune:v zerolatency -x264-params b-adapt=0:bframes=0:keyint=300:keyint-min=300:scenecut=0 -force_key_frames \"expr:gte(t,n_forced*$keyint_secs)\""
# Audio Capture
audio_source="-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100"
#audio_source="-fflags +nobuffer -f alsa -ac 2 -ar 44100 -i hw:3"
audio_codec="-c:a aac -ac 2 -b:a 256k -strict -2"
output="-f flv \"rtmp://localhost/live/_definst_/clock\""
#output="-f flv camera.flv"
eval "ffmpeg -y -loglevel verbose -ss 00:00:05 -vsync 2 $video_source $audio_source $video_codec $audio_codec $rate $output";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment