https://github.com/paolo-pr/laav
Asynchronous Audio / Video Library for H264 / MJPEG / OPUS / AAC / MP2 encoding, transcoding, recording and streaming from live sources
https://github.com/paolo-pr/laav
aac audio-library audio-streaming h264 http low-latency matroska mjpeg-decoder mjpeg-stream mpegts mqtt stream udp-server video-live video-processing video-recording video-streaming video-surveillance
Last synced: 3 months ago
JSON representation
Asynchronous Audio / Video Library for H264 / MJPEG / OPUS / AAC / MP2 encoding, transcoding, recording and streaming from live sources
- Host: GitHub
- URL: https://github.com/paolo-pr/laav
- Owner: paolo-pr
- License: gpl-3.0
- Created: 2017-04-25T10:57:09.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-09-17T16:15:26.000Z (almost 3 years ago)
- Last Synced: 2024-11-01T08:33:50.616Z (8 months ago)
- Topics: aac, audio-library, audio-streaming, h264, http, low-latency, matroska, mjpeg-decoder, mjpeg-stream, mpegts, mqtt, stream, udp-server, video-live, video-processing, video-recording, video-streaming, video-surveillance
- Language: C++
- Homepage:
- Size: 457 KB
- Stars: 63
- Watchers: 4
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Live Asynchronous Audio Video Library
## ABOUT
A header-only **C++** library which wraps [FFmpeg](https://ffmpeg.org/), [V4L2](https://linuxtv.org/), [ALSA](https://www.alsa-project.org) and [Libevent](http://libevent.org/) for capturing audio and video from multiple live sources (cameras and microphones) and
* Encoding (video: **H264**, audio: **AAC**, **MP2** and **OPUS**)
* Decoding (video: **MJPEG**) / transcoding (video: **MJPEG** -> **H264**)
* Recording to file (**MPEGTS** and **MATROSKA** containers, audio and/or video)
* Streaming (**HTTP** and **UDP** protocols for **MPEGTS** and **MATROSKA** containers)
* Basic image processingThe project is useful for building **video surveillance** systems as well, consisting in media servers which stream and record at the same time and which can be controlled through **MQTT** or **HTTP** commands (see **[THIS](https://github.com/paolo-pr/laav/blob/master/mqtt-avsystem/README.md)** and **[THIS](https://github.com/paolo-pr/laav/blob/master/examples/VideoExample_2.cpp)** examples).
The project runs on **Linux** (**ALSA** and **V4L2** devices), but a Windows port is planned (any contribution is welcome!).
## FEATURES
* All the audio/video tasks are made with **strictly asynchronous** multiple **pipes**, inside one main loop. This allows to create **simple**, **short** (a complete live H264 grabber/streamer can be made with less than 40 lines of code, see **[THIS](https://github.com/paolo-pr/laav/blob/master/examples/VideoExample_1.cpp)** example), **easy to read** and **intuitive** code in which all the pipes can be realized through overloaded operators, in the following form:
```
while (!LAAVStop)
{
// Pipe
grabber >> converter >> encoder >> streamer;
// Audio-video events catcher
eventsCatcher->catchNextEvent();
}
```* **Threads are not used at all** and they are intentionally discouraged in order to avoid that they can be improperly used for decoupling tasks, without taking advantage from multi-core systems.
* All the audio/video modules (-> classes) make **extensive use of templates** and all their possible concatenations are checked at **compile-time**, so to avoid inconsistent pipes.
* All the pipes are **safe at runtime**. I.E: when a source is disconnected or temporarily unavailable, the main loop can continue without necessarily having to check errors (they can be checked, anyway, by polling the status of each node: see **[THIS](https://github.com/paolo-pr/laav/blob/master/examples/AudioVideoExample_2.cpp)** example)
* The library is all RAII-designed (basically it safely wraps Libavcodec/format, V4L and ALSA) and **the user doesn't have to bother with pointers and memory management**.
* The public API is intended to be intuitive, with a few self-explanatory functions.## COMPILING / RUNNING
Dependencies: **[FFmpeg](https://ffmpeg.org/)** >= **5.0** (tested with **5.0** version), **[Libevent](http://libevent.org/)** and pkg-config (optional: see the compile command below).
**[FFmpeg](https://ffmpeg.org/)** needs **[x264](http://www.videolan.org/developers/x264.html)** for H264 support and **[libopus](http://opus-codec.org/)** for OPUS support.* Include the library global header (LAAV.hpp), as shown in the [examples](https://github.com/paolo-pr/laav/tree/master/examples), in YourProgram.cpp and execute:
```
g++ -Wall -std=c++11 -DLINUX -o YourProgram YourProgram.cpp `pkg-config --libs libavformat libavcodec libavutil libswresample libswscale libevent alsa`
```
* Execute ./CompileExamples for compiling the provided examples.
* API documentation in HTML format can be created by executing, inside the doxy directory:
```
doxygen Doxyfile
```
The library has been tested with the **[VLC](http://www.videolan.org/)**, **[FFPLAY](https://ffmpeg.org/)** and **[MPV](https://mpv.io/)** media players, but other players should work as well.
In order to reduce the network streams' latency, use the following flags on the client side:VLC (tested with v2.2.4: set a low value for --network-caching flag):
```
vlc --network-caching 200 http://stream_url
```
FFPLAY:
```
ffplay -fflags nobuffer http://stream_url
```## HOW TO USE IT
See the provided **[EXAMPLES](https://github.com/paolo-pr/laav/tree/master/examples)**
## TODO
* Improve the compile-time error messages, for inconsistent pipes, with more static_assert(...) calls.
* Add a RTSP/RTP streaming server.
* Windows port (basically, it will consist in creating Windows based classes corresponding to the ALSAGrabber and V4L2Grabber classes, with the same API, and few other things: any contribution is welcome!).
* MPEGTS-MJPEG is currently NOT supported.