Post Wed Jun 01, 2022 7:51 pm

Tip: Configure Ubiquiti (Ubnt) Stream as an Online Source

Hello everyone!

I've been dealing with incompatibilities between Ubiquiti (and Intelbras) Cameras/NVRs as the "online source" option on Serviio for quite a while now. Fortunately, Serviio uses ffmpeg in its backend, and there's a way to customize the ffmpeg.exe command line for each source.

First of all, you can update the ffmpeg.exe binary file in the /lib subdirectory without any problems. For some obscure (to me) reason, different versions of ffmpeg deal differently with RTSP. Some will corrupt more the video frames, others will corrupt less the video frames, and some will work flawlessly. The version that comes with Serviio installation is a broken one (will corrupt the video frames less). Get some of the lastest binary versions and test them.

Last week, Ubiquiti rolled out an update that added an audio stream to the RTSP stream and, once again, broke the connection between Serviio and my Unifi Cloud Key Gen 2.

I won't explain line by line what I've done, but here is how I'm customizing the ffmpeg command:

In the file <Serviio install folder>/config/user.vmoptions, we define our custom location of ffmpeg:
  Code:
-Dffmpeg.location=C:\Program Files\Serviio\lib\ffmpeg.bat


Then, in the batch file referenced above, we put the logic to assembly the desired command. This is how mine looks right now:
  Code:
@echo off
setlocal EnableDelayedExpansion
set "ALL_PARAMS=%*"
REM two empty lines below are required


REM for /f %%a in ('copy /z "%~f0" nul') do set "CR=%%a"

call :IsContains ddns-intelbras
if not ERRORLEVEL 1 (set INTELBRAS=1)

call :IsContains 192.168.2.20
if not ERRORLEVEL 1 (set UBNT=1)

IF DEFINED INTELBRAS (
  SET ALL_PARAMS=%ALL_PARAMS% -rtsp_transport tcp
)
ELSE (
  IF DEFINED UBNT (
    SET ALL_PARAMS=%ALL_PARAMS:-map 0:1=-map 0:2%
  )
)

"%~dp0\ffmpeg.exe" !ALL_PARAMS!

GOTO :eof

REM check if ALL_PARAMS contains passed string, will set ERRORLEVEL 0 if found, 1 otherwise
:IsContains
echo "!ALL_PARAMS!" | FINDSTR /C:"%1" >nul
REM IF ERRORLEVEL 1 (ECHO not found) else (ECHO found)
EXIT /B