Index: conf.c
===================================================================
--- conf.c	(revisión: 261)
+++ conf.c	(copia de trabajo)
@@ -92,6 +92,7 @@
 	tuner_device:          NULL,
 #endif
 	video_device:          VIDEO_DEVICE,
+	v4l2_palette:          8,		
 	vidpipe:               NULL,
 	filepath:              NULL,
 	jpegpath:              DEF_JPEGPATH,
@@ -198,6 +199,30 @@
 	copy_string,
 	print_string
 	},
+	{
+	"v4l2_palette",
+	"# v4l2_palette allow to choose preferable palette to be use by motion\n"
+	"# to capture from those supported by your videodevice. ( default: 8)\n"
+	"# i.ex if your videodevice supports V4L2_PIX_FMT_SBGGR8 and\n"
+	"# V4L2_PIX_FMT_MJPEG by default motion will use V4L2_PIX_FMT_MJPEG so\n"
+	"# set v4l2_palette 1 to force motion use V4L2_PIX_FMT_SBGGR8 instead.\n" 
+	"#\n"
+	"# Values :\n"
+	"#\n"
+	"# V4L2_PIX_FMT_SN9C10X : 0  'S910'\n"
+	"# V4L2_PIX_FMT_SBGGR8  : 1  'BA81'\n"
+	"# V4L2_PIX_FMT_MJPEG   : 2  'MJPEG'\n"
+	"# V4L2_PIX_FMT_JPEG    : 3  'JPEG'\n"
+	"# V4L2_PIX_FMT_RGB24   : 4  'RGB3'\n"
+	"# V4L2_PIX_FMT_UYVY    : 5  'UYVY'\n"
+	"# V4L2_PIX_FMT_YUYV    : 6  'YUYV'\n"
+	"# V4L2_PIX_FMT_YUV422P : 7  '422P'\n"
+	"# V4L2_PIX_FMT_YUV420  : 8  'YU12'",
+	0,
+	CONF_OFFSET(v4l2_palette),
+	copy_int,
+	print_int
+	},
 #if (defined(BSD))
 	{
 	"tunerdevice",
Index: conf.h
===================================================================
--- conf.h	(revisión: 261)
+++ conf.h	(copia de trabajo)
@@ -76,6 +76,7 @@
 	const char *tuner_device;
 #endif
 	const char *video_device;
+	short unsigned int v4l2_palette;
 	const char *vidpipe;
 	const char *filepath;
 	const char *jpegpath;
Index: video2.c
===================================================================
--- video2.c	(revisión: 261)
+++ video2.c	(copia de trabajo)
@@ -291,10 +291,10 @@
 	return (0);
 }
 
-static int v4l2_set_pix_format(src_v4l2_t * s, int *width, int *height)
+static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width, int *height)
 {
 	struct v4l2_fmtdesc fmt;
-	int v4l2_pal;
+	short int v4l2_pal;
 
 	static const u32 supported_formats[] = {	/* higher index means better chance to be used */
 		V4L2_PIX_FMT_SN9C10X,
@@ -309,7 +309,7 @@
 		0
 	};
 
-	int index_format = -1;
+	short int index_format = -1;
 
 	memset(&fmt, 0, sizeof(struct v4l2_fmtdesc));
 	fmt.index = v4l2_pal = 0;
@@ -317,7 +317,7 @@
 
 	motion_log(LOG_INFO, 0, "Supported palettes:");
 	while (xioctl(s->fd, VIDIOC_ENUM_FMT, &fmt) != -1) {
-		int i;
+		short int i;
 
 		motion_log(LOG_INFO, 0, "%i: %c%c%c%c (%s)", v4l2_pal,
 			   fmt.pixelformat >> 0, fmt.pixelformat >> 8,
@@ -325,6 +325,13 @@
 
 		for (i = 0; supported_formats[i]; i++)
 			if (supported_formats[i] == fmt.pixelformat && i > index_format) {
+				if (cnt->conf.v4l2_palette == i) {
+					index_format = cnt->conf.v4l2_palette;
+					motion_log(LOG_INFO, 0, "Selected palette %c%c%c%c", fmt.pixelformat >> 0, 
+								fmt.pixelformat >> 8, fmt.pixelformat >> 16, fmt.pixelformat >> 24);
+					i=10;
+					break;
+				}
 				index_format = i;
 			}
 
@@ -345,7 +352,7 @@
 		s->fmt.fmt.pix.field = V4L2_FIELD_ANY;
 
 		if (xioctl(s->fd, VIDIOC_TRY_FMT, &s->fmt) != -1 && s->fmt.fmt.pix.pixelformat == pixformat) {
-			motion_log(LOG_INFO, 0, "Test palette %c%c%c%c (%dx%d)", pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height);
+			motion_log(LOG_INFO, 0, "index_format %d Test palette %c%c%c%c (%dx%d)", index_format, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height);
 
 			if (s->fmt.fmt.pix.width != (unsigned int) *width
 			    || s->fmt.fmt.pix.height != (unsigned int) *height) {
@@ -651,7 +658,7 @@
 		goto err;
 	}
 
-	if (v4l2_set_pix_format(s, &width, &height)) {
+	if (v4l2_set_pix_format(cnt ,s, &width, &height)) {
 		goto err;
 	}
 
Index: motion-dist.conf
===================================================================
--- motion-dist.conf	(revisión: 261)
+++ motion-dist.conf	(copia de trabajo)
@@ -28,6 +28,25 @@
 # for FreeBSD default is /dev/bktr0
 videodevice /dev/video0
 
+# v4l2_palette allow to choose preferable palette to be use by motion
+# to capture from those supported by your videodevice. ( default: 8)
+# i.ex if your videodevice supports V4L2_PIX_FMT_SBGGR8 and
+# V4L2_PIX_FMT_MJPEG by default motion will use V4L2_PIX_FMT_MJPEG so
+# set v4l2_palette 1 to force motion use V4L2_PIX_FMT_SBGGR8 instead. 
+#
+# Values :
+#
+# V4L2_PIX_FMT_SN9C10X : 0  'S910'
+# V4L2_PIX_FMT_SBGGR8  : 1  'BA81'
+# V4L2_PIX_FMT_MJPEG   : 2  'MJPEG'
+# V4L2_PIX_FMT_JPEG    : 3  'JPEG'
+# V4L2_PIX_FMT_RGB24   : 4  'RGB3'
+# V4L2_PIX_FMT_UYVY    : 5  'UYVY'
+# V4L2_PIX_FMT_YUYV    : 6  'YUYV'
+# V4L2_PIX_FMT_YUV422P : 7  '422P'
+# V4L2_PIX_FMT_YUV420  : 8  'YU12'
+v4l2_palette 8
+
 # Tuner device to be used for capturing using tuner as source (default /dev/tuner0)
 # This is ONLY used for FreeBSD. Leave it commented out for Linux
 ; tunerdevice /dev/tuner0
