gen2brain / cam2ip

Turn any webcam into an IP camera
GNU General Public License v3.0
889 stars 93 forks source link

Cannot install using go get #45

Open MaddyPhi opened 1 year ago

MaddyPhi commented 1 year ago

When I try to install using go get -v -tags cv2 github.com/gen2brain/cam2ip/cmd/cam2ip I get the following:

# pkg-config --cflags  -- opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing 'opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
pkg-config: exit status 1
# github.com/klauspost/compress/flate
go/src/github.com/klauspost/compress/flate/deflate.go:135:23: cannot convert d.window (type []byte) to type *[32768]byte
go/src/github.com/klauspost/compress/flate/deflate.go:135:56: cannot convert d.window[windowSize:] (type []byte) to type *[32768]byte
go/src/github.com/klauspost/compress/flate/fast_encoder.go:93:28: cannot convert e.hist (type []byte) to type *[32768]byte
go/src/github.com/klauspost/compress/flate/fast_encoder.go:93:63: cannot convert e.hist[offset:] (type []byte) to type *[32768]byte
go/src/github.com/klauspost/compress/flate/huffman_bit_writer.go:794:17: cannot convert w.literalFreq[:] (type []uint16) to type *[256]uint16
go/src/github.com/klauspost/compress/flate/huffman_bit_writer.go:796:16: cannot convert w.literalFreq[256:] (type []uint16) to type *[32]uint16

When I do go get -v github.com/gen2brain/cam2ip/cmd/cam2ip I get the same without the opencv issue.

When I run one of the binaries offered, I get -bash: ./cam2ip: No such file or directory except for if I use the rpi static version which seems to work. However, when running that version it would seem that the frame rate is very slow.

For some context, this is the system I am working with

pi@crafthub:~/cam2ip-1.6-RPi-nocgo $ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
pi@crafthub:~/cam2ip-1.6-RPi-nocgo $ v4l2-ctl --list-formats-ext --device /dev/video0
ioctl: VIDIOC_ENUM_FMT
        Type: Video Capture

        [0]: 'MJPG' (Motion-JPEG, compressed)
                Size: Discrete 1920x1080
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 640x480
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 1024x768
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 1280x720
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 1280x1024
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 2048x1536
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 320x240
                        Interval: Discrete 0.033s (30.000 fps)
        [1]: 'YUYV' (YUYV 4:2:2)
                Size: Discrete 640x480
                        Interval: Discrete 0.040s (25.000 fps)
                Size: Discrete 1024x768
                        Interval: Discrete 0.100s (10.000 fps)
                Size: Discrete 1280x720
                        Interval: Discrete 0.100s (10.000 fps)
                Size: Discrete 1280x1024
                        Interval: Discrete 0.200s (5.000 fps)
                Size: Discrete 1920x1080
                        Interval: Discrete 0.200s (5.000 fps)
                Size: Discrete 320x240
                        Interval: Discrete 0.033s (30.000 fps)
                Size: Discrete 2048x1536
                        Interval: Discrete 0.200s (5.000 fps)
pi@crafthub:~/cam2ip-1.6-RPi-nocgo $ 

Any help you can offer, I would appreciate. Thank you in advance.

mmokrejs commented 8 months ago

It worked for me:

$ export GOPATH=$HOME/apps/cam2ip
go install github.com/gen2brain/cam2ip/cmd/cam2ip@latest
go: downloading github.com/gen2brain/cam2ip v0.0.0-20240130151524-b302c77f20e3
go: downloading github.com/jamiealquiza/envy v1.1.0
go: downloading github.com/abbot/go-http-auth v0.4.0
go: downloading github.com/disintegration/imaging v1.6.2
go: downloading github.com/korandiz/v4l v1.1.0
go: downloading github.com/pbnjay/pixfont v0.0.0-20200714042608-33b744692567
go: downloading nhooyr.io/websocket v1.8.10
go: downloading github.com/gen2brain/base64 v0.0.0-20221015184129-317a5c93030c
go: downloading golang.org/x/crypto v0.18.0
go: downloading golang.org/x/net v0.20.0
go: downloading golang.org/x/image v0.15.0
go: downloading github.com/spf13/cobra v1.8.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading golang.org/x/sys v0.16.0
$

$ ~/apps/cam2ip/bin/cam2ip  -index 1 -height 3840
Listening on :56000

The camera appears twice as /dev/video files. That confuses cam2ip. I have an internal UVC camera and the external, so 4 `/dev/video` files in total.

While the first device of a pair cannot be used by guvcview it must be used by cam2ip. But I only get 640x480 resulution.

$ v4l2-ctl --list-devices
Integrated_Webcam_HD: Integrate (usb-0000:00:14.0-11):
    /dev/video0
    /dev/video1
    /dev/media0

4K USB Camera: 4K USB Camera (usb-0000:00:14.0-2):
    /dev/video2
    /dev/video3
    /dev/media1

$ v4l2-ctl --list-formats-ext --device /dev/video0
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'MJPG' (Motion-JPEG, compressed)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
    [1]: 'YUYV' (YUYV 4:2:2)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
$ v4l2-ctl --list-formats-ext --device /dev/video1
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

$ $ v4l2-ctl --list-formats-ext --device /dev/video2 --list-ctrls

User Controls

                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=19
                       contrast 0x00980901 (int)    : min=0 max=95 step=1 default=0 value=0
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=64 value=68
                            hue 0x00980903 (int)    : min=-2000 max=2000 step=1 default=0 value=0
        white_balance_automatic 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=64 max=300 step=1 default=100 value=170
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=100 value=121
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1 (50 Hz)
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=7 step=1 default=0 value=3
         backlight_compensation 0x0098091c (int)    : min=36 max=160 step=1 default=80 value=88

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=3 (Aperture Priority Mode)
         exposure_time_absolute 0x009a0902 (int)    : min=1 max=8188 step=1 default=156 value=156 flags=inactive
                   pan_absolute 0x009a0908 (int)    : min=-648000 max=648000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-648000 max=648000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=1023 step=1 default=0 value=0 flags=inactive
     focus_automatic_continuous 0x009a090c (bool)   : default=1 value=1
                  zoom_absolute 0x009a090d (int)    : min=0 max=60 step=1 default=0 value=0
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'MJPG' (Motion-JPEG, compressed)
        Size: Discrete 3840x2160
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2592x1944
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 2048x1536
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x960
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
    [1]: 'YUYV' (YUYV 4:2:2)
        Size: Discrete 3840x2160
            Interval: Discrete 1.000s (1.000 fps)
        Size: Discrete 2592x1944
            Interval: Discrete 1.000s (1.000 fps)
        Size: Discrete 2048x1536
            Interval: Discrete 0.333s (3.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x960
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)
$

From another shell I can run:

$ mpv http://127.0.0.1:56000/mjpeg --fps=25 --fs

OK, the issue with only 640x480 resolution is selected also happens if I access the device directly. No idea how to ask for higher resolution.

$ mpv file:///dev/video2 
 (+) Video --vid=1 (rawvideo 640x480 30.000fps)
[autoconvert] Converting yuyv422 -> yuv422p
[autoconvert] Converting yuyv422 -> yuv422p
VO: [gpu] 640x480 yuv422p
V: 00:00:52 / 00:00:52 (100%)
[ffmpeg/demuxer] video4linux2,v4l2: Some buffers are still owned by the caller on close.
[ffmpeg] ioctl(VIDIOC_QBUF): Bad file descriptor
gen2brain commented 8 months ago

I changed recently the default to be internal native jpeg, and not libturbo-jpeg. That is slower but I cannot handle the issues people who don't know how to compile are sending. Also, every cam has resolution, if the cam is 640x, you cannot "request" higher, you need to get better camera. Of course, you can do software scale.

mmokrejs commented 8 months ago

@gen2brain Thank you for your answer.

I discovered https://github.com/jacksonliam/mjpg-streamer meanwhile:

I read a bit the code because the README.md were not detailed enough to give me a clue how to handle the tool. I suggest showing more complicated examples:

# when neither -u nor -y are specified then  JPEG aka yuvj422p is selected by default
# --uyvy or -u specify UYVY aka yuvj422p
# --yuv or -y specify YUYV aka yuv420p (my mobile app cannot read the MJPEG stream but mpv works fine)
mjpg_streamer -i "/usr/lib64/mjpg-streamer/lib64/input_uvc.so -d /dev/video2 -r 3840x2160 -f 25 -pl 50hz -q 98 -y" -o "/usr/lib64/mjpg-streamer/lib64/output_http.so -w /usr/share/mjpg-streamer/www -l 192.168.0.452"
mjpg_streamer -i "/usr/lib64/mjpg-streamer/lib64/input_uvc.so -d /dev/video4 -r 3840x2160 -f 25 -pl 50hz -q 98 -y" -o "/usr/lib64/mjpg-streamer/lib64/output_http.so -w /usr/share/mjpg-streamer/www -l 192.168.0.45 -p 8888"

Then I could access both instances with my camera 2 and 3 (camera 0 is laptops internal, yet another UVC):

mpv http://192.168.0.45:8080/?action=stream
mpv http://192.168.0.45:8888/?action=stream

I did not manage to use the --fourcc RGB565 or --fourcc RGB24 for some reason. Also not setup UDP streaming server or RTSP server.

gen2brain commented 8 months ago

Thanks, but that all seems to be related to mjpg_streeamer app, right? I just heard about it. Readme should have just basic info imo, the rest is up to user.

mmokrejs commented 8 months ago

Yes, this about mjpg_streeamer app, which allows me to select even the maximum resolution of my camera.

gen2brain commented 8 months ago

If you can, please send a PR for readme, where ffplay and vlc are, but just one example please.