Skip to content

Instantly share code, notes, and snippets.

@cbilson
Last active November 18, 2022 23:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cbilson/8148606 to your computer and use it in GitHub Desktop.
Save cbilson/8148606 to your computer and use it in GitHub Desktop.
Messing around with screen capture -> http(hls)
#!/bin/bash
# also tried: VLC -> fifo -> ffmpeg(transcode to x264) -> RTMP -> NGINX, but didn't work for me
# FIFO=/tmp/screen-capture.raw
# mkfifo $FIFO
VLC=/Applications/VLC.app/Contents/MacOS/VLC
# FFMPEG=`which ffmpeg`
PIDFILE=/tmp/screen-capture-vlc.pid
on_die () {
# kill all children
kill -9 `cat $PIDFILE`
}
trap 'on_die' TERM
$VLC --intf dummy screen:// \
--screen-fps "30" \
--screen-caching 100 \
--sout file/muxer:- \
--ttl 1 \
--pidfile $PIDFILE \
--sout-keep
wait
user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 9999;
server_name localhost;
access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/Cellar/nginx-rtmp-module/HEAD;
}
location /control {
rtmp_control all;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-control no-cache;
}
}
}
rtmp {
server {
listen 1935;
#chunk_size 8192;
ping 30s;
notify_method get;
application live {
live on;
hls on;
hls_path /tmp/hls;
hls_sync 100ms;
hls_continuous on;
#This will start/stop our ffmpeg script and camera stream (thanks #towolf)
exec_static /usr/local/etc/nginx/capture-screen.sh;
exec_kill_signal term;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment