Skip to content

Commit e533074

Browse files
Implement libjpeg_to_ffmpeg_qv
1 parent 6abd914 commit e533074

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/zm_ffmpeg.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,15 @@ int zm_get_samples_from_fifo(AVAudioFifo *fifo, AVFrame *frame) {
800800
zm_dump_frame(frame, "Out frame after fifo read");
801801
return 1;
802802
}
803+
#include <algorithm> // for std::max and std::min
804+
805+
// Converts libjpeg quality [0-100] to ffmpeg -q:v [2-31] for MJPEG encoding
806+
int libjpeg_to_ffmpeg_qv(int libjpeg_quality) {
807+
// Clamp libjpeg_quality to valid range
808+
libjpeg_quality = std::max(0, std::min(100, libjpeg_quality));
809+
// Map libjpeg 0-100 to ffmpeg 31-2
810+
int ffmpeg_qv = 31 - static_cast<int>(libjpeg_quality * 29.0 / 100.0 + 0.5);
811+
// Clamp ffmpeg_qv to valid range
812+
ffmpeg_qv = std::max(2, std::min(31, ffmpeg_qv));
813+
return ffmpeg_qv;
814+
}

src/zm_ffmpeg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,6 @@ int setup_hwaccel(AVCodecContext *codec_ctx, const CodecData *codec_data,AVBuffe
356356
#ifdef HAVE_QUADRA
357357
int ni_get_cardno(const AVCodecContext *ctx);
358358
#endif
359+
int libjpeg_to_ffmpeg_qv(int libjpeg_quality);
359360

360361
#endif // ZM_FFMPEG_H

0 commit comments

Comments
 (0)