ihrapsa / KlipperWrt

A guide to install Klipper with fluidd, Mainsail or Duet-Web-Control and webcam stream in OpenWrt. Mainly created around the Creality Wi-Fi box but any OpenWrt running device with similar specs will work just fine.
180 stars 39 forks source link

Webcam is not working with mjpg-streamer #41

Closed kgsrirama closed 1 year ago

kgsrirama commented 1 year ago

Hi,

I installed openwrt on the Creality web box and was able to successfully able to run klipper and do prints. I was trying to install mjpg-steamer and webcam, but all methods failed. BTW, I am able to use ffmpeg to record video and download it and also run mjpg-streamer in command line and able to see the stream.

lsusb -v

Bus 001 Device 004: ID 13d3:784b FLH-BY-0309-200514 Integrated Camera Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 239 bDeviceSubClass 2 bDeviceProtocol 1 bMaxPacketSize0 64 idVendor 0x13d3 idProduct 0x784b bcdDevice 5.14 iManufacturer 1 FLH-BY-0309-200514 iProduct 2 Integrated Camera iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x01e2 bNumInterfaces 2 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 500mA Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 0 bInterfaceCount 2 bFunctionClass 14 bFunctionSubClass 3 bFunctionProtocol 0 iFunction 4 Integrated Camera Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 1 bInterfaceProtocol 0 iInterface 4 Integrated Camera VideoControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 1 (HEADER) bcdUVC 1.00 wTotalLength 0x006d dwClockFrequency 48.000000MHz bInCollection 1 baInterfaceNr( 0) 1 VideoControl Interface Descriptor: bLength 18 bDescriptorType 36 bDescriptorSubtype 2 (INPUT_TERMINAL) bTerminalID 1 wTerminalType 0x0201 Camera Sensor bAssocTerminal 0 iTerminal 0 wObjectiveFocalLengthMin 0 wObjectiveFocalLengthMax 0 wOcularFocalLength 0 bControlSize 3 bmControls 0x0000000e Auto-Exposure Mode Auto-Exposure Priority Exposure Time (Absolute) VideoControl Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 5 (PROCESSING_UNIT) Warning: Descriptor too short bUnitID 2 bSourceID 1 wMaxMultiplier 16384 bControlSize 2 bmControls 0x0000177f Brightness Contrast Hue Saturation Sharpness Gamma White Balance Temperature Backlight Compensation Gain Power Line Frequency White Balance Temperature, Auto iProcessing 0 bmVideoStandards 0x1d None PAL - 625/50 SECAM - 625/50 NTSC - 625/50 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 3 guidExtensionCode {0fb885c3-68c2-4547-90f7-8f47579d95fc} bNumControls 5 bNrInPins 1 baSourceID( 0) 2 bControlSize 4 bmControls( 0) 0x1f bmControls( 1) 0x00 bmControls( 2) 0x00 bmControls( 3) 0x00 iExtension 0 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 4 guidExtensionCode {63610682-5070-49ab-b8cc-b3855e8d221d} bNumControls 20 bNrInPins 1 baSourceID( 0) 3 bControlSize 4 bmControls( 0) 0xff bmControls( 1) 0xff bmControls( 2) 0x71 bmControls( 3) 0x00 iExtension 0 VideoControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 3 (OUTPUT_TERMINAL) bTerminalID 5 wTerminalType 0x0101 USB Streaming bAssocTerminal 0 bSourceID 4 iTerminal 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x87 EP 7 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 8 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 VideoStreaming Interface Descriptor: bLength 15 bDescriptorType 36 bDescriptorSubtype 1 (INPUT_HEADER) bNumFormats 2 wTotalLength 0x0096 bEndpointAddress 0x81 EP 1 IN bmInfo 0 bTerminalLink 5 bStillCaptureMethod 2 bTriggerSupport 1 bTriggerUsage 0 bControlSize 1 bmaControls( 0) 4 bmaControls( 1) 0 VideoStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 6 (FORMAT_MJPEG) bFormatIndex 1 bNumFrameDescriptors 1 bFlags 1 Fixed-size samples: Yes bDefaultFrameIndex 1 bAspectRatioX 0 bAspectRatioY 0 bmInterlaceFlags 0x00 Interlaced stream or variable: No Fields per frame: 1 fields Field 1 first: No Field pattern: Field 1 only bCopyProtect 0 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 1 bmCapabilities 0x01 Still image supported wWidth 640 wHeight 480 dwMinBitRate 147456000 dwMaxBitRate 147456000 dwMaxVideoFrameBufferSize 614400 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 14 bDescriptorType 36 bDescriptorSubtype 3 (STILL_IMAGE_FRAME) bEndpointAddress 0x00 EP 0 OUT bNumImageSizePatterns 1 wWidth( 0) 640 wHeight( 0) 480 bNumCompressionPatterns 4 bCompression( 0) 1 bCompression( 1) 5 bCompression( 2) 10 bCompression( 3) 20 VideoStreaming Interface Descriptor: bLength 6 bDescriptorType 36 bDescriptorSubtype 13 (COLORFORMAT) bColorPrimaries 1 (BT.709,sRGB) bTransferCharacteristics 1 (BT.709) bMatrixCoefficients 4 (SMPTE 170M (BT.601)) VideoStreaming Interface Descriptor: bLength 27 bDescriptorType 36 bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED) bFormatIndex 2 bNumFrameDescriptors 1 guidFormat {32595559-0000-0010-8000-00aa00389b71} bBitsPerPixel 16 bDefaultFrameIndex 1 bAspectRatioX 0 bAspectRatioY 0 bmInterlaceFlags 0x00 Interlaced stream or variable: No Fields per frame: 2 fields Field 1 first: No Field pattern: Field 1 only bCopyProtect 0 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 5 (FRAME_UNCOMPRESSED) bFrameIndex 1 bmCapabilities 0x00 Still image unsupported wWidth 640 wHeight 480 dwMinBitRate 147456000 dwMaxBitRate 147456000 dwMaxVideoFrameBufferSize 614400 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 3 (STILL_IMAGE_FRAME) bEndpointAddress 0x00 EP 0 OUT bNumImageSizePatterns 1 wWidth( 0) 640 wHeight( 0) 480 bNumCompressionPatterns 1 bCompression( 0) 1 VideoStreaming Interface Descriptor: bLength 6 bDescriptorType 36 bDescriptorSubtype 13 (COLORFORMAT) bColorPrimaries 1 (BT.709,sRGB) bTransferCharacteristics 1 (BT.709) bMatrixCoefficients 4 (SMPTE 170M (BT.601)) Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 1 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x00c0 1x 192 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 2 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0180 1x 384 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 3 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 4 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0280 1x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 5 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0320 1x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 6 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x03b0 1x 944 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 7 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0a80 2x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 8 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0b20 2x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 9 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0be0 2x 992 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 10 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x13c0 3x 960 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 11 bNumEndpoints 1 bInterfaceClass 14 bInterfaceSubClass 2 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x13fc 3x 1020 bytes bInterval 1 Binary Object Store Descriptor: bLength 5 bDescriptorType 15 wTotalLength 0x0019 bNumDeviceCaps 1 Container ID Device Capability: bLength 20 bDescriptorType 16 bDevCapabilityType 4 bReserved 0 ContainerID {20b69f2c-34b3-4690-a228-67bd251277e9} Device Status: 0x0000 (Bus Powered)

running v4l2-ctl --list-devices

Integrated Camera: Integrated C (usb-101c0000.ehci-1.2): /dev/video0 /dev/video1

v4l2-ctl -l

                 brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                   contrast 0x00980901 (int)    : min=0 max=255 step=1 default=42 value=42
                 saturation 0x00980902 (int)    : min=0 max=100 step=1 default=64 value=64
                        hue 0x00980903 (int)    : min=-180 max=180 step=1 default=0 value=0

white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1 gamma 0x00980910 (int) : min=90 max=150 step=1 default=120 value=120 gain 0x00980913 (int) : min=4 max=8 step=1 default=4 value=4 power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1 white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=4000 value=4000 flags=inactive sharpness 0x0098091b (int) : min=0 max=7 step=1 default=2 value=2 backlight_compensation 0x0098091c (int) : min=0 max=2 step=1 default=0 value=0 exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3 exposure_absolute 0x009a0902 (int) : min=10 max=2500 step=1 default=156 value=156 flags=inactive error 5 getting ext_ctrl Exposure, Auto Priority

ffmpeg -f v4l2 -list_formats all -i /dev/video0

ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 8.4.0 (OpenWrt GCC 8.4.0 r16936-e4f5ccf44d) configuration: --enable-cross-compile --cross-prefix=mipsel-openwrt-linux-musl- --arch=mipsel --cpu=24kc --target-os=linux --prefix=/usr --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-altivec --disable-vsx --disable-power8 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-fast-unaligned --disable-runtime-cpudetect --disable-x86asm --enable-gnutls --enable-small --enable-libshine --enable-gpl --enable-libx264 libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [video4linux2,v4l2 @ 0x764fb140] Compressed: mjpeg : Motion-JPEG : 640x480 [video4linux2,v4l2 @ 0x764fb140] Raw : yuyv422 : YUYV 4:2:2 : 640x480 /dev/video0: Immediate exit requested

ffmpeg -f oss -f video4linux2 -s 640x480 -i /dev/video0 out.mpg

ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 8.4.0 (OpenWrt GCC 8.4.0 r16936-e4f5ccf44d) configuration: --enable-cross-compile --cross-prefix=mipsel-openwrt-linux-musl- --arch=mipsel --cpu=24kc --target-os=linux --prefix=/usr --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-altivec --disable-vsx --disable-power8 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-fast-unaligned --disable-runtime-cpudetect --disable-x86asm --enable-gnutls --enable-small --enable-libshine --enable-gpl --enable-libx264 libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 Input #0, video4linux2,v4l2, from '/dev/video0': Duration: N/A, start: 27755.562880, bitrate: 147456 kb/s Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg1video (native)) Press [q] to stop, [?] for help [mpeg @ 0x77eac020] VBV buffer size not set, using default size of 230KB If you want the mpeg file to be compliant to some specification Like DVD, VCD or others, make sure you set the correct buffer size Output #0, mpeg, to 'out.mpg': Metadata: encoder : Lavf58.45.100 Stream #0:0: Video: mpeg1video, yuv420p, 640x480, q=2-31, 200 kb/s, 30 fps, 90k tbn, 30 tbc Metadata: encoder : Lavc58.91.100 mpeg1video Side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A frame= 27 fps=3.8 q=9.3 Lsize= 98kB time=00:00:00.83 bitrate= 963.4kbits/s dup=14 drop=0 speed=0.117x
video:97kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.455840% Exiting normally, received signal 2.

/usr/bin/mjpg_streamer --input "input_uvc.so --device /dev/video0 -y" --output "output_http.so -p 8090"

MJPG Streamer Version.: 2.0 i: Using V4L2 device.: /dev/video0 i: Desired Resolution: 640 x 480 i: Frames Per Second.: -1 i: Format............: YUYV i: JPEG Quality......: 80 i: TV-Norm...........: DEFAULT UVCIOC_CTRL_ADD - Error at Pan (relative): Not a tty (25) UVCIOC_CTRL_ADD - Error at Tilt (relative): Not a tty (25) UVCIOC_CTRL_ADD - Error at Pan Reset: Not a tty (25) UVCIOC_CTRL_ADD - Error at Tilt Reset: Not a tty (25) UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Not a tty (25) UVCIOC_CTRL_ADD - Error at Focus (absolute): Not a tty (25) UVCIOC_CTRL_MAP - Error at Pan (relative): Not a tty (25) UVCIOC_CTRL_MAP - Error at Tilt (relative): Not a tty (25) UVCIOC_CTRL_MAP - Error at Pan Reset: Not a tty (25) UVCIOC_CTRL_MAP - Error at Tilt Reset: Not a tty (25) UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Not a tty (25) UVCIOC_CTRL_MAP - Error at Focus (absolute): Not a tty (25) UVCIOC_CTRL_MAP - Error at LED1 Mode: Not a tty (25) UVCIOC_CTRL_MAP - Error at LED1 Frequency: Not a tty (25) UVCIOC_CTRL_MAP - Error at Disable video processing: Not a tty (25) UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Not a tty (25) o: www-folder-path......: disabled o: HTTP TCP port........: 8090 o: HTTP Listen Address..: (null) o: username:password....: disabled o: commands.............: enabled ^Csetting signal to stop i: cleaning up resources allocated by input thread force cancellation of threads and cleanup resources Segmentation fault

ihrapsa commented 1 year ago

Hi, mjpg-streamer is installed by default. OpenWrt uses /etc/config/mjpg-streamer as the configuration file. The server is restarting every time you plug a video device. To troubleshoot do logread -f and unplug-> replug the usb webcam. logread -f terminal should output some logs. The mjpg-streamer server should be onhttp://:8080`

kgsrirama commented 1 year ago

Sorry forgot to mention earlier, checked those too. Tried toggling option enabled to 1 and device to /dev/video1 /etc/config/mjpg-streame but nothing changed

ihrapsa commented 1 year ago

What webcam are you using?

kgsrirama commented 1 year ago

It is Enter Device 004: ID 13d3:784b FLH-BY-0309-200514 Integrated Camera with SPCA2072A chip in it. I use it in my ubuntu laptop. BTW I can see it working in the commandline mjpg-streamer in klipper/ender3 box too

Sorry for split messages (used to Ctrl+enter in another program to move to next line)

This is the only output after accessing http://ender3.lan:8080/webcam/stream.html which is unrealted to above error Tue Dec 6 21:27:30 2022 daemon.err odhcpd[1663]: Failed to send to ff02::1%lan@br-lan (Address not available)

kgsrirama commented 1 year ago

Sorry for the trouble, I am able to solve the issue. It was due to a conflict in port for 8080. I guess KlipperWRT pushes openwrt to port 8080 in nginx configuration. But I moved openWRT to 8000 using luci and tried using 8080 for mjpg-streamer. However, 8080 configuration remained in nginx and access url to mjpg-streamer was always redirected by cgi-bin/luci.

I solved it temporarily moving mjpg-streamer to port 8090

array81 commented 11 months ago

I have a similar problem with my webcam plug on USB2.

This is my code:

config mjpg-streamer 'core'
        option enabled '0'
        option input 'uvc'
        option output 'http'
        option device '/dev/video0'
        option resolution '640x480'
        option yuv '0'
        option quality '80'
        option fps '5'
        option led 'auto'
        option www '/www/webcam'
        option port '8080'
        #option listen_ip '192.168.1.1'
        #option username 'openwrt'
        #option password 'openwrt'