2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rtsp の使い方

Last updated at Posted at 2022-08-16

gstreamer で動画を送信し、mpv で受信する方法です。
次のページを参考にしました。
GStreamerを使用したRTSPサーバを構築し、Macから動画を送信してみました。

送信サーバー

必要なライブラリーのインストール

sudo apt install automake
sudo apt install autopoint
sudo apt install libtool
sudo apt install gtk-doc-tools
sudo apt install libglib2.0-dev
sudo apt install gstreamer1.0-plugins-base gstreamer1.0-tools
sudo apt install libgstreamer1.0-dev
sudo apt install libgstreamer-plugins-base1.0-dev

ソースのダウンロードとコンパイル

git clone git://anongit.freedesktop.org/gstreamer/gst-rtsp-server
cd gst-rtsp-server
git checkout 1.4
./autogen.sh
make
sudo make install

mp4 の送信

cd examples
./test-mp4 /tmp/sample-5s.mp4
$ ./test-mp4 /tmp/sample-5s.mp4 
stream ready at rtsp://127.0.0.1:8554/test

mpv で受信

mpv rtsp://localhost:8554/test

ffplay で受信

ffplay rtsp://127.0.0.1:8554/test

python3-opencv で受信

ライブラリーのインストール

sudo apt install python3-opencv
camera.py
#! /usr/bin/python
#
#	camera.py
#
#					Aug/16/2022
# ------------------------------------------------------------------
import sys
import cv2
#
# ------------------------------------------------------------------
sys.stderr.write("*** start ***\n")
url = 'rtsp://127.0.0.1:8554/test'
cap_file = cv2.VideoCapture(url)
print(type(cap_file))
print(cap_file.isOpened())
width = cap_file.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap_file.get(cv2.CAP_PROP_FRAME_HEIGHT)
print(height,width)

while True:
	ret, frame = cap_file.read()
	if ret:
		cv2.imshow('frame',frame)
		if cv2.waitKey(1) & 0xFF == ord('q'):
			break
	else:
		break

cap_file.release()
cv2.destroyAllWindows()
#
sys.stderr.write("*** end ***\n")
# ------------------------------------------------------------------

実行結果

$ ./camera.py 
*** start ***
<class 'cv2.VideoCapture'>
True
1080.0 1920.0
*** end ***
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?