From f79c4783c7ba4067deecf19ae8a8ea4d37bbf63f Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Wed, 21 Jun 2023 16:08:37 +0200 Subject: [PATCH] rename environment variable RTSP_PATH into MTX_PATH (#1967) --- README.md | 10 +++++----- internal/conf/conf_test.go | 8 ++++---- internal/core/core_test.go | 2 +- internal/core/path.go | 3 ++- internal/core/rtmp_conn.go | 3 ++- internal/core/rtsp_conn.go | 3 ++- mediamtx.yml | 18 +++++++++--------- scripts/run.mk | 4 ++-- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index bcf67a08..0bc99395 100644 --- a/README.md +++ b/README.md @@ -408,7 +408,7 @@ To change the format, codec or compression of a stream, use _FFmpeg_ or _GStream paths: all: original: - runOnReady: ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 600k -max_muxing_queue_size 1024 -f rtsp rtsp://localhost:$RTSP_PORT/compressed + runOnReady: ffmpeg -i rtsp://localhost:$RTSP_PORT/$MTX_PATH -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 600k -max_muxing_queue_size 1024 -f rtsp rtsp://localhost:$RTSP_PORT/compressed runOnReadyRestart: yes ``` @@ -419,7 +419,7 @@ To save available streams to disk, you can use the `runOnReady` parameter and _F ```yml paths: mypath: - runOnReady: ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -c copy -f segment -strftime 1 -segment_time 60 -segment_format mpegts saved_%Y-%m-%d_%H-%M-%S.ts + runOnReady: ffmpeg -i rtsp://localhost:$RTSP_PORT/$MTX_PATH -c copy -f segment -strftime 1 -segment_time 60 -segment_format mpegts saved_%Y-%m-%d_%H-%M-%S.ts runOnReadyRestart: yes ``` @@ -432,7 +432,7 @@ Edit `mediamtx.yml` and replace everything inside section `paths` with the follo ```yml paths: ondemand: - runOnDemand: ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH + runOnDemand: ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH runOnDemandRestart: yes ``` @@ -623,7 +623,7 @@ To publish the video stream of a generic webcam to the server, edit `mediamtx.ym ```yml paths: cam: - runOnInit: ffmpeg -f v4l2 -i /dev/video0 -pix_fmt yuv420p -preset ultrafast -b:v 600k -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH + runOnInit: ffmpeg -f v4l2 -i /dev/video0 -pix_fmt yuv420p -preset ultrafast -b:v 600k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH runOnInitRestart: yes ``` @@ -632,7 +632,7 @@ If the platform is Windows: ```yml paths: cam: - runOnInit: ffmpeg -f dshow -i video="USB2.0 HD UVC WebCam" -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 600k -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH + runOnInit: ffmpeg -f dshow -i video="USB2.0 HD UVC WebCam" -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 600k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH runOnInitRestart: yes ``` diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index ee91db06..a9e53829 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -98,8 +98,8 @@ func TestConfFromFile(t *testing.T) { } func TestConfFromFileAndEnv(t *testing.T) { - os.Setenv("RTSP_PATHS_CAM1_SOURCE", "rtsp://testing") - defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCE") + os.Setenv("MTX_PATHS_CAM1_SOURCE", "rtsp://testing") + defer os.Unsetenv("MTX_PATHS_CAM1_SOURCE") os.Setenv("RTSP_PROTOCOLS", "tcp") defer os.Unsetenv("RTSP_PROTOCOLS") @@ -137,8 +137,8 @@ func TestConfFromFileAndEnv(t *testing.T) { } func TestConfFromEnvOnly(t *testing.T) { - os.Setenv("RTSP_PATHS_CAM1_SOURCE", "rtsp://testing") - defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCE") + os.Setenv("MTX_PATHS_CAM1_SOURCE", "rtsp://testing") + defer os.Unsetenv("MTX_PATHS_CAM1_SOURCE") conf, hasFile, err := Load("mediamtx.yml") require.NoError(t, err) diff --git a/internal/core/core_test.go b/internal/core/core_test.go index 7ec6b8a2..4de265d6 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -207,7 +207,7 @@ func main() { source := gortsplib.Client{} err := source.StartRecording( - "rtsp://localhost:" + os.Getenv("RTSP_PORT") + "/" + os.Getenv("RTSP_PATH"), + "rtsp://localhost:" + os.Getenv("RTSP_PORT") + "/" + os.Getenv("MTX_PATH"), media.Medias{medi}) if err != nil { panic(err) diff --git a/internal/core/path.go b/internal/core/path.go index 6e21e576..718bda81 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -541,7 +541,8 @@ func (pa *path) shouldClose() bool { func (pa *path) externalCmdEnv() externalcmd.Environment { _, port, _ := net.SplitHostPort(pa.rtspAddress) env := externalcmd.Environment{ - "RTSP_PATH": pa.name, + "MTX_PATH": pa.name, + "RTSP_PATH": pa.name, // deprecated "RTSP_PORT": port, } diff --git a/internal/core/rtmp_conn.go b/internal/core/rtmp_conn.go index bf7e9056..2cfaf4a7 100644 --- a/internal/core/rtmp_conn.go +++ b/internal/core/rtmp_conn.go @@ -296,7 +296,8 @@ func (c *rtmpConn) run() { c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ - "RTSP_PATH": "", + "MTX_PATH": "", + "RTSP_PATH": "", // deprecated "RTSP_PORT": port, }, func(err error) { diff --git a/internal/core/rtsp_conn.go b/internal/core/rtsp_conn.go index 71cd1c63..da59c41c 100644 --- a/internal/core/rtsp_conn.go +++ b/internal/core/rtsp_conn.go @@ -77,7 +77,8 @@ func newRTSPConn( c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ - "RTSP_PATH": "", + "MTX_PATH": "", + "RTSP_PATH": "", // deprecated "RTSP_PORT": port, }, func(err error) { diff --git a/mediamtx.yml b/mediamtx.yml index 04b308d7..635d807b 100644 --- a/mediamtx.yml +++ b/mediamtx.yml @@ -56,7 +56,7 @@ pprofAddress: 127.0.0.1:9999 # Prepend ./ to run an executable in the current folder (example: "./ffmpeg") # This is terminated with SIGINT when a client disconnects from the server. # The following environment variables are available: -# * RTSP_PORT: server port +# * RTSP_PORT: RTSP server port runOnConnect: # Restart the command if it exits. runOnConnectRestart: no @@ -410,8 +410,8 @@ paths: # Prepend ./ to run an executable in the current folder (example: "./ffmpeg") # This is terminated with SIGINT when the program closes. # The following environment variables are available: - # * RTSP_PATH: path name - # * RTSP_PORT: server port + # * MTX_PATH: path name + # * RTSP_PORT: RTSP server port # * G1, G2, ...: regular expression groups, if path name is # a regular expression. runOnInit: @@ -423,8 +423,8 @@ paths: # Prepend ./ to run an executable in the current folder (example: "./ffmpeg") # This is terminated with SIGINT when the path is not requested anymore. # The following environment variables are available: - # * RTSP_PATH: path name - # * RTSP_PORT: server port + # * MTX_PATH: path name + # * RTSP_PORT: RTSP server port # * G1, G2, ...: regular expression groups, if path name is # a regular expression. runOnDemand: @@ -442,8 +442,8 @@ paths: # Prepend ./ to run an executable in the current folder (example: "./ffmpeg") # This is terminated with SIGINT when the stream is not ready anymore. # The following environment variables are available: - # * RTSP_PATH: path name - # * RTSP_PORT: server port + # * MTX_PATH: path name + # * RTSP_PORT: RTSP server port # * G1, G2, ...: regular expression groups, if path name is # a regular expression. runOnReady: @@ -454,8 +454,8 @@ paths: # Prepend ./ to run an executable in the current folder (example: "./ffmpeg") # This is terminated with SIGINT when a client stops reading. # The following environment variables are available: - # * RTSP_PATH: path name - # * RTSP_PORT: server port + # * MTX_PATH: path name + # * RTSP_PORT: RTSP server port # * G1, G2, ...: regular expression groups, if path name is # a regular expression. runOnRead: diff --git a/scripts/run.mk b/scripts/run.mk index 73b6d87a..87609114 100644 --- a/scripts/run.mk +++ b/scripts/run.mk @@ -21,10 +21,10 @@ define CONFIG_RUN paths: all: -# runOnReady: ffmpeg -i rtsp://localhost:$$RTSP_PORT/$$RTSP_PATH -c copy -f mpegts myfile_$$RTSP_PATH.ts +# runOnReady: ffmpeg -i rtsp://localhost:$$RTSP_PORT/$$MTX_PATH -c copy -f mpegts myfile_$$MTX_PATH.ts # readUser: test # readPass: tast -# runOnDemand: ffmpeg -re -stream_loop -1 -i testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$$RTSP_PORT/$$RTSP_PATH +# runOnDemand: ffmpeg -re -stream_loop -1 -i testimages/ffmpeg/emptyvideo.mkv -c copy -f rtsp rtsp://localhost:$$RTSP_PORT/$$MTX_PATH # proxied: # source: rtsp://192.168.2.198:554/stream