#!/bin/bash
#
# Author: twily 2017
# Description: Stream music/audio from one computer to another over ssh.
# (Script is intended for use within a LAN).
# Requires: * custom ~/.asroundrc
# * alsa snd-aloop
# * ffmpeg on this end
# * mplayer on the remote end
# *** The script handling the streaming
#ffmpeg -f alsa -channel_layout stereo -ac 2 -i hw:0,1 -b:a 320K -f dts -strict -2 - | \
# ssh -c arcfour -4 dwv@twily \
# mplayer/mplayer.exe - -idle -quiet -nocache -noautosub -novideo -demuxer lavf
ffmpeg -f alsa -channel_layout stereo -ac 2 -i hw:0,1 -b:a 320K -f mp2 - | \
ssh -c arcfour -4 dwv@twily \
mplayer/mplayer.exe - -quiet -nocache -novideo -demuxer audio
# $ ffmpeg -encoders / -formats (eg.: dts, ac3)
# $ mplayer -demuxer help (eg.: lavf)
# *** Enable insecure/faster (arcfour) connections for SSH on remote computer
#
# This command will enable all ciphers available:
# $ sudo echo "Ciphers $(ssh -Q cipher localhost | paste -d , -s)" >> /etc/ssh/sshd_config
#
# Disable compression:
# $ sudo echo "Compression no" >> /etc/ssh/sshd_config
#
# Restart sshd
# (If using cygwin: cygrunsrv -E sshd && cygrunsrv -S sshd)
#
# Sources:
# https://www.lowendtalk.com/discussion/43269/optimize-ssh-tunneling-latency
# https://serverfault.com/questions/116875/how-can-i-disable-encryption-on-openssh
# http://mgalgs.github.io/2014/10/22/enable-arcfour-and-other-fast-ciphers-on-recent-versions-of-openssh.html
# https://superuser.com/questions/979636/error-in-running-sshd-as-a-service-in-cygwin
# *** Disable pulseaudio permanently on local computer
#
# I did not get alsa loopback devices to work with pulse running in the background.
# To disable pulseaudio:
# $ echo "autorespawn = no" > ~/.config/pulse/client.conf
# $ pkill -f pulseaudio
# (Logout/in may be advised)
#
# Sources:
# https://askubuntu.com/questions/489609/how-can-i-cleanly-remove-pulseaudio-in-ubuntu-14-04
# *** Setting up Alsa Loopback devices (snd-aloop)
#
# Check if you have snd-aloop installed:
# $ modinfo snd-aloop
# (If not, follow instructions from 'alsa.opensrc.org' below for installing it)
#
# To enable:
# $ sudo modprobe snd-aloop
# $ sudo echo "snd-aloop" >> /etc/modules
#
# Install my "~/.asoundrc" file below (backup your original in case).
# Get list of devices using:
# $ aplay -l
# Match that up in your new .asoundrc (card #,device #)
#
# Testing the loopback device:
# $ mplayer -ao alsa audio_file.mp3
# $ arecord -D hw:Loopback,1 record.wav -f S16_LE -c 2 -r 48000
# If the record.wav successfully recorded the music it's working!
#
# Sources:
# https://askubuntu.com/questions/891445/alsa-snd-aloop-kernel-module-for-16-04-or-14-04-server
# http://alsa.opensrc.org/Jack_and_Loopback_device_as_Alsa-to-Jack_bridge
# https://www.alsa-project.org/main/index.php/Matrix:Module-aloop
# *** My "~/.asoundrc":
#
# Copy-paste to your home directory and uncomment, backup your own if you have one.
# Replace "[INSERT SOUND CARD #]" with the card index of your soundcard displayed by $ aplay -l
# If it's not working you can try:
# $ alsactl restore -P
# to reload, and play around in alsamixer.
#
#
#defaults.pcm.card [INSERT SOUND CARD #]
#defaults.pcm.device 0
#defaults.ctl.card [INSERT SOUND CARD #]
#
#pcm.!default {
# type asym
# playback.pcm "LoopAndReal"
# capture.pcm "hw:[INSERT SOUND CARD #],0"
#}
#
#pcm.LoopAndReal {
# type plug
# slave.pcm mdev
# route_policy "duplicate"
#}
#
#pcm.mdev {
# type multi
# slaves.a.pcm pcm.MixReale
# slaves.a.channels 2
# slaves.b.pcm pcm.MixLoopback
# slaves.b.channels 2
# bindings.0.slave a
# bindings.0.channel 0
# bindings.1.slave a
# bindings.1.channel 1
# bindings.2.slave b
# bindings.2.channel 0
# bindings.3.slave b
# bindings.3.channel 1
#}
#
#pcm.MixReale {
# type dmix
# ipc_key 1024
# slave {
# pcm "hw:[INSERT SOUND CARD #],0"
# rate 48000
# periods 128
# period_time 0
# period_size 1024 # must be power of 2
# buffer_size 8192
# }
#}
#
#pcm.MixLoopback {
# type dmix
# ipc_key 1025
# slave {
# pcm "hw:Loopback,0,0"
# rate 48000
# periods 128
# period_time 0
# period_size 1024 # must be power of 2
# buffer_size 8192
# }
#}
Top