elsampsa / valkka-core

Valkka - Create video surveillance, management and analysis programs with PyQt
GNU Lesser General Public License v3.0
186 stars 35 forks source link

What is the best way to use libValkka to build an RTSP application? #60

Closed karma0 closed 1 year ago

karma0 commented 1 year ago

General Question

I'm struggling to get started.

I've skimmed the tutorials for relevant pieces to my work, I've perused the valkka-examples project, and I feel ready to get started. I am trying to figure out what I needed to do to get up and running with a simple development environment.

I have come to understand, given the really great documentation and examples within the ecosystem of Valkka projects, that I need to install Valkka Core. This at first glance didn't seem right, since I thought that I would be installing a Python package, but makes sense given that the core library leverages C++ heavily. Unfortunately, it seems that using virtual environments and installing via pip is not an ideal approach.

In installation of Valkka Core, I seem to hit a snag - PPAs aren't really supported by Ubuntu any longer, and this is the approach in the instructions. So, I decided to pivot and to try to get up and running in a docker container in order to test out the examples and ultimately develop my application there.

Since I would rather not have to modify my installation of Ubuntu to get this running, and running in production will likely be in a container, Docker seems like an ideal solution to building my application, but the README seems to be outdated. I tried initially building just using the Dockerfile for my platform, but after failing I realized the helper scripts are there to help. When I use the tags and versions in the README, they fail, and the build script has a different name.

I decided to modify the files, but I'm getting the same errors (vaapi requested but not found) in any attempt to build. I also attempted to pull the container up on Docker Hub but it failed to run.


If I want to dig in and play with libValkka and use the examples in order to stream RTSP feeds to disk on a headless system and spit out occasional snapshot images, what would be the best approach to get started?

FWIW, I'd be happy do submit some bugs and PRs, but I'm feeling a little overwhelmed with all of the challenges that I'm encountering and I would rather only follow best practices and see if I hit any challenges there first.

elsampsa commented 1 year ago

Installing libValkka

If you are not into PPAs, I recently added a ci/cd pipeline that produces deb packages:

https://github.com/elsampsa/valkka-core/releases

After using sudo dpkg -i packagename.deb you still need to do sudo apt-get install -fy to pull the dependencies.

note for myself: need to add this into the main documentation page

Using PPAs or those packages just mentioned, doesn't really "harm" your ubuntu installation: they just pull a number of dependencies (see the last "depends" clause in here) and then install libValkka.

All that installation is done into the "system-wide" python installation directory usr/lib/python/python3 (seen by all users)

Now, if you use virtualenv or you have installed packages into userspace (i.e. as normal/non-sudo user with pip install) then those packages take preference over the "system-wide" directory, say, the numpy you have in your virtualenv, etc. has preference over the one in usr/lib/python/python3. You can check what actually happens with the quicktest.py script.

So no problem there.

Docker

Docker images are as of today, outdated and I need to build a ci/cd pipeline for them (similar as I did for the deb package) asap

note for myself: do this asap

Compilation problem

VAAPI acceleration was recently added into libValkka. I wanted to add it as a separate deb package, but eventually went for the "easy" solution of using the existing ffmpeg/libav infra for using VAAPI - so now it is part of valkka-core and giving all kinds of dependency problems: https://github.com/elsampsa/valkka-core/issues/9

Please do file a separate ticket on the problems you encounter

note for myself: test for compilation in arm, bitch!

rtsp app

You want to read rtsp stream(s), write it to disk and spit out occasional images & do this in docker. The filterchains would look roughly like this:

live branch
    decoding branch
        push decoded frames through shmem server (1)
    frag-mp4 branch
        push frag-mp4 packets through shmem server (2)

Then in your (separate) python multiprocesses (MP) read (1) and (2). In MP(1), use any standard tool to decode a frame occasionally to jpg/png (PIL.Image for example). In MP(2) dump the received frag-mp4's to the disk.

A word of warning: you need to master & understand python multiprocessing (as per my tutorials).

For similar stuff, this is the most up-to-date example: https://github.com/elsampsa/valkka-streamer This is not so up-to-date, but maybe simpler one: https://github.com/elsampsa/valkka-examples/tree/master/example_projects/basic

Please remember to use the H264 substream of your IP cameras as of today, libValkka is still not using H265.

karma0 commented 1 year ago

Thank you! This is immensely helpful!

It seems that I had misread the notification from apt-add-repository in my late-night shenanigans:

NOTE: PPA will soon be deprecated in the favor of .deb packages from https://github.com/elsampsa/valkka-core

This, followed by a 404 on apt update, which is more likely because I'm on the 23.04 release of Ubuntu:

Err:17 https://ppa.launchpadcontent.net/sampsa-riikonen/valkka/ubuntu lunar Release
  404  Not Found [IP: 185.125.190.52 443]

I'll see if I can get the deb package installed, and go from there. Thanks again!

elsampsa commented 1 year ago

yeah, I only provide packages for ubuntu LTS distros.

elsampsa commented 1 year ago

ok, now you can find fresh docker images in the dockerhub as well - there is now a ci/cd pipeline that constructs docker images automatically