Serverside splitting of livestream audio into different streams
Lesezeit 2min
In the last days I did a livestream that was translated simultaniously. At first we had two streaming pc’s which streamed both the exact same picture with to different mono audio channels to youtube. This meant we had 2 audio interfaces, 2 pc’s, 2 capture cards, 2 screens I need to monitor, as well as an internet connection that easily supports 2 streams. Well, we’re in germany, so thats not so easy. I thought: There has to be a better way!
Warning, work in progress!
I knew, that SRS is a good and stable streaming server. I mainly use the default docker container of it to generate a testserver for things like encoder settings and to test audiosync. But it can do quite a bit more.
Amongst other things you can set ffmpeg transocders in the config file.
listen 1935;
max_connections 1000;
srs_log_tank console;
daemon off;
vhost __defaultVhost__ {
transcode live/translated {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine de {
enabled on;
vcodec copy;
acodec libfdk_aac;
abitrate 160;
asample_rate 48000;
achannels 2;
aparams {
af pan=stereo|c0=FL|c1=FL;
}
output rtmp://rtmp-youtube.example/live/stream-deutsch;
}
engine en {
enabled on;
vcodec copy;
acodec libfdk_aac;
abitrate 160;
asample_rate 48000;
achannels 2;
aparams {
af pan=stereo|c0=FR|c1=FR;
}
output rtmp://rtmp-youtube.example/live/stream-englisch;
}
}
}
Both engine’s transcode the stream and restream it to the set destination. Well, in my case the livestream was only speech, so mono audio was fine with me, so I got the german audio on the left channel and the translated audio on the right channel of my stereo mix. The engines copy the video codec, so you do not need a beefy cpu / gpu to encode multiple video streams, it just touches the audio codec. With the audio filter (af) “pan” you can mix and change the audio channels. Basically I tell ffmpeg to put the front left (FL) channel in the german stream on audio channel c0 and c1, and in the translated stream it should put the front right (FR) channel on c0 and c1. Then I just need to set the restream target url and I’m done. Now when I stream to my Server rtmp://live.example.com/live/translated
both ffmpeg encoders automatically start transcoding and restreaming the input stream.
With advanced settings OBS is able to stream more than one stereo audio stream, so it has to be possible to split the audio to two stereo streams, I need to test this at some point.