MJPEG camera in Frigate?

Have someone managed to get mjpeg cameras working in the amazing Frigate add-on?
I have four D’link dcs-932L with urls/configs like below, but only get a green screen. The urls works in the chrome browser… and in Agent DVR as mjpeg cameras.
My hikvision cameras with rtsp work like a charm.
Is there maybe a way to pass codec info or something to ffmpeg? Or any other ideas?

tested urls
http://usr:pass@IP/VIDEO.CGI
http://IP/image/jpeg.cgi (with auth disabled)

cameras:
  cam3:
    ffmpeg:
      inputs:
        - path: 'http://usr:pass@IP/VIDEO.CGI'
          roles:
            - detect
            - rtmp
        - path: 'http://usr:pass@IP/VIDEO.CGI'
          roles:
            - clips
            - record
    width: 640
    height: 480
    fps: 5

There are some other parameters in docs to configure MJPEG, however it’s not working for me as well.

Did anyone get this working? I get this in the log:

ffmpeg.back_garden.detect      ERROR   : [flv @ 0x55a96500a140] Video codec mjpeg not compatible with flv
ffmpeg.back_garden.detect      ERROR   : Could not write header for output file #1 (incorrect codec parameters ?): Function not implemented
ffmpeg.back_garden.detect      ERROR   : 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x564d95a8b140] moov atom not found
/tmp/cache/back_garden-20210516164700.mp4: Invalid data found when processing input
frigate.events                 INFO    : bad file: back_garden-20210516164700.mp4

Old topic, I know, but if you’re in the search, like me when I saw this post, here is my working config of a 13 year old Wanscam (can work on any Foscam compatible cameras) mjpeg camera:

  CAMARA_LIVING_FRIGATE:
    ffmpeg:
      inputs:
        - path: http://yourip:port/videostream.cgi?user=youruser&pwd=yourpass&resolution=32&rate=0
          roles:
            - detect
      input_args:
        - -avoid_negative_ts
        - make_zero
        - -fflags
        - nobuffer
        - -flags
        - low_delay
        - -strict
        - experimental
        - -fflags
        - +genpts+discardcorrupt
        - -r
        - "3" # <---- adjust depending on your desired frame rate from the mjpeg image
        - -use_wallclock_as_timestamps
        - "1"        
    width: 640
    height: 480
    fps: 3       

This is just configured for detection, if you wanna record clips or serve RTMP you need to config the output arguments to do conversion to h264. All work, but you need to consider that your CPU will be doing a lot of work converting mjpeg to h264.

2 Likes

Thanks, maybe I will give it a new try some day based on your findings! :slight_smile:

I tried that and I still have the sane errors in the log

Have you tried your own path on a VLC player to assure your path is ok? Most problems I saw on this come from not assure that the path provided to Frigate is a working mjpeg video path and/or not knowing how the camera brand exposes mjpeg paths (this may vary per brand).

VLC doesn’t play it or show an error but I can see the camera input using Firefox.

EDIT
I found another URL which plays on VLC, still getting errors and here is VLC codec information
Screenshot_20210831_134849

ffprobe

libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100

Under the roles, it turns out I still had rtmp, which I disabled and now I can see the stream. Where did I go wrong ?

Because to stream RTMP, Frigate need output parameters to know how to encode the MJPEG stream into h264 video and then work with that output. Unless you need to serve an h264 converted stream or use it for capturing things, I suggest to avoid this step and keep just the detection role for just alarm use purposes. But, if this conversion is a real need for you instead my advice, try to add this to your camera config on frigate.yml (please, be aware this will take significant power from your CPU, and can be an overkill for a small CPU):

output_args:
  record: -f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
  clips: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
  rtmp: -c:v libx264 -an -f flv

I never tried this, I’m just reproducing what’s suggested on the docs. I think it must work if you have enough CPU power. https://blakeblackshear.github.io/frigate/configuration/cameras#mjpeg-cameras

I tried the output_args only for clips as you suggested and when I try to play the video in Frigate within the browser, I receive an error that video can not be played because it is corrupt.

Anyone who got ever mjpeg stream running in Frigate?

This is my working config for dlink dsc-932LB mjpeg cameras:

  camera:
    ffmpeg:
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1
      output_args:
        record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
        rtmp: -c:v libx264 -an -f flv
      inputs:
        - path: http://IP.IP.IP.IP/video/mjpg.cgi
          roles:
            - detect
            - record
            - rtmp
    detect:
      width: 640
      height: 480
    objects:
      track:
        - person
        - car

That specific camera is not password protected but if you need that then just modify the URL path to include username and password.

9 Likes

Thanks mate…life saver…it works with my old Wanscam cam :+1: :+1:

Thanks for posting this. It worked perfectly for me with some old eyespy247 cameras I have.

I tried using the restreaming method talked about in the Frigate documentation but couldn’t make it work. This worked first time.

I spoke too soon! When I enable record for these cameras, the stream stops.
Is there a way to tweak the frigate config file to enable recording of the stream? It is just the video that doesn’t work, so when an event takes place, I get the snapshot but not the clip.

hi it been a while i have same problem if u rember or still now could u tell me if u fixed the problem