Commit 18e904e0 authored by Vermeeren's avatar Vermeeren

add ffmpeg/stream.sh magic

parent 93464938
#!/bin/bash
# (c) 2018 Melvin Vermeeren
# licence: AGPLv3
# in case HOSTNAME isn't set for whatever reason
[[ ! $HOSTNAME ]] && HOSTNAME='HOST'
if [[ ! $1 || $1 == '-h' || $1 == '--help' ]]
then
printf '%s\n' \
"magical ffmpeg/pulse based streaming, with gpg support
edit the script itself to change ffmpeg configuration
use pavucontrol(-qt) to determine what pulseaudio sends to ffmpeg
$0 server port [gpg recipient] [ssl passphrase]
server: listen to connection to this machine
port: tcp port to listen on
gpg: encrypt with gpg to their pubkey
ssl: encrypt with openssl and a passphrase
$0 client host port [gpg recipient] [ssl passphrase]
client: send all output to another host
host: host to send to (either IP or DNS)
port: tcp port on destination server
gpg: encrypt with gpg to their pubkey
ssl: encrypt with openssl and a passphrase
the command to be used on the other side is generated and printing
prior to start. you may want to replace '$HOSTNAME' with your WAN IP"
exit 0
fi
unset nc
unset crypt
case "$1" in
server)
[[ ! $2 ]] && printf 'read --help\n' && exit 1
nc="nc -l -p '$2' -q 0"
[[ $3 && ! $4 ]] && printf 'read --help\n' && exit 1
[[ $3 == gpg ]] && crypt="gpg --batch -e -r '$4' |"
[[ $3 == ssl ]] && crypt="openssl enc -e -k '$4' -aes-256-cbc |"
printf 'on the client, run the following:\n\t%s' \
"nc '$HOSTNAME' '$2' -w 10 -q 0"
[[ $3 == gpg ]] && printf '%s' " | gpg -d"
[[ $3 == ssl ]] && printf '%s' " | openssl enc -d -k '$4' -aes-256-cbc"
printf '%s\n' " | mpv --no-pause -"
;;
client)
[[ ! $2 || ! $3 ]] && printf 'read --help\n' && exit 1
nc="nc '$2' '$3' -w 10 -q 0"
[[ $4 && ! $5 ]] && printf 'read --help\n' && exit 1
[[ $4 == gpg ]] && crypt="gpg --batch -e -r '$5' |"
[[ $4 == ssl ]] && crypt="openssl enc -e -k '$5' -aes-256-cbc |"
printf 'on the server, run the following:\n\t%s' \
"nc -l -p '$3' -q 0"
[[ $4 == gpg ]] && printf '%s' " | gpg -d"
[[ $4 == ssl ]] && printf '%s' " | openssl enc -d -k '$5' -aes-256-cbc"
printf '%s\n' " | mpv --no-pause -"
printf 'please prepare the server now, press ENTER to continue\n'
read -r
;;
*)
printf 'read --help\n'
exit 1
;;
esac
ffmpeg \
-f x11grab -s 4096x2160 -framerate 30 -i :0.0 \
-f pulse -ac 2 -ar 48000 -i default \
-vf "scale=-1:720" -sws_flags fast_bilinear \
-c:v h264_nvenc -preset:v llhq -rc:v vbr \
-c:a aac -b:a 128k \
-f mpegts - \
| eval "$crypt $nc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment