Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg copy mjpeg on Raspberry Pi not outputting stream #747

Open
dts350z opened this issue Nov 12, 2023 · 17 comments
Open

ffmpeg copy mjpeg on Raspberry Pi not outputting stream #747

dts350z opened this issue Nov 12, 2023 · 17 comments
Labels
enhancement New feature or request

Comments

@dts350z
Copy link

dts350z commented Nov 12, 2023

On Raspberry Pi Bookworm (or DietPi) on Pi 5, Pi 4, and Pi zero 2 W, using docker and go2rtc 1.8.2, the "add" format for copying an mjpeg stream doesn't output a stream:

ffmpeg:device?video=/dev/video0&input_format=mjpeg&video_size=1920x1080

Produces a ffmpeg command:

ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -f mjpeg -

However when you go to: http://192.168.102.48:1984/stream.html?src=one&mode=mjpeg

It says mjpeg eof. I've also seen something about a header error, but didn't capture the error.

My input device:

glenn@raspberrypi:~ $ sudo v4l2-ctl --device=/dev/video0 --all
Driver Info:
        Driver name      : uvcvideo
        Card type        : USB Video: USB Video
        Bus info         : usb-0000:01:00.0-1.4
        Driver version   : 6.1.58
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : uvcvideo
        Model            : USB Video: USB Video
        Serial           :
        Bus info         : usb-0000:01:00.0-1.4
        Media version    : 6.1.58
        Hardware revision: 0x00002100 (8448)
        Driver version   : 6.1.58
Interface Info:
        ID               : 0x03000002
        Type             : V4L Video
Entity Info:
        ID               : 0x00000001 (1)
        Name             : USB Video: USB Video
        Function         : V4L2 I/O
        Flags            : default
        Pad 0x01000007   : 0: Sink
          Link 0x0200000d: from remote pad 0x100000a of entity 'Processing 2' (Video Pixel Formatter): Data, Enabled, Immutable
Priority: 2
Video input : 0 (Input 1: ok)
Format Video Capture:
        Width/Height      : 1920/1080
        Pixel Format      : 'YUYV' (YUYV 4:2:2)
        Field             : None
        Bytes per Line    : 3840
        Size Image        : 4147200
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Default (maps to Limited Range)
        Flags             :
Crop Capability Video Capture:
        Bounds      : Left 0, Top 0, Width 1920, Height 1080
        Default     : Left 0, Top 0, Width 1920, Height 1080
        Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:
Streaming Parameters Video Capture:
        Capabilities     : timeperframe
        Frames per second: 5.000 (5/1)
        Read buffers     : 0

User Controls

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

Just FYI ,

streams:
  usb0:   ffmpeg:device?video=0#video=mjpeg

which gives:

ffmpeg -hide_banner -v error -f v4l2 -i /dev/video0 -c:v mjpeg -an -f mjpeg -

works, but I'd like to have ffmpeg just do the copy, rather than decode and re-encode the same format, to save CPU.

@dts350z
Copy link
Author

dts350z commented Nov 12, 2023

Here is the error:

18:05:00.672 ERR github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166 > error="streams: streams: unsupported scheme: fffmpeg:device?video=/dev/video0&input_format=mjpeg&video_size=1920x1080"

@AlexxIT AlexxIT added the question Further information is requested label Nov 12, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented Nov 12, 2023

  1. Looks like you have triple f for fffmpeg in your config
  2. Why do you think, your camera supports the mjpeg codec?

@dts350z
Copy link
Author

dts350z commented Nov 12, 2023

  1. Typo. With the offending f removed (this is just the format string copied from the "Add" web UI):

mpeg: streams magic: unsupported header: ff80ff80 in the web page

and

18:48:52.201 ERR github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166 > error="streams: magic: unsupported header: 14500145"

on browser reload, and:

18:51:20.732 ERR github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166 > error="streams: EOF"

another time.

  1. Not a camera, but an HDMI to USB interface. See the output of sudo v4l2-ctl --device=/dev/video0 --all I had pasted in above. Also, again, I am just taking your ffmpeg format string from the "add" web UI.

@AlexxIT
Copy link
Owner

AlexxIT commented Nov 12, 2023

Don't use add page for adding ffmpeg sources. Add them to the config page.
And show Add > FFmpeg Device screenshot.

@dts350z
Copy link
Author

dts350z commented Nov 12, 2023

image

image

image

image

@dts350z
Copy link
Author

dts350z commented Nov 12, 2023

Just noticed that if I reboot, with all of the above already in place, vs. "Save & Restart", I do get an output, no errors, but "flashing" black output (output flashes on and off with all back showing when the video isn't).

@AlexxIT
Copy link
Owner

AlexxIT commented Nov 13, 2023

Can you record some data and post it here?

ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -t 10 -f mjpeg dump.mjpeg

@dts350z
Copy link
Author

dts350z commented Nov 13, 2023

glenn@raspberrypi:~ $ ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -t 10 -f mjpeg dump.mjpeg
/dev/video0: Device or resource busy
glenn@raspberrypi:~ $ sudo systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket
glenn@raspberrypi:~ $ ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -t 10 -f mjpeg dump.mjpeg
ioctl(VIDIOC_QBUF): Bad file descriptor

With an iphone connected to the HDMI to USB adapter:

glenn@raspberrypi:~ $ ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -t 10 -f mjpeg dump.mjpeg
[mjpeg @ 0x55a1c81540] bits 60 is invalid
File 'dump.mjpeg' already exists. Overwrite? [y/N] y
ioctl(VIDIOC_QBUF): Bad file descriptor

Resulting file plays OK in VLC either way

Note: this is the system os ffmpeg. I don't know how to access the ffmpeg inside the gotortc docker container.

Uploading iphone-dump.zip…

@AlexxIT
Copy link
Owner

AlexxIT commented Nov 13, 2023

Your upload broker. Can you add it once again?

@dts350z
Copy link
Author

dts350z commented Nov 14, 2023

@dts350z
Copy link
Author

dts350z commented Nov 14, 2023

@dts350z
Copy link
Author

dts350z commented Nov 14, 2023

@AlexxIT
Copy link
Owner

AlexxIT commented Nov 14, 2023

No. All of your uploading broken

@dts350z
Copy link
Author

dts350z commented Nov 14, 2023

@AlexxIT AlexxIT added enhancement New feature or request and removed question Further information is requested labels Nov 18, 2023
@AlexxIT AlexxIT added this to the v1.8.4 milestone Nov 18, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented Nov 19, 2023

Your MJPEG stream has some trash on start. I hope latest release will handle this
https://github.com/AlexxIT/go2rtc/releases/tag/v1.8.4

@AlexxIT AlexxIT closed this as completed Nov 19, 2023
@dts350z
Copy link
Author

dts350z commented Nov 19, 2023

Thanks for working on this.

The stream starts without error, and the CPU load is MUCH less, however the resulting stream (played in chrome, on windows) randomly and frequently "flashes" between normal and a black background. Very roughly one or more times per second or two.

Using the OS supplied ffmpeg:

sjaa@station251:~$ ffmpeg -hide_banner -v error -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c copy -t 10 -f mjpeg dump.mjpeg
[mjpeg @ 0x55acf69570] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1144152 >= 1144152
[mjpeg @ 0x55acf69570] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 3744491 >= 3744491
[mjpeg @ 0x55acf69570] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6144837 >= 6144837
ioctl(VIDIOC_QBUF): Bad file descriptor

Seems like that plays in VLC OK, however, without "flashing".

https://drive.google.com/file/d/1PBkv6NBON7C2pw19UwLk01tga6s_Sz8T/view?usp=sharing

I tried adding -r30 to the ffmpeg command. That gave a ton more dts error messages.

https://drive.google.com/file/d/1PDuoAEviHYxu71JLpApOjmYkb0O8jpeI/view?usp=sharing

Both of those files seem to play normally when streamed:

streams:
  usb0:   ffmpeg:device?video=0#video=mjpeg#hardware
  file0:  ffmpeg:/config/r30.mjpeg
  file1:  ffmpeg:/config/dump.mjpeg

however.

@AlexxIT AlexxIT reopened this Nov 19, 2023
@AlexxIT AlexxIT self-assigned this Dec 12, 2023
@AlexxIT AlexxIT removed this from the v1.8.4 milestone Dec 12, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented Dec 28, 2023

Both your files has a lot of trash at the start. I have already increase probe size to 4KB. I don't think it is good idea to increase this size more. This can be problem for other users

@AlexxIT AlexxIT removed their assignment Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants