Skip to content

Commit 6abd914

Browse files
Implement libjpeg_to_ffmpeg_qv to fix quality settings of mjpeg output
1 parent 903fda0 commit 6abd914

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/zm_event.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ int Event::OpenJpegCodec(AVFrame *frame) {
202202
mJpegCodecContext->sw_pix_fmt = chosen_codec_data->sw_pix_fmt;
203203

204204
// Should be able to just set quality with the q setting. Need to convert the old quality to 2-31
205-
int quality = config.jpeg_file_quality;
205+
int quality = libjpeg_to_ffmpeg_qv(config.jpeg_file_quality);
206206

207207
//(alarm_frame && (config.jpeg_alarm_file_quality > config.jpeg_file_quality)) ?
208208
//config.jpeg_alarm_file_quality : 0; // quality to use, zero is default
209-
mJpegCodecContext->qcompress = quality/100.0; // 0-1
210-
mJpegCodecContext->qmax = 1;
211-
mJpegCodecContext->qmin = 1; //quality/100.0; // 0-1
212-
mJpegCodecContext->global_quality = quality/100.0; // 0-1
209+
//mJpegCodecContext->qcompress = quality/100.0; // 0-1
210+
//mJpegCodecContext->qmax = 1;
211+
//mJpegCodecContext->qmin = 1; //quality/100.0; // 0-1
212+
mJpegCodecContext->global_quality = quality;//100.0; // 0-1
213213

214214
Debug(1, "Setting pix fmt to %d %s, sw_pix_fmt %d %s",
215215
chosen_codec_data->sw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->sw_pix_fmt),
@@ -400,8 +400,10 @@ bool Event::WriteJpeg(AVFrame *in_frame, const std::string &filename) {
400400
if (!mJpegCodecContext) return false;
401401

402402
int raw_fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
403-
if (raw_fd < 0)
403+
if (raw_fd < 0) {
404+
Error("Fail to open %s: %s", filename.c_str(), strerror(raw_fd));
404405
return false;
406+
}
405407
FILE *outfile = fdopen(raw_fd, "wb");
406408
if (outfile == nullptr) {
407409
close(raw_fd);
@@ -730,7 +732,7 @@ void Event::AddFrame(const std::shared_ptr<ZMPacket>&packet) {
730732
(packet->image and WriteFrameImage(packet->image, packet->timestamp, snapshot_file.c_str()))
731733
) {
732734
snapshot_file_written = true;
733-
} else {
735+
} else if (packet->ai_frame or packet->in_frame or packet->image) {
734736
Warning("Fail to write snapshot");
735737
}
736738
} else {

0 commit comments

Comments
 (0)