Study: ComputerScience(CS)/CS: Network

[Network] RTSP ์„œ๋ฒ„ ํด๋ผ์ด์–ธํŠธ ๊ตฌ์ถ•ํ•˜๊ธฐ(feat. rtsp-simple-server, mediamtx)

DrawingProcess 2023. 4. 27. 10:41
๋ฐ˜์‘ํ˜•
๐Ÿ’ก ๋ณธ ๋ฌธ์„œ๋Š” 'RTSP ์„œ๋ฒ„ ํด๋ผ์ด์–ธํŠธ ๊ตฌ์ถ•ํ•˜๊ธฐ(feat. rtsp-simple-server)'์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋†“์€ ๊ธ€์ž…๋‹ˆ๋‹ค.
๊ฐ„๋‹จํ•œ RTSP ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•˜์—ฌ ํŠน์ • ์˜์ƒ์„ streamํ•˜๊ณ  ์ด๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ํด๋ผ์ด์–ธํŠธ๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜์˜€์œผ๋‹ˆ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

1.  Installation

1.1. Download FFmpeg:

% brew install ffmpeg

1.2. Download VLC(VLC Media Player):

% brew install --cask vlc

Error: It seems there is already an App at '/Applications/VLC.app'.

% nano ~/.bashrc
...
alias vlc='/Applications/VLC.app/Contents/MacOS/VLC'

% source ~/.bashrc

2. basic usage

2.1. Download and launch the image:

$ docker run --rm -it --network=host aler9/rtsp-simple-server
2023/04/25 12:24:35 INF MediaMTX / rtsp-simple-server v0.22.2
2023/04/25 12:24:35 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2023/04/25 12:24:35 INF [RTMP] listener opened on :1935
2023/04/25 12:24:35 INF [HLS] listener opened on :8888
2023/04/25 12:24:35 INF [WebRTC] listener opened on :8889 (HTTP)

2.2. Publish a stream. For instance, you can publish a video file with FFmpeg:

% ffmpeg -re -stream_loop -1 -i file.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream
ffmpeg version 2.8.17-0ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --build-suffix=-ffmpeg --toolchain=hardened
 ...

2.3. Open the stream. For instance, you can open the stream with VLC:

# vlc
% vlc rtsp://localhost:8554/mystream

# GStreamer
% gst-launch-1.0 rtspsrc location=rtsp://localhost:8554/mystream name=s s. ! application/x-rtp,media=video ! decodebin ! autovideosink s. ! application/x-rtp,media=audio ! decodebin ! audioconvert ! audioresample ! autoaudiosink

# ffplay
% ffplay rtsp://localhost:8554/mystream

# FFmpeg
% ffmpeg -i rtsp://localhost:8554/mystream -c copy output.mp4

+ ์ถ”๊ฐ€

[Blog] VLC Media Player(GUI)๋ฅผ ์ด์šฉํ•œ RTSP ์„œ๋ฒ„ ํด๋ผ์ด์–ธํŠธ ๊ตฌ์ถ•

Video Player๋กœ ์ข…์ข… ์‚ฌ์šฉํ•˜๋Š” VLC์—์„œ ์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ์ธ RTSP ์ŠคํŠธ๋ฆฌ๋ฐ์„ ์ด์šฉํ•˜์—ฌ RTSP ํด๋ผ์ด์–ธํŠธ ๋ฐ ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

[Blog] ์›น์—์„œ IP ์นด๋ฉ”๋ผ ์ŠคํŠธ๋ฆฌ๋ฐ ํ•˜๊ธฐ

์›น์ƒ์— ์นด๋ฉ”๋ผ๋ฅผ ์ŠคํŠธ๋ฆฌ๋ฐํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ๋Ÿฌ ํ”„๋กœํ† ์ฝœ์„ ์ ์šฉํ•ด๋ณด๋Š” ์‹œํ–‰์ฐฉ์˜ค ๊ณผ์ •์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋†“์€ ๋ฌธ์„œ๋กœ, ๊ฒฐ๋ก ์€ 'FFMPEG๋กœ RTSP๋ฅผ HLS๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์›น์ƒ์— ๋ฐฐํฌ' ์ž…๋‹ˆ๋‹ค.

[Blog] Browser RTSP, RTMP, HLS CCTV streaming ์ด์Šˆ ์ •๋ฆฌ

์นด๋ฉ”๋ผ ์˜์ƒ์„ RTSP๋กœ ํ‘œ์ถœํ•˜๋Š” ์ด์œ , RTSP๊ฐ€ ์›น์—์„œ ํ‘œ์ถœํ•  ์ˆ˜ ์—†๋Š” ์ด์œ  ๋“ฑ ๋‹ค์–‘ํ•œ ์ด์Šˆ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋‘” ๋ฌธ์„œ์ž…๋‹ˆ๋‹ค.

  1. ๋ณดํ†ต ์‹ค์‹œ๊ฐ„ ์˜์ƒ์€ RTSP ํ”„๋กœํ† ์ฝœ๋กœ ์ œ๊ณต๋˜๋ฉฐ VLC Player๋กœ ํ‘œ์ถœ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  2. ์ด๋ฅผ ๋ธŒ๋ผ์šฐ์ €์—์„œ ํ‘œ์ถœํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด RTSP ํ”„๋กœํ† ์ฝœ์„ HLS ํ”„๋กœํ† ์ฝœ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋ฉฐ,
  3. HLS ํ”„๋กœํ† ์ฝœ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ž‘์—…์ด ์–ด๋ ค์šธ ๊ฒฝ์šฐ, WOWZA ์™€ ๊ฐ™์€ ๋ฐ›์€ ์˜์ƒ์„ ์—ฌ๋Ÿฌ ํ”„๋กœํ† ์ฝœ๋กœ ๋ณ€ํ™˜(RTMP, HLS ๋“ฑ) ํ•ด์ฃผ๋Š” ์ŠคํŠธ๋ฆฌ๋ฐ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. (์œ ๋ฃŒ)
  4. ๋˜๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ FFmpeg ๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์—ฐ๊ฒฐ๋œ RTSP ํ”„๋กœํ† ์ฝœ ์˜์ƒ์„ ์„ค์ •๋œ ์‹œ๊ฐ„(์ดˆ), ํŒŒ์ผ ๊ฐœ์ˆ˜๋งŒํผ .ts ํŒŒ์ผ(์˜์ƒํŒŒ์ผ)๋กœ ๋งŒ๋“ค์–ด ํ•ด๋‹น ํŒŒ์ผ์„ stream ํŒŒ์ผ๋กœ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ 

๋ฐ˜์‘ํ˜•