Available mjpg-streamer configuration options

The following configuration options can be supplied to MJPG Streamer on start to modify certain camera settings. To change any of these options in OctoPi, edit the relevant sections in octopi.txt as described here.

USB webcams (input_uvc.so)

input_uvc.so comes bundled with MJPG Streamer.

See also the documentation for the recommended MJPG Streamer fork (bundled with OctoPi) for additional options not listed here.

  • -d <device>: The video device to use, e.g. -d /dev/video0
  • -r <resolution>: The resolution, e.g. -r 640x480 for 640x480px
  • -f <framerate>: The framerate in frames per second, e.g. -f 10 for 10 fps
  • -q <quality>: The quality of the JPG compression to use, e.g. -q 85 for compression down to 85%
  • -y: Use this if your camera doesn't support MJPG, pictures will be captured in YUVY

Raspicam (input_raspi.so)

:raised_hand: No longer available under OctoPi 1.0.0, use input_uvc.so for the Raspicam there. (On OctoPi, this means usb mode, using camera_usb_options as above)

input_raspi.so is included in this MJPG Streamer fork by Jackson Liam which also supports the Raspberry Pi Camera. This is the fork that is shipped on the OctoPi SD card image for the Raspberry Pi.

See also the documentation for more information about these options.

  • -fps or --framerate: set video framerate, default 1 frame/sec
  • -x or --width: width of frame capture, default 640
  • -y or --height: height of frame capture, default 480
  • -quality: set JPEG quality (0 to 100), default 85
  • -usestills: uses stills mode instead of video mode
  • -sh: Set image sharpness (-100 to 100)
  • -co: Set image contrast (-100 to 100)
  • -br: Set image brightness (0 to 100)
  • -sa: Set image saturation (-100 to 100)
  • -ISO: Set capture ISO
  • -vs: Turn on video stablisation
  • -ev: Set EV compensation
  • -ex: Set exposure mode, valid values (according to the RaspiCam documentation):
    • off
    • auto: Use automatic exposure
    • night: Select setting for night shooting
    • nightpreview
    • backlight: Select setting for back-lit subject
    • spotlight
    • sports: Select setting for sports (fast shutter etc.)
    • snow: Select setting optimized for snowy scenery
    • beach: Select setting optimized for beach
    • verylong: Select setting for long exposures
    • fixedfps: Constrain fps to a fixed value
    • antishake: Antishake mode
    • fireworks: Select setting optimized for fireworks
  • -awb: Set AWB mode, valid values (according to the RaspiCam documentation):
    • off: Turn off white balance calculation
    • auto: Automatic mode (default)
    • sun: Sunny mode
    • cloudshade: Cloudy mode
    • tungsten: Tungsten lighting mode
    • fluorescent: Fluorescent lighting mode
    • incandescent: Incandescent lighting mode
    • flash: Flash mode
    • horizon: Horizon mode
  • -ifx: Set image effect (according to the RaspiCam documentation):
    • none: No effect
    • negative: Produces a negative image
    • solarise: Solarise the image
    • whiteboard: Whiteboard effect
    • blackboard: Blackboard effect
    • sketch: Sketch-style effect
    • denoise: Denoise the image
    • emboss: Embossed effect
    • oilpaint: Oil paint-style effect
    • hatch: Cross-hatch sketch style
    • gpen: Graphite sketch style
    • pastel: Pastel effect
    • watercolour: Watercolour effect
    • film: Grainy film effect
    • blur: Blur the image
    • saturation: Colour-saturate the image
    • colourswap: Not fully implemented
    • washedout: Not fully implemented
    • posterise: Not fully implemented
    • colourpoint: Not fully implemented
    • colourbalance: Not fully implemented
    • cartoon: Not fully implemented
  • -cfx: Set colour effect (U:V), the supplied U and V parameters (range 0 to 255) are applied to the U and Y channels of the image. For example, --colfx 128:128 should result in a monochrome image (according to the RaspiCam documentation).
  • -mm: Set metering mode (see raspistill notes), valid values (according to the RaspiCam documentation):
    • average: Average the whole frame for metering
    • spot: Spot metering
    • backlit: Assume a backlit image
    • matrix: Matrix metering
  • -rot: Set image rotation (0-359, at the present only 0, 90, 180 and 270 are supported though)
  • -hf: Set horizontal flip
  • -vf: Set vertical flip
5 Likes

Not sure if you want question in this thread or not, but I have played with the -q setting with the C270 and see no change in compression artifacts in the live feed when altering the parameter from 85 down to 0 rebooting with each change.
Would I only see a difference in a timelaps or does it only effect the jpg size? I did not yet attempt a print and creation of the Timelaps with this setting.
Thanks
Doug

Not all cameras expose all controls via UVC. The C270 exposes fewer than the C525 or C615, which in turn expose fewer than the C920 or C930. It's possible that the JPEG quality is fixed on the C270 (or the version of firmware yours has) or that the artifacts are noise or other capture artifacts (light level, contrast, lens, IR or UV, quirks of your particular die, etc.) and not compression artifacts.

If you hadn't tried such a large range, I'd suggest it was also possible that you are asking it for the same level of compression it's already doing, due to binning (for instance, a camera may only have 3 quality levels and both the default value and the one you request may equate to the same level of compression).

1 Like

Thanks Supertaz, that all make perfect sense!

Can we change usb-camera iso or exposure settings? My usb camera stream too dark

It depends on your camera. If your camera exposes exposure settings via UVC, then you should be able to change them, though mjpeg-streamer only exposes those for input_raspi.so, so you'd need to set it via another UVC consumer.

1 Like

Check this thread but make sure you read it all https://discourse.octoprint.org/t/changed-the-video-feed-brightness-contrast-and-settings-for-my-logitech-usb-video/1103/7

How do I get my Logitech C170 ! 1280x720 (camera_usb_options="-r 1280x720 -f 15") to actually display and save in it's correct aspect ratio? It is only displaying and saving 1024/768. Do you need a log file?

Thank you.

Octopi.txt:

### Configure which camera to use
#
# Available options are:
# - auto: tries first usb webcam, if that's not available tries raspi cam
# - usb: only tries usb webcam
# - raspi: only tries raspi cam
#
# Defaults to auto
#
camera="usb"

### Additional options to supply to MJPG Streamer for the USB camera
#
# See https://github.com/foosel/OctoPrint/wiki/MJPG-Streamer-configuration
# for available options
#
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
#
camera_usb_options="-r 1280x720 -f 15"


### Additional webcam devices known to cause problems with -f
#
# Apparently there a some devices out there that with the current
# mjpg_streamer release do not support the -f parameter (for specifying
# the capturing framerate) and will just refuse to output an image if it
# is supplied.
#
# The webcam daemon will detect those devices by their USB Vendor and Product
# ID and remove the -f parameter from the options provided to mjpg_streamer.
#
# By default, this is done for the following devices:
#   Logitech C170 (046d:082b)
#   GEMBIRD (1908:2310)
#   Genius F100 (0458:708c)
#   Cubeternet GL-UPC822 UVC WebCam (1e4e:0102)
#
# Using the following option it is possible to add additional devices. If
# your webcam happens to show above symptoms, try determining your cam's
# vendor and product id via lsusb, activating the line below by removing # and
# adding it, e.g. for two broken cameras "aabb:ccdd" and "aabb:eeff"
#
#   additional_brokenfps_usb_devices=("aabb:ccdd" "aabb:eeff")
#
# If this fixes your problem, please report it back so we can include the device
# out of the box: https://github.com/guysoft/OctoPi/issues
#
#additional_brokenfps_usb_devices=()

### Additional options to supply to MJPG Streamer for the RasPi Cam
#
# See https://github.com/foosel/OctoPrint/wiki/MJPG-Streamer-configuration
# for available options
#
# Defaults to 10fps
#
#camera_raspi_options="-fps 10"

### Configuration of camera HTTP output
#
# Usually you should NOT need to change this at all! Only touch if you
# know what you are doing and what the parameters mean.
#
# Below settings are used in the mjpg-streamer call like this:
#
#   -o "output_http.so -w $camera_http_webroot $camera_http_options"
#
# Current working directory is the mjpg-streamer base directory.
#
#camera_http_webroot="./www-octopi"
#camera_http_options="-n"

@Space_Engineer I remember the C170 has an issue with the -f parameter (the comment further down also states this). So definitely get rid of that (the webcam server script should strip it, but maybe that isn't working properly here for some reason).

And the answer to "do you need a log file" is always "yes".

3 Likes

That right there deserves a sticky FAQ post :wink:

2 Likes

Is there anyway to use auto exposure, white balance etc. but then fix the values? Slight variances in these are jaunting in my timelapses

@geekkid, I believe you are using Octolapse, are you not? If so, take a look at this guide for getting custom image preferences working for mjpegstreamer. Pay close attention to the octopi.txt modifications that are needed as well as the security implications of making the change.

You could also use the 'Camera Initialization Script' to set the parameters via script, but that's probably overkill.

I am but my pi isn't running ocotpi but instead raspbian that I have installed octoprint on top of. I guess it it just a case of manually adjusting the exposure parameter of mjpg-streamer? I was hoping for a way to get the value of the autoexposure and then keep it ideally. Does mjpg-streaner expose the current exposure in any way?
This is probably the wrong thread and forum but is there anyway of having different resolutions for live stream and capture? I'm not to bothered about the live stream not looking too good and would rather have a low resolution and higher frame rate and my internet not too affected whereas when captures are required for octolapse I would rather have a high resolution image.

Sorry for all the questions

If you're running the default mjpegstreamer install control.htm should already be enabled. You can check it like so:

http://{ip address of pi}/webcam/control.htm

If a page loads you should be good to go as far as getting the custom image preferences working.

I'm not sure if it's possible to retrieve the current 'exposure' setting, but you definitely can change it. There are several ways of doing it, but Octolapse uses an http request sent to the mjpegstreamer's control.htm page. There are other ways of setting the exposure, however.

Regarding using a different resolution for capture/streaming, I don't think this is possible, but will look into it a bit when I have some time. The still images are captured from the camera stream, I believe. The most straightforward way to accomplish what you are trying to do would be to use two cameras and set one to a lower resolution. This solution can cause bandwidth and cpu utilization issues depending on a lot of variables (pi type, resolution, internal camera compression availability, etc...). However, I have not tested this, so perhaps it will work better if you're not actually streaming the higher res camera to any browsers.

I'm going to do a multi-stream tutorial soon, and will try to test cpu utilization also. The BEST solution would be to use a separate pi as a webcam server, and I'll try to include this option in my tutorial.

I like answering questions :slight_smile:

i add this line to my /boot/octopi.txt
camera_raspi_options="-x 1920 -y 1080 -fps 20 -quality 100 -ex auto -awb auto"
print a stl, but is always 640x480, i have a raspicam 1080p
whats wrong?
how can i test without always start print?

webcamd.service - LSB: webcam daemon
   Loaded: loaded (/etc/init.d/webcamd; generated; vendor preset: enabled)
   Active: active (running) since Wed 2019-03-27 13:21:18 GMT; 13min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 408 ExecStart=/etc/init.d/webcamd start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/webcamd.service
           β”œβ”€444 /bin/bash /root/bin/webcamd
           └─460 ./mjpg_streamer -o output_http.so -w ./www-octopi -n -i input_uvc.so -r 640x480 -f 10 -d /dev/video0

ok , solved:
camera="auto" dont work, force camera="raspi"
service webcamd restart
service webcamd status Show actual parameter
http://ip:8080 show actual size image

1 Like

Nice. I need to get my hands on and learn more about the raspi cam.

I can get to http://{my octopi address}/webcam/control.htm, but when I select "Enable And Apply Preferences Before Print", an error (Unable To Enable Custom Preferences) pops up. What do I do next?

Hi GlenH! Can you let me know what the error message is? Also, what do you see when you go to control.htm? Finally, what kind of camera are you using?

I posted the header of the message. I’ll post the body when I get home. The camera is an HXSJ S70; a cheap HD webcam from Amazon. Control.htm exposes a bunch of controls, including focus and exposure.

Unable To Enable Custom Preferences

mjpegstreamer-control-error: The server denied access to the MJPG-Streamer control.html for the 'Default Webcam' camera profile. Please see this link to correct this error., or disable 'Custom Image Preferences'.

Note that the error message says "control.html", though the actual page is "control.htm"