Available mjpg-streamer configuration options


#1

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.

  • -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)

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.

  • -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

Can't get my webcam to work with OctoPi
Webcam exposure
Pi cam streaming over internet slow
Problem with webcam crashes
Webcam stream flipped
Octolapse Resolution with Raspi Cam
#2

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


#3

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).


#4

Thanks Supertaz, that all make perfect sense!


#5

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


#6

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.


#7

Check this thread but make sure you read it all Changed the video feed brightness, contrast and settings for my Logitech USB video


#8

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"

#9

@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".


#10

That right there deserves a sticky FAQ post :wink:


#11

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


#12

@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.


#13

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


#14

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: