diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 7a2048102..a3662c654 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -1090,14 +1090,16 @@ bool Image::WriteJpeg(const std::string &filename, const int &quality_override, SystemTimePoint timestamp, bool on_blocking_abort) const { - // jpeg libs are not thread safe - std::unique_lock lck(jpeg_mutex); if (config.colour_jpeg_files && (colours == ZM_COLOUR_GRAY8)) { Image temp_image(*this); temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB); return temp_image.WriteJpeg(filename, quality_override, timestamp, on_blocking_abort); } + + // jpeg libs are not thread safe + std::unique_lock lck(jpeg_mutex); + int quality = quality_override ? quality_override : config.jpeg_file_quality; jpeg_compress_struct *cinfo = writejpg_ccinfo[quality];