Skip to content

Commit 8ce4972

Browse files
authored
rpi: support exposing a secondary stream from the same camera (#4426)
1 parent 9579989 commit 8ce4972

File tree

18 files changed

+619
-282
lines changed

18 files changed

+619
-282
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
/apidocs/*.html
66
/internal/core/VERSION
77
/internal/servers/hls/hls.min.js
8-
/internal/staticsources/rpicamera/mtxrpicam_*
8+
/internal/staticsources/rpicamera/mtxrpicam_*/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
/apidocs/*.html
55
/internal/core/VERSION
66
/internal/servers/hls/hls.min.js
7-
/internal/staticsources/rpicamera/mtxrpicam_*
7+
/internal/staticsources/rpicamera/mtxrpicam_*/

README.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ _rtsp-simple-server_ has been rebranded as _MediaMTX_. The reason is pretty obvi
8888
* [By device](#by-device)
8989
* [Generic webcam](#generic-webcam)
9090
* [Raspberry Pi Cameras](#raspberry-pi-cameras)
91+
* [Adding audio](#adding-audio)
92+
* [Secondary stream](#secondary-stream)
9193
* [By protocol](#by-protocol)
9294
* [SRT clients](#srt-clients)
9395
* [SRT cameras and servers](#srt-cameras-and-servers)
@@ -274,7 +276,7 @@ The RTSP protocol supports multiple underlying transport protocols, each with it
274276
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp -rtsp_transport tcp rtsp://localhost:8554/mystream
275277
```
276278

277-
The resulting stream will be available in path `/mystream`.
279+
The resulting stream is available in path `/mystream`.
278280

279281
#### GStreamer
280282

@@ -301,7 +303,7 @@ gst-launch-1.0 filesrc location=file.mp4 ! qtdemux name=d \
301303
d.video_0 ! rtspclientsink protocols=tcp name=s location=rtsp://localhost:8554/mystream
302304
```
303305

304-
The resulting stream will be available in path `/mystream`.
306+
The resulting stream is available in path `/mystream`.
305307

306308
GStreamer can also publish a stream by using the [WebRTC / WHIP protocol](#webrtc). Make sure that GStreamer version is at least 1.22, and that if the codec is H264, the profile is baseline. Use the `whipclientsink` element:
307309

@@ -350,7 +352,7 @@ Latest versions of OBS Studio can publish to the server with the [WebRTC / WHIP
350352

351353
Save the configuration and click `Start streaming`.
352354

353-
The resulting stream will be available in path `/mystream`.
355+
The resulting stream is available in path `/mystream`.
354356

355357
#### OpenCV
356358

@@ -425,7 +427,7 @@ while True:
425427
start = now
426428
```
427429

428-
The resulting stream will be available in path `/mystream`.
430+
The resulting stream is available in path `/mystream`.
429431

430432
#### Unity
431433

@@ -536,7 +538,7 @@ public class WebRTCPublisher : MonoBehaviour
536538

537539
In the _Hierarchy_ window, find or create a scene and a camera, then add the `WebRTCPublisher.cs` script as component of the camera, by dragging it inside the _Inspector_ window. then Press the _Play_ button at the top of the page.
538540

539-
The resulting stream will be available in path `/unity`.
541+
The resulting stream is available in path `/unity`.
540542

541543
#### Web browsers
542544

@@ -546,7 +548,7 @@ Web browsers can publish a stream to the server by using the [WebRTC protocol](#
546548
http://localhost:8889/mystream/publish
547549
```
548550

549-
The resulting stream will be available in path `/mystream`.
551+
The resulting stream is available in path `/mystream`.
550552

551553
This web page can be embedded into another web page by using an iframe:
552554

@@ -584,7 +586,7 @@ Where `USB2.0 HD UVC WebCam` is the name of a webcam, that can be obtained with:
584586
ffmpeg -list_devices true -f dshow -i dummy
585587
```
586588

587-
The resulting stream will be available in path `/cam`.
589+
The resulting stream is available in path `/cam`.
588590

589591
#### Raspberry Pi Cameras
590592

@@ -611,7 +613,7 @@ If you want to run the standard (non-Docker) version of the server:
611613
source: rpiCamera
612614
```
613615

614-
The resulting stream will be available in path `/cam`.
616+
The resulting stream is available in path `/cam`.
615617

616618
If you want to run the server inside Docker, you need to use the `latest-rpi` image and launch the container with some additional flags:
617619

@@ -639,6 +641,8 @@ paths:
639641

640642
All available parameters are listed in the [sample configuration file](/mediamtx.yml).
641643

644+
##### Adding audio
645+
642646
In order to add audio from a USB microfone, install GStreamer and alsa-utils:
643647

644648
```sh
@@ -678,7 +682,42 @@ paths:
678682
runOnInitRestart: yes
679683
```
680684

681-
The resulting stream will be available in path `/cam_with_audio`.
685+
The resulting stream is available in path `/cam_with_audio`.
686+
687+
##### Secondary stream
688+
689+
It is possible to enable a secondary stream from the same camera, with a different resolution, FPS and codec. Configuration is the same of a primary stream, with `rpiCameraSecondary` set to `true` and parameters adjusted accordingly:
690+
691+
```yml
692+
paths:
693+
# primary stream
694+
rpi:
695+
source: rpiCamera
696+
# Width of frames.
697+
rpiCameraWidth: 1920
698+
# Height of frames.
699+
rpiCameraHeight: 1080
700+
# FPS.
701+
rpiCameraFPS: 30
702+
703+
# secondary stream
704+
secondary:
705+
source: rpiCamera
706+
# This is a secondary stream.
707+
rpiCameraSecondary: true
708+
# Width of frames.
709+
rpiCameraWidth: 640
710+
# Height of frames.
711+
rpiCameraHeight: 480
712+
# FPS.
713+
rpiCameraFPS: 10
714+
# Codec. in case of secondary streams, it defaults to M-JPEG.
715+
rpiCameraCodec: auto
716+
# JPEG quality.
717+
rpiCameraJPEGQuality: 60
718+
```
719+
720+
The secondary stream is available in path `/secondary`.
682721

683722
### By protocol
684723

@@ -690,7 +729,7 @@ SRT is a protocol that allows to publish and read live data stream, providing en
690729
srt://localhost:8890?streamid=publish:mystream&pkt_size=1316
691730
```
692731

693-
Replace `mystream` with any name you want. The resulting stream will be available in path `/mystream`.
732+
Replace `mystream` with any name you want. The resulting stream is available in path `/mystream`.
694733

695734
If credentials are enabled, append username and password to `streamid`:
696735

@@ -723,7 +762,7 @@ WebRTC is an API that makes use of a set of protocols and methods to connect two
723762
http://localhost:8889/mystream/publish
724763
```
725764

726-
The resulting stream will be available in path `/mystream`.
765+
The resulting stream is available in path `/mystream`.
727766

728767
WHIP is a WebRTC extensions that allows to publish streams by using a URL, without passing through a web page. This allows to use WebRTC as a general purpose streaming protocol. If you are using a software that supports WHIP (for instance, latest versions of OBS Studio), you can publish a stream to the server by using this URL:
729768

@@ -756,7 +795,7 @@ RTSP is a protocol that allows to publish and read streams. It supports differen
756795
rtsp://localhost:8554/mystream
757796
```
758797
759-
The resulting stream will be available in path `/mystream`.
798+
The resulting stream is available in path `/mystream`.
760799
761800
Known clients that can publish with RTSP are [FFmpeg](#ffmpeg), [GStreamer](#gstreamer), [OBS Studio](#obs-studio).
762801
@@ -771,7 +810,7 @@ paths:
771810
source: rtsp://original-url
772811
```
773812

774-
The resulting stream will be available in path `/proxied`.
813+
The resulting stream is available in path `/proxied`.
775814

776815
The server supports any number of source streams (count is just limited by available hardware resources) it's enough to add additional entries to the paths section:
777816

@@ -792,7 +831,7 @@ RTMP is a protocol that allows to read and publish streams, but is less versatil
792831
rtmp://localhost/mystream
793832
```
794833

795-
The resulting stream will be available in path `/mystream`.
834+
The resulting stream is available in path `/mystream`.
796835

797836
In case authentication is enabled, credentials can be passed to the server by using the `user` and `pass` query parameters:
798837

@@ -813,7 +852,7 @@ paths:
813852
source: rtmp://original-url
814853
```
815854
816-
The resulting stream will be available in path `/proxied`.
855+
The resulting stream is available in path `/proxied`.
817856

818857
#### HLS cameras and servers
819858

@@ -826,7 +865,7 @@ paths:
826865
source: http://original-url/stream/index.m3u8
827866
```
828867

829-
The resulting stream will be available in path `/proxied`.
868+
The resulting stream is available in path `/proxied`.
830869

831870
#### UDP/MPEG-TS
832871

@@ -854,7 +893,7 @@ paths:
854893
source: udp://238.0.0.1:1234
855894
```
856895

857-
The resulting stream will be available in path `/mypath`.
896+
The resulting stream is available in path `/mypath`.
858897

859898
Known clients that can publish with WebRTC and WHIP are [FFmpeg](#ffmpeg) and [GStreamer](#gstreamer).
860899

apidocs/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ components:
364364
# Raspberry Pi Camera source
365365
rpiCameraCamID:
366366
type: integer
367+
rpiCameraSecondary:
368+
type: boolean
367369
rpiCameraWidth:
368370
type: integer
369371
rpiCameraHeight:
@@ -436,6 +438,8 @@ components:
436438
type: string
437439
rpiCameraLevel:
438440
type: string
441+
rpiCameraJPEGQuality:
442+
type: integer
439443

440444
# Hooks
441445
runOnInit:

internal/conf/conf_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func TestConfFromFile(t *testing.T) {
7878
RPICameraBitrate: 5000000,
7979
RPICameraProfile: "main",
8080
RPICameraLevel: "4.1",
81+
RPICameraJPEGQuality: 60,
8182
RunOnDemandStartTimeout: 5 * Duration(time.Second),
8283
RunOnDemandCloseAfter: 10 * Duration(time.Second),
8384
}, pa)

0 commit comments

Comments
 (0)