0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ffmpegを使ってRTP送受信+V4L2経由で仮想デバイス化

Posted at

ffmpegを使ってUSBカメラの映像をRTPで送信し、受け側ではV4L2経由で仮想デバイス化(USBカメラが付いているようにふるまう)する方法です。

1.RTPで映像送信する

1.1.必要ソフトウェアの準備

Ubuntu環境で下記をインストールします。

sudo apt update sudo apt install ffmpeg v4l-utils

v4l2をインストールすると、v4l2-ctl --list-devicesコマンドで、接続されたUSBカメラを確認することができます。

1.2.カメラ映像のRTP送信

ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -i /dev/video0 \ -c:v libx264 -preset ultrafast -tune zerolatency -f rtp \ rtp://<DC_IP>:5004
  • <DC_IP>:受信サーバIP
  • -f rtp:RTP形式での出力
  • rtp:// : UDP上のRTP送信。デフォルトでポート5004を使用

2.RTPで映像受信しV4L2経由で仮想デバイス化

2.1.v4l2loopback のインストール(仮想V4L2カメラ作成)

sudo apt update sudo apt install v4l2loopback-dkms

インストール後、仮想デバイスを作成します。

sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="VirtualCam" exclusive_caps=1

上記コマンドの場合、/dev/video10 に仮想カメラができます(video_nr=10

2.2.GStreamer のインストール

sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

2.3.GStreamer パイプラインの例(RTP受信 → 仮想カメラ出力)

H.264形式のRTPを受信して仮想カメラに出力する例を示します。

gst-launch-1.0 -v udpsrc port=5004 caps="application/x-rtp, encoding-name=H264, payload=96" ! \
rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! \
video/x-raw,format=YUY2 ! v4l2sink device=/dev/video10

適切なバッファリングが出来てない場合は、こちらを試してみてください。

gst-launch-1.0 -v udpsrc port=5004 caps="application/x-rtp, encoding-name=H264, payload=96" ! \
queue ! rtph264depay ! queue ! h264parse ! queue ! avdec_h264 ! \
queue ! videoconvert ! queue ! video/x-raw,format=YUY2 ! v4l2sink device=/dev/video10

私の場合、v4l2sinkでは、うまくいかなかったので、fpsdisplaysinkでデコード状態を出力するようにしたら、いけました。

2.4.Cheese などで確認

cheese

設定メニューなどで VirtualCam(/dev/video10) を選べば、RTPで受信した映像が表示されるはずです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?