JPEG Quality confusion

Support and queries relating to all previous versions of ZoneMinder
Locked
User avatar
ma77hias
Posts: 71
Joined: Wed Jul 07, 2004 3:18 pm

JPEG Quality confusion

Post by ma77hias »

This might be a bug:
I have only noticed it on version 1.21.3, it might already exist on earlier versions.

In the Options under the Config tag there are two settings regarding the jpeg quality:
ZM_JPEG_FILE_QUALITY JPEG quality for the saved event files
and
ZM_JPEG_IMAGE_QUALITY JPEG quality for the streamed 'live' images

When I watch streaming of a camera (in any mode) changing the ZM_JPEG_FILE_QUALITY setting slows down or speeds up the streaming,
while changing ZM_JPEG_IMAGE_QUALITY which I thought was responsible for this doesn't do anything at all.

Did I miss something, or can other users reproduce this behaviour?
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

I have done research inti file sizes and collated average file sizes dependant upon compression rate. This was all done on the LiveCD. As you are increasing the compression this also increases the workload for the server so if you are slightly under powered this would cause a slow down as zm would drop frames to keep up.

James
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I will check this just in case anyway!

Phil
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I've checked and sure enough it is a bug! The following patch should fix it for now

Code: Select all

*** src/zm_image.cpp    12 Jul 2005 13:38:42 -0000      1.30
--- src/zm_image.cpp    22 Sep 2005 13:43:36 -0000
***************
*** 276,282 ****
        }
        jpeg_set_defaults(&cinfo);
        cinfo.dct_method = JDCT_FASTEST;
!       jpeg_set_quality(&cinfo, config.jpeg_file_quality, false);
        jpeg_start_compress(&cinfo, TRUE);
  
        JSAMPROW row_pointer;   /* pointer to a single row */
--- 276,282 ----
        }
        jpeg_set_defaults(&cinfo);
        cinfo.dct_method = JDCT_FASTEST;
!       jpeg_set_quality(&cinfo, config.jpeg_image_quality, false);
        jpeg_start_compress(&cinfo, TRUE);
  
        JSAMPROW row_pointer;   /* pointer to a single row */
I suspect this slipped in a version or two ago! Thanks to Matthias for finding this one.

Phil
scottles
Posts: 2
Joined: Fri Nov 18, 2005 10:59 am

Post by scottles »

I have just upgraded to to zoneminder v1.21.4 and have noticed that now the "ZM_JPEG_FILE_QUALITY" setting seems to have no effect on the quality of captured images that are saved to disk. It now seems to use the quality setting specified in "ZM_JPEG_IMAGE_QUALITY" for images saved to disk. I have spent some time experimenting with the settings to verify this. I was hoping to have "ZM_JPEG_FILE_QUALITY" set to 100 in order to ensure the images saved to disk are high quality and then have "ZM_JPEG_IMAGE_QUALITY" set to something pretty low like 30 to allow images to be streamed over lower bandwidth connection, but can not do this at present as it seems to actually be saving the images to disk at the quality specified in "ZM_JPEG_IMAGE_QUALITY". Has anyone else encountered this?
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I think you have actually found a bug with this one. The image quality setting works correctly but the file quality setting only works if you do not have the frame server option switched on. This is because in order to send the image to the frame server it is encoded in memory and then sent. Encoding in memory uses the image quality setting and not the file one.

This is obviously incorrect, though turning off the frame server is one workaround. I think the patch below should sort it properly.

Phil

Code: Select all

--- zm_image.h	17 Oct 2005 21:45:06 -0000	1.20
+++ zm_image.h	18 Nov 2005 17:13:22 -0000
@@ -192,9 +192,9 @@
 	}
 
 	bool ReadJpeg( const char *filename );
-	bool WriteJpeg( const char *filename ) const;
+	bool WriteJpeg( const char *filename, int quality_override=0 ) const;
 	bool DecodeJpeg( JOCTET *inbuffer, int inbuffer_size );
-	bool EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size ) const;
+	bool EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override=0 ) const;
 
 	void Overlay( const Image &image );
 	void Blend( const Image &image, int transparency=10 ) const;
--- zm_image.cpp	17 Oct 2005 21:45:06 -0000	1.32
+++ zm_image.cpp	18 Nov 2005 17:14:50 -0000
@@ -168,7 +168,7 @@
 	return( true );
 }
 
-bool Image::WriteJpeg( const char *filename ) const
+bool Image::WriteJpeg( const char *filename, int quality_override ) const
 {
 	if ( config.colour_jpeg_files && colours == 1 )
 	{
@@ -204,7 +204,7 @@
 	}
 	jpeg_set_defaults(&cinfo);
 	cinfo.dct_method = JDCT_FASTEST;
-	jpeg_set_quality(&cinfo, config.jpeg_file_quality, false);
+	jpeg_set_quality(&cinfo, quality_override?quality_override:config.jpeg_file_quality, false);
 	jpeg_start_compress(&cinfo, TRUE);
 
 	JSAMPROW row_pointer;	/* pointer to a single row */
@@ -269,7 +269,7 @@
 	return( true );
 }
 
-bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size ) const
+bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override ) const
 {
 	if ( config.colour_jpeg_files && colours == 1 )
 	{
@@ -298,7 +298,7 @@
 	}
 	jpeg_set_defaults(&cinfo);
 	cinfo.dct_method = JDCT_FASTEST;
-	jpeg_set_quality(&cinfo, config.jpeg_image_quality, false);
+	jpeg_set_quality(&cinfo, quality_override?quality_override:config.jpeg_image_quality, false);
 	jpeg_start_compress(&cinfo, TRUE);
 
 	JSAMPROW row_pointer;	/* pointer to a single row */
--- zm_event.cpp	16 Oct 2005 21:39:10 -0000	1.64
+++ zm_event.cpp	18 Nov 2005 17:15:44 -0000
@@ -194,7 +194,7 @@
 	static int jpg_buffer_size = 0;
 	static unsigned char jpg_buffer[ZM_MAX_IMAGE_SIZE];
 
-	image->EncodeJpeg( jpg_buffer, &jpg_buffer_size );
+	image->EncodeJpeg( jpg_buffer, &jpg_buffer_size, config.jpeg_file_quality );
 
 	static FrameHeader frame_header;
scottles
Posts: 2
Joined: Fri Nov 18, 2005 10:59 am

Post by scottles »

that patch seems to work great.. thanks :)
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Good. I've actually added quite a lot of new stuff in the last week or two so 1.21.5 probably won't be far off and will obviously include this.

Phil
Locked