Question / Help General Linux Performances

desaintmartin

New Member
Hello Guys,
I've been playing with OBS for a few days now, and my goal is to setup a Linux machine that receives 4K RTMP streams as pull input (through some RTMP server like nginx or srs) and output it in 4K using NVENC.

So far, the NVENC part works well and I am able to encode my output stream using the video engine from my GTX 1070.

But I have dropped frames even when not streaming, the decoding / filtering / rendering parts alone seem to put my GPU on its knees. Oddly enough, everything works well on Windows.

When looking at GPU usage (using "nvidia-smi dmon" command on linux, GPU-Z on Windows) I see on Linux 100% usage without even streaming, but on Windows it is only around 50%, and ~80% when streaming.
It results that when streaming, on Linux I get ~22FPS instead of 30.

I'm using 0.19.0.3 on both OSes, and nvidia drivers 183 on Linux and 184 on Windows. Linux is a Ubuntu 16.04 up-to-date.

Is there some differences between the openGL / Xorg rendering and the direct3D one that could explain this huge difference? Is it an OBS-related optimization issue? I've seen some 2-years-old post on Stack Overflow where MadCactus relates his early xorg problems, maybe it has changed since that? I really would like to kind of automate everything and Linux is much more indicated for server-like purposes than Windows...
 
Last edited:

desaintmartin

New Member
Thanks, I thought I created it under Linux subforum.

Here are some logs of my running OBS :
Code:
Attempted path: ../../data/obs-studio/locale/en-US.ini
Attempted path: ../../data/obs-studio/locale.ini
Attempted path: ../../data/obs-studio/themes/Dark.qss
Attempted path: ../../data/obs-studio/license/gplv2.txt
info: Processor: 8 logical cores
info: Processor: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
info: Physical Memory: 7867MB Total
info: Kernel Version: Linux 4.4.0-83-generic
info: Distribution: "Ubuntu" "16.04"
info: Portable mode: false
info: OBS 19.0.3-29-g1e7e501 (linux)
info: ---------------------------------
info: ---------------------------------
info: audio settings reset:
    samples per sec: 44100
    speakers:        2
info: ---------------------------------
info: Initializing OpenGL...
info: OpenGL version: 3.2.0 NVIDIA 381.22
info: ---------------------------------
info: video settings reset:
    base resolution:   3840x1920
    output resolution: 3840x1920
    downscale filter:  Bilinear
    fps:               30/1
    format:            NV12
info: ---------------------------------
info: NVENC supported
info: ---------------------------------
info:   Loaded Modules:
info:     text-freetype2.so
info:     rtmp-services.so
info:     obs-x264.so
info:     obs-transitions.so
info:     obs-outputs.so
info:     obs-libfdk.so
info:     obs-filters.so
info:     obs-ffmpeg.so
info:     linux-pulseaudio.so
info:     linux-decklink.so
info:     linux-alsa.so
info:     image-source.so
info:     frontend-tools.so
info: ==== Startup complete ===============================================
info: All scene data cleared
info: ------------------------------------------------
info: pulse-input: Server name: 'pulseaudio 8.0'
info: pulse-input: Audio format: s16le, 44100 Hz, 2 channels
info: pulse-input: Started recording from 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor'
info: pulse-input: Server name: 'pulseaudio 8.0'
error: pulse-input: An error occurred while getting the source info!
info: [Media Source '360 1']: settings:
    input:                   rtmp://127.0.0.1/live/360_1
    input_format:          
    is_looping:              no
    is_hw_decoding:          yes
    is_clear_on_media_end:   no
    restart_on_activate:     yes
    close_when_inactive:     yes
info: [Media Source 'Antenne']: settings:
    input:                   rtmp://127.0.0.1/live/sdi
    input_format:          
    is_looping:              no
    is_hw_decoding:          yes
    is_clear_on_media_end:   yes
    restart_on_activate:     yes
    close_when_inactive:     yes
info: [Media Source '360 2']: settings:
    input:                   rtmp://127.0.0.1/live/360_2
    input_format:          
    is_looping:              no
    is_hw_decoding:          yes
    is_clear_on_media_end:   yes
    restart_on_activate:     yes
    close_when_inactive:     yes
info: Switched to scene 'Scene 360 1'
info: ------------------------------------------------
info: Loaded scenes:
info: - scene 'Scene antenne':
info:     - source: '360 background' (image_source)
info:     - source: 'Antenne' (ffmpeg_source)
info:     - source: 'Antenne' (ffmpeg_source)
info:     - source: 'Antenne' (ffmpeg_source)
info: - scene 'Scene 360 1':
info:     - source: '360 1' (ffmpeg_source)
info:     - source: 'Overlay' (image_source)
info: - scene 'Scene 360 2':
info:     - source: '360 2' (ffmpeg_source)
info:     - source: 'Overlay' (image_source)
info: - scene 'Scene 360 1 2':
info:     - source: '360 1' (ffmpeg_source)
info: - scene 'Scene 360 2 2':
info: ------------------------------------------------
0x18fbea0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d3b00 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d35f0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d3150 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d2c70 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d27e0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x18fca70 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d5790 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d60e0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d6a00 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d2c70 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x18fbea0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d27e0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d6a00 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d3150 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d35f0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19e4900 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d27e0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x18fbea0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d2c70 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d6a00 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19e4900 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d35f0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d3150 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d27e0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x18fbea0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d2c70 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
0x19d6a00 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0x1606160) ): Attempt to set a screen on a child window.
[flv @ 0x7fb6f80009c0] audio stream discovered after head already parsed
[flv @ 0x7fb6f80009c0] video stream discovered after head already parsed
info: adding 23 milliseconds of audio buffering, total audio buffering is now 23 milliseconds
info: adding 23 milliseconds of audio buffering, total audio buffering is now 46 milliseconds

As soon as I start OBS, GPU usage is 100% at full frequency and running at 27FPS instead of 30. I haven't started streaming yet. Decreasing resolution makes it better (obviously) gradually reaching 30FPS and decreasing GPU usage.
Here is some CPU usage:
Code:
Tasks: 242 total,   1 running, 241 sleeping,   0 stopped,   0 zombie
%Cpu(s): 20,5 us,  7,2 sy,  0,0 ni, 71,8 id,  0,0 wa,  0,0 hi,  0,4 si,  0,0 st
KiB Mem :  8056716 total,  5311108 free,  1584192 used,  1161416 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  6118320 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                            
4854 live      20   0 2692484 603260 142160 S 203,7  7,5   1:16.75 obs                                                                                
2148 live      20   0 1260756 137848  75012 S  10,6  1,7   0:41.46 compiz                                                                             
1061 root      20   0  328772 192308  56900 S   4,3  2,4   0:35.85 Xorg                                                                               
4427 live      20   0   26240  12488   5032 S   2,7  0,2   0:13.01 srs                                                                                
2124 live       9 -11  508876  11812   8776 S   2,3  0,1   0:05.60 pulseaudio                                                                         
1038 root     -51   0       0      0      0 S   1,7  0,0   0:06.08 irq/34-nvidia                                                                      
2294 live      20   0  739316  36788  29004 S   1,0  0,5   0:01.56 nm-applet                                                                          
  837 root      20   0  456068  17940  14676 S   0,7  0,2   0:00.75 NetworkManager                                                                     
  768 message+  20   0   44344   5136   3528 S   0,3  0,1   0:00.70 dbus-daemon                                                                        
1761 live      20   0   43912   4284   2808 S   0,3  0,1   0:00.80 dbus-daemon                                                                        
2014 live      20   0  642720  34944  26000 S   0,3  0,4   0:01.45 unity-panel-ser                                                                    
4682 live      20   0 2191944 302024 112360 S   0,3  3,7   0:38.70 firefox                                                                            
4962 live      20   0   41932   3840   3104 R   0,3  0,0   0:00.01 top                                                                                
    1 root      20   0  119564   5884   4156 S   0,0  0,1   0:01.02 systemd                                                                            
    2 root      20   0       0      0      0 S   0,0  0,0   0:00.00 kthreadd                                                                           
    3 root      20   0       0      0      0 S   0,0  0,0   0:00.00 ksoftirqd/0                                                                        
    5 root       0 -20       0      0      0 S   0,0  0,0   0:00.00 kworker/0:0H                                                                       
    7 root      20   0       0      0      0 S   0,0  0,0   0:01.35 rcu_sched                                                                          
    8 root      20   0       0      0      0 S   0,0  0,0   0:00.00 rcu_bh                                                                             
    9 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 migration/0                                                                        
   10 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 watchdog/0                                                                         
   11 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 watchdog/1                                                                         
   12 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 migration/1                                                                        
   13 root      20   0       0      0      0 S   0,0  0,0   0:00.00 ksoftirqd/1                                                                        
   14 root      20   0       0      0      0 S   0,0  0,0   0:00.01 kworker/1:0                                                                        
   15 root       0 -20       0      0      0 S   0,0  0,0   0:00.00 kworker/1:0H                                                                       
   16 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 watchdog/2                                                                         
   17 root      rt   0       0      0      0 S   0,0  0,0   0:00.00 migration/2                                                                        
   18 root      20   0       0      0      0 S   0,0  0,0   0:00.00 ksoftirqd/2                                                                        
   19 root      20   0       0      0      0 S   0,0  0,0   0:00.01 kworker/2:0


To be continued in next post.
 

desaintmartin

New Member
OBS has been built with latest commit from last week (but any version of OBS does the same) with :
Code:
#!/bin/sh

set -e

sudo apt install libcurl4-openssl-dev qtbase5-dev libqt5x11extras5-dev

git clone https://github.com/jp9000/obs-studio.git obs-studio.git || cd obs-studio.git && git fetch && git rebase origin/master && cd ..

mkdir -p $HOME/360/obs/build
cd obs-studio.git
mkdir -p build
cd build
export CMAKE_INCLUDE_PATH=$HOME/360/ffmpeg/build/ffmpeg-3.2.2/include
export  CMAKE_LIBRARY_PATH=$HOME/360/ffmpeg/build/ffmpeg-3.2.2/lib
cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX=$HOME/360/obs/build ..
make -j4
make install

And finally, ffmpeg has been built with :
Code:
#!/bin/sh
set -e

SOURCE_PWD="$HOME/360/ffmpeg/sources"
BUILD_PWD="$HOME/360/ffmpeg/build/ffmpeg-3.2.2"

sudo apt-get -y install autoconf automake build-essential libass-dev \
  libtool \
  pkg-config texinfo zlib1g-dev

# YASM
if [ ! -f "$BUILD_PWD/lib/libyasm.a" ]
then
    cd $SOURCE_PWD
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
    tar xzvf yasm-1.3.0.tar.gz
    cd yasm-1.3.0
    ./configure --prefix="$BUILD_PWD" --bindir="$HOME/bin"
    make -j$(nproc)
    make -j$(nproc) install
    make -j$(nproc) distclean
fi

# x264
if [ ! -f "$BUILD_PWD/lib/libx264.so" ]
then
    cd $SOURCE_PWD
    wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
    tar xjvf last_x264.tar.bz2
    cd x264-snapshot*
    PATH="$HOME/bin:$PATH" ./configure --prefix="$BUILD_PWD" --bindir="$HOME/bin" --enable-shared --disable-opencl
    PATH="$HOME/bin:$PATH" make -j8
    make -j$(nproc) install
    make -j$(nproc) distclean
fi

#libfdk-aac
if [ ! -f "$BUILD_PWD/lib/libfdk-aac.so" ]
then
    cd $SOURCE_PWD
    wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
    tar xzvf fdk-aac.tar.gz
    cd mstorsjo-fdk-aac*
    autoreconf -fiv
    ./configure --prefix="$BUILD_PWD"
    make -j$(nproc)
    make -j$(nproc) install
    make -j$(nproc) distclean
fi

# ffmpeg
sudo apt-get -y install glew-utils libglew-dbg libglew-dev libglew1.13 \
libglewmx-dev libglewmx-dbg freeglut3 freeglut3-dev freeglut3-dbg libghc-glut-dev \
libghc-glut-doc libghc-glut-prof libalut-dev libxmu-dev libxmu-headers libxmu6 \
libxmu6-dbg libxmuu-dev libxmuu1 libxmuu1-dbg nvidia-cuda-dev \
libgnutls-dev libsdl1.2-dev libsdl2-dev

cd "$SOURCE_PWD/ffmpeg-3.2.2"
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$BUILD_PWD" ./configure \
  --prefix="$BUILD_PWD" \
  --extra-cflags="-I$BUILD_PWD/include -I$SOURCE_PWD/Video_Codec_SDK_7.1.9/Samples/common/inc" \
  --extra-ldflags="-L$BUILD_PWD/lib -L$SOURCE_PWD/Video_Codec_SDK_7.1.9/Samples/common/lib/linux/x86_64 -L/usr/lib/nvidia-378/" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libx264 \
  --disable-libx265 \
  --enable-nvenc \
  --enable-cuvid \
  --enable-cuda \
  --enable-nonfree \
  --enable-gpl \
  --enable-pic --enable-shared
PATH="$HOME/bin:$PATH" make -j$(nproc)
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

Of course, running a up-to-date Ubuntu 16.04.
(Would those script be useful in any way? It took a bit of time to have the correct commands to build everything with nvenc support)
 
Top