Skip to content

Commit

Permalink
Merge pull request #14 from elsampsa/sampsa-dev
Browse files Browse the repository at this point in the history
etc
  • Loading branch information
elsampsa authored Sep 8, 2023
2 parents ea79b95 + 3b076a1 commit 1896683
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 77 deletions.
67 changes: 49 additions & 18 deletions api_level_2/cli/rtsp_fps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
For the exact format of the .yaml file, please see below
"""

import os, yaml, time
import os, yaml, time, sys
from valkka.core import *
from valkka.api2.logging import setFFmpegLogLevel, setValkkaLogLevel
"""We can express a filterchain as a hierarchical list as well! (no need for ascii art):
::
Expand All @@ -31,7 +32,7 @@ class Filterchain:

def __init__(self, livethread = None, address = None,
slot = 1, interval = 10, sws = None, verbose = False, n_stack = None,
affinity = None, n_threads = None, ms_pass = None
affinity = None, n_threads = None, ms_pass = None, vaapi = False, tcp = False
):
self.livethread = livethread
self.interval = int(interval*1000) # sec to msec
Expand All @@ -40,6 +41,8 @@ def __init__(self, livethread = None, address = None,
self.sws = sws # None or tuple: (width, height)
self.verbose = verbose
self.n_stack = n_stack # not used
self.vaapi = vaapi
self.tcp = tcp

# *** DECODE BRANCH ***
# Create the FPSCountFrameFilter
Expand Down Expand Up @@ -76,10 +79,17 @@ def __init__(self, livethread = None, address = None,
#if self.n_stack is not None:
# ffc.n_basic = dic["n_stack_live"]

self.avthread = AVThread(
"avthread-" + str(self.slot),
self.fork2) # feeds the bitmap fork & decoding branch
# self.framefifo_ctx)
if self.vaapi:
print("using vaapi for stream", address)
self.avthread = VAAPIThread(
"avthread-" + str(self.slot),
self.fork2) # feeds the bitmap fork & decoding branch
# self.framefifo_ctx)
else:
self.avthread = AVThread(
"avthread-" + str(self.slot),
self.fork2) # feeds the bitmap fork & decoding branch
# self.framefifo_ctx)

if n_threads:
print("setting", n_threads,"threads per libav decoder")
Expand All @@ -95,7 +105,11 @@ def __init__(self, livethread = None, address = None,
self.ctx =\
LiveConnectionContext(LiveConnectionType_rtsp,
self.address, self.slot, self.fork1)

if self.tcp:
print("USING TCP")
self.ctx.request_tcp = True
else:
print("USING UDP")

def __call__(self):
# start decoding thread
Expand All @@ -117,7 +131,7 @@ def waitStop(self):
self.avthread.waitStopCall()


def makeChains():
def makeChains(yaml_file = "streams.yaml"):
"""Create filterchains based on a yaml file that looks like this:
::
Expand All @@ -129,6 +143,7 @@ def makeChains():
use: true # optional
bind: 1 # optional
ms_pass: 100 # optional (see below)
vaapi: true # optional
- name: that other camera
address: rtsp://user:[email protected]
interpolate: [300,300] # optional
Expand All @@ -142,6 +157,7 @@ def makeChains():
bind: 0 # bind livethread to a core # optional
decoder_threads: 2 # how many libav(ffmpeg) threads per decoder
ms_pass: 100 # after decoding to YUV, pass each frame only every 100 ms # optional
vaapi: true # use vaapi for streams # optional
If the top-level "interpolate" is present, then all YUVs are interpolated into that
RGB dimensions
Expand Down Expand Up @@ -172,13 +188,16 @@ def makeChains():
..can just use buffers that overflow (& should shut up the overflow warning)
"""
with open('streams.yaml','r') as f:
with open(yaml_file,'r') as f:
dic=yaml.safe_load(f)

itp = dic.get("interpolate", None)
verbose = False
if ("verbose" in dic) and (dic["verbose"]):
verbose = True
verbose = dic.get("verbose", False)
core_verbose = dic.get("core-verbose", False)

if core_verbose:
setFFmpegLogLevel(3)
setValkkaLogLevel(4)

assert "streams" in dic, "needs streams"
assert "duration" in dic, "needs test duration"
Expand All @@ -193,10 +212,11 @@ def makeChains():
print("binding livethread to", dic["bind"])
livethread.setAffinity(dic["bind"])

n_stack_decoder = dic.get("n_stack_decoder", None)
# --> not used
n_stack_decoder = dic.get("n_stack_decoder", None) # not used
n_threads = dic.get("decoder_threads", None)
ms_pass = dic.get("ms_pass", None)
vaapi = dic.get("vaapi", False)
tcp = dic.get("tcp", False)

chains = []
cc = 1
Expand All @@ -210,6 +230,8 @@ def makeChains():

bind = stream.get("bind", None)
ms_pass_ = stream.get("ms_pass", ms_pass)
vaapi_ = stream.get("vaapi", vaapi)
tcp_ = stream.get("tcp", tcp)

fc = Filterchain(
livethread = livethread,
Expand All @@ -221,7 +243,9 @@ def makeChains():
n_stack = n_stack_decoder,
affinity = bind,
n_threads = n_threads,
ms_pass = ms_pass_
ms_pass = ms_pass_,
vaapi = vaapi_,
tcp = tcp_
)
chains.append(fc)
cc+=1
Expand All @@ -231,8 +255,13 @@ def makeChains():

# start live connections and decoders
print("USING", len(chains), "STREAM(S)")
print("all addresses:")
for i, chain in enumerate(chains):
print(i+1, chain.address)
print("")
for chain in chains:
chain()
# time.sleep(0.1)

print("all cams started, running test for", dic["duration"], "seconds")
time.sleep(dic["duration"])
Expand All @@ -248,6 +277,8 @@ def makeChains():


if __name__ == "__main__":
from valkka.api2.logging import setFFmpegLogLevel
setFFmpegLogLevel(0)
makeChains()
if len(sys.argv) < 2:
makeChains()
else:
print("using input file", sys.argv[1])
makeChains(sys.argv[1])
4 changes: 2 additions & 2 deletions api_level_2/cli/single_stream_rtsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def main():

chain = BasicFilterchain(
livethread=livethread, openglthread=openglthread, address=address, slot=1,
# vaapi = True
vaapi = False
vaapi = True
# vaapi = False
)

chain.decodingOn() # tell the decoding thread to start its job
Expand Down
12 changes: 6 additions & 6 deletions api_level_2/cli/streams.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
streams:
- name: mummocamera
# address: rtsp://admin:[email protected]
address: rtsp://admin:[email protected]
address: rtsp://admin:[email protected]
use: true
bind: 1
ms_pass: 100
- name: mummocamera
# address: rtsp://admin:[email protected]
address: rtsp://admin:[email protected]
address: rtsp://admin:[email protected]
use: false
bind: 2
interpolate: [300,300]
interval: 5
duration: 20
verbose: true
duration: 10
# verbose: true
verbose: false
bind: 0
decoder_threads: 2
# ms_pass: 100
vaapi: true
Binary file modified docs/_build/doctrees/hardware.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/requirements.doctree
Binary file not shown.
17 changes: 17 additions & 0 deletions docs/_build/html/_sources/hardware.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ Please first read this :ref:`word of warning <gpuaccel>`.

Comes in the basic libValkka installation (and uses ffmpeg/libav infrastructure) - no additional packages needed.

First of all, the user using VAAPI, must belong to the "video" user group:

.. code:: bash
groups $USER
# run the following command if the user does not appear in the video group
sudo usermod -a -G video $USER
# after that you still need to logout & login
In order to use the VAAPI acceleration, just replace `AVThread` with `VAAPIThread`, i.e. instead of

.. code:: python
Expand All @@ -68,6 +77,7 @@ use this:
avthread = VAAPIThread("avthread", target_filter)
For more details about VAAPI, you can read `this <https://wiki.archlinux.org/title/Hardware_video_acceleration>`_,
`this <https://wiki.debian.org/HardwareVideoAcceleration>`_ and `this <https://en.wikipedia.org/wiki/Video_Acceleration_API#Supported_hardware_and_drivers>`_.

Expand All @@ -92,6 +102,13 @@ If you wish to use VAAPI in a docker environment, you should start docker with
And be sure that the host machine has all required vaapi-related libraries installed (the easiest way: install libValkka on the host as well).

Finally, you can follow the GPU usage in realtime with:

.. code:: bash
sudo intel_gpu_top
*NVidia / CUDA*

Provided as a separate package that installs into the `valkka.nv` namespace and is used like this:
Expand Down
54 changes: 42 additions & 12 deletions docs/_build/html/_sources/requirements.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
Installing
==========

Install valkka-core
-------------------
The debian package includes the core library, its python bindings and some API level 2 python code. The python part is installed "globally" into */usr/lib/python3/dist-packages/*

.. note:: LibValkka comes precompiled and packaged for a certain ubuntu distribution version. This means that the compilation and it's dependencies assume the default
python version of that distribution. Using custom-installed python versions, anacondas and whatnot might cause dependency problems.

A. Install using PPA
--------------------

*the preferred way*

For recent ubuntu distributions, the core library binary packages and python bindings are provided by a PPA repository. Subscribe to the PPA repo (do this only once) with:

Expand All @@ -20,27 +27,50 @@ Install with:
sudo apt-get update
sudo apt-get install valkka

Test the installation with:

::

curl https://raw.githubusercontent.com/elsampsa/valkka-examples/master/quicktest.py
python3 quicktest.py

When you need to update valkka, do:

::

sudo apt-get update
sudo apt-get install --only-upgrade valkka


B. Install using releases
-------------------------

*if you don't like PPAs*

You can download and install the required .deb packages "manually" from the
`releases page <https://github.com/elsampsa/valkka-core/releases>`_

::

sudo dpkg -i Valkka-*.deb
sudo apt-get install -fy

The last line pulls the dependencies.

Repeat the process when you need to update.

C. Compile yourself
-------------------

*the last resort*

If you're not using a recent Ubuntu distro and need to build libValkka and it's python bindings yourself,
please refer to the `valkka-core github page <https://github.com/elsampsa/valkka-core#compile-yourself>`_.

The debian package includes the core library, its python bindings and some API level 2 python code. The python part is installed "globally" into */usr/lib/python3/dist-packages/*

.. note:: LibValkka comes precompiled and packaged for a certain ubuntu distribution version. This means that the compilation and it's dependencies assume the default
python version of that distribution. Using custom-installed python versions, anacondas and whatnot might cause dependency problems.
Test your installation
----------------------

Test the installation with:

::

curl https://raw.githubusercontent.com/elsampsa/valkka-examples/master/quicktest.py -o quicktest.py
python3 quicktest.py


Numpy
-----
Expand Down
11 changes: 11 additions & 0 deletions docs/_build/html/hardware.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ <h2>Linux clients<a class="headerlink" href="#linux-clients" title="Permalink to
<p>Please first read this <a class="reference internal" href="decoding.html#gpuaccel"><span class="std std-ref">word of warning</span></a>.</p>
<p><em>VAAPI</em></p>
<p>Comes in the basic libValkka installation (and uses ffmpeg/libav infrastructure) - no additional packages needed.</p>
<p>First of all, the user using VAAPI, must belong to the “video” user group:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>groups <span class="nv">$USER</span>
<span class="c1"># run the following command if the user does not appear in the video group</span>
sudo usermod -a -G video <span class="nv">$USER</span>
<span class="c1"># after that you still need to logout &amp; login</span>
</pre></div>
</div>
<p>In order to use the VAAPI acceleration, just replace <cite>AVThread</cite> with <cite>VAAPIThread</cite>, i.e. instead of</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">avthread</span> <span class="o">=</span> <span class="n">AVThread</span><span class="p">(</span><span class="s2">&quot;avthread&quot;</span><span class="p">,</span> <span class="n">target_filter</span><span class="p">)</span>
</pre></div>
Expand All @@ -95,6 +102,10 @@ <h2>Linux clients<a class="headerlink" href="#linux-clients" title="Permalink to
</pre></div>
</div>
<p>And be sure that the host machine has all required vaapi-related libraries installed (the easiest way: install libValkka on the host as well).</p>
<p>Finally, you can follow the GPU usage in realtime with:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo intel_gpu_top
</pre></div>
</div>
<p><em>NVidia / CUDA</em></p>
<p>Provided as a separate package that installs into the <cite>valkka.nv</cite> namespace and is used like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">valkka.nv</span> <span class="kn">import</span> <span class="n">NVThread</span>
Expand Down
5 changes: 4 additions & 1 deletion docs/_build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ <h1>Valkka<a class="headerlink" href="#valkka" title="Permalink to this headline
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="requirements.html">Installing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#install-valkka-core">Install valkka-core</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#a-install-using-ppa">A. Install using PPA</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#b-install-using-releases">B. Install using releases</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#c-compile-yourself">C. Compile yourself</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#test-your-installation">Test your installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#numpy">Numpy</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#install-the-testsuite">Install the testsuite</a></li>
<li class="toctree-l2"><a class="reference internal" href="requirements.html#gtk">GTK</a></li>
Expand Down
Loading

0 comments on commit 1896683

Please sign in to comment.