こぼれネット

WIndows10のWSL Ubuntu-20.04に仮想の/dev/video*を作って、Webカメラ C270n をGstreamer で表示できるようにするまでの軌跡

まず、WIndows10のWSL Ubuntu-20.04 を WSL2にしなければなりません。

WSLのバージョンが"1"だったので"2"に変えようとしたら、ちょっと酷い目にあった件

でもって、さらに、このWSL2に usbのデバイスを使えるようにしなければなりません。

再度、『wsl で USBのWebカメラを使う』に挑戦中

でもって、Gstreamの環境がインストールされていることが前提です。

Windows10のWSLでX11アプリケーションを実行してみた + GStreamerを試してみた

と、ターゲットのカメラはこれ

Webカメラ C270n HD 720P

=====  手続の備忘録 ======

Step 1: powershellを管理者モードで立ち上げて、"
usbipd server"投入

Step 2: コマンドプロンプトから、"C:\Users\ebata>wsl -d Ubuntu-20.04"を投入

Step 3: 別のpowershellを管理者モードで立ち上げて、"
usbipd wsl attach --distribution Ubuntu-20.04 --busid 8-3"を投入

Step 4: コマンドプロンプトから、"C:\Users\ebata>sudo chmod 777 /dev/video*"を投入

これらを乗り超えて、ようやく、Gstreamer で、Webカメラの映像をループバックで表示しようとしたのですが、これが全く分からなくて、色々試しました。やけくそのトアイアンドエラー

gst-launch-1.0 videotestsrc ! videoconvert ! x264enc tune=zerolatency key-int-max=30 ! mpegtsmux ! srtserversink uri="srt://:12345" latency=500
(成功)

gst-launch-1.0 v4l2src device="/dev/video0" ! 'video/x-raw, width=640, height=480, framerate=30/1' ! videoconvert ! nv3dsink (失敗)

gst-launch-1.0 videotestsrc ! videoconvert ! video/x-raw,width=1280,height=720,framerate=30/1 ! autovideosink

gst-launch-1.0 -e filesrc location=start_up.mp4 ! videoconvert ! x264enc tune=zerolatency key-int-max=30 ! mpegtsmux ! srtserversink uri="srt://:12345" latency=500
(失敗)

gst-launch-1.0 filesrc location=start_up.mp4 ! decodebin ! videorate ! video/x-raw,framerate=30/1 ! autovideosink
(動く)

gst-launch-1.0 filesrc location=start_up.mp4 ! decodebin ! videorate ! video/x-raw,framerate=30/1 ! srtserversink uri="srt://:12345" latency=500(動く)

gst-launch-1.0 v4l2src ! videoconvert ! ximagesink (動くが、大きなブラック画面がでてきただけ)

gst-launch-1.0 v4l2src device="/dev/video0" ! videoconvert ! ximagesink

gst-launch-1.0 v4l2src device="/dev/video0" ! 'video/x-raw, width=640, height=480, framerate=30/1' ! videoconvert ! nv3dsink

gst-launch-1.0 v4l2src device="/dev/video0" ! 'video/x-raw, width=640, height=480, framerate=30/1' ! videoconvert ! ximagesink
(これは黒い画面が表示される)

gst-launch-1.0 filesrc location=start_up.mp4 ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! srtserversink uri="srt://:12345" latency=500
(失敗)
00:40:58.339192/multiqueue0:src*E:SRT.c: LiveCC: payload size: 506880 exceeds maximum allowed 1316
00:40:59.339081/multiqueue0:src*E:SRT.c: LiveCC: payload size: 506880 exceeds maximum allowed 1316
00:41:00.339101/multiqueue0:src*E:SRT.c: LiveCC: payload size: 506880 exceeds maximum allowed 1316
00:41:01.339057/multiqueue0:src*E:SRT.c: LiveCC: payload size: 506880 exceeds maximum allowed 1316

gst-launch-1.0 filesrc location=start_up.mp4 ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! autovideosink
(成功)

gst-launch-1.0 filesrc location=start_up.mp4 ! videoconvert ! x264enc tune=zerolatency key-int-max=30 ! mpegtsmux ! srtserversink uri="srt://:12345" latency=500
(失敗)

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, height=480, width=640 ! videoconvert ! x264enc tune=zerolatency ! video/x-h264, profile=high ! mpegtsmux ! srtserversink uri=srt://:12345/
(エラーは出ていないが表示もされない)
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Redistribute latency...
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:01:50.658920768
Setting pipeline to NULL ...
Freeing pipeline ...

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, height=480, width=640 ! videoconvert ! x264enc tune=zerolatency key-int-max=30 ! mpegtsmux ! srtserversink uri="srt://:12345" latency=500
(失敗)

gst-launch-1.0 -v filesrc location=start_up.mp4 ! qtdemux ! queue ! h264parse ! avdec_h264 ! video/x-raw, height=1080, width=1920 ! videoconvert ! x264enc tune=zerolatency ! video/x-h264, profile=high ! mpegtsmux ! srtsink uri=srt://:12345/
(失敗)

gst-launch-1.0 filesrc location=start_up.mp4 ! qtdemux ! h264parse ! rtph264pay ! udpsink host=127.0.0.1 port=5000
(失敗)

gst-launch-1.0 filesrc location=30ftp.mp4 ! qtdemux ! h264parse ! rtph264pay ! srtsink uri=srt://:12345
(失敗)

gst-launch-1.0 filesrc location=30ftp.mp4 ! qtdemux ! h264parse ! identity drop-probability=1 ! rtph264pay ! srtsink uri=srt://:12345

gst-launch-1.0 v4l2src ! video/x-raw,width=640,height=480 ! autovideosink

gst-launch-1.0 v4l2src device="/dev/video0" ! 'image/jpeg, width=1280, height=720, framerate=30/1' ! jpegdec ! nv3dsink

gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,format=(string)YUYV,width=640,height=480,framerate=30/1' ! autovideosink

gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! videoconvert ! autovideosink

ChatGPTが示してきた答え
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,format=(string)YUY2,width=640,height=480,framerate=30/1' ! autovideosink

でも、これでもエラーはでてこないが、動かない。

C270nのWebカメラ映像をGstreamerで録画したい
(ChatGPTが示してきた答え)
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,format=(string)YUY2,width=640,height=480,framerate=30/1' ! videoconvert ! x264enc ! mp4mux ! filesink location=output.mp4

で、ようやく動いたのが、これ

gst-launch-1.0 v4l2src device="/dev/video0" ! 'image/jpeg, width=1280, height=720, framerate=30/1' ! jpegdec ! autovideosink

ちょっと画面が大きいので、今、表示しているのは、以下のコマンドで少し小さくして表示

ebata@DESKTOP-P6KREM0:/mnt/c/Users/ebata/Gstreamer$ gst-launch-1.0 v4l2src device="/dev/video0" ! 'image/jpeg, width=640, height=480, framerate=30/1' ! jpegdec ! autovideosink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'autovideosink0': gst.gl.GLDisplay=context, gst.gl.GLDisplay=(GstGLDisplay)"\(GstGLDisplayX11\)\ gldisplayx11-0";
Setting pipeline to PLAYING ...
New clock: GstSystemClock
WARNING: from element /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstGLImageSinkBin:autovideosink0-actual-sink-glimage/GstGLImageSink:sink: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(3003): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstGLImageSinkBin:autovideosink0-actual-sink-glimage/GstGLImageSink:sink:
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstGLImageSinkBin:autovideosink0-actual-sink-glimage/GstGLImageSink:sink: A lot of buffers are being dropped.
Additional debug info:
gstbasesink.c(3003): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstGLImageSinkBin:autovideosink0-actual-sink-glimage/GstGLImageSink:sink:
There may be a timestamping problem, or this computer is too slow

表示されたのはいいけど、警告が凄い

ちなみに、SRTの通信にも成功してVLCで表示できました(遅延が凄いけど(2~3秒))。

gst-launch-1.0 v4l2src device="/dev/video0" ! 'image/jpeg, width=640, height=480, framerate=30/1' ! jpegdec ! videoconvert ! x264enc tune=zerolatency key-int-max=30 ! mpegtsmux ! srtserversink uri="srt://:12345" latency=500

コマンドをかたっぱしからくっつけたでけです。

モバイルバージョンを終了