diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp
index b4c9270129958ca278010867d77e2b722e45a361..b1fbb3c6ffde51804f632d74dfcfe0f3bb2c9e7e 100644
--- a/src/media/media_encoder.cpp
+++ b/src/media/media_encoder.cpp
@@ -726,7 +726,7 @@ MediaEncoder::setBitrate(uint64_t br)
 
     std::lock_guard<std::mutex> lk(encMutex_);
     // No need to restart encoder for h264, h263 and MPEG4
-    // Change parameters on the fly  
+    // Change parameters on the fly
     if(codecId == AV_CODEC_ID_H264)
         initH264(encoderCtx, br);
     else if(codecId == AV_CODEC_ID_H263P)
@@ -785,6 +785,7 @@ MediaEncoder::initVP8(AVCodecContext* encoderCtx, uint64_t br)
     encoderCtx->slices = 2; // VP8E_SET_TOKEN_PARTITIONS
     encoderCtx->qmin = 4;
     encoderCtx->qmax = 56;
+    crf = std::min(encoderCtx->qmax, std::max((int)crf, encoderCtx->qmin));
     libav_utils::setDictValue(&options_, "crf", std::to_string(crf));
     av_opt_set_int(encoderCtx, "crf", crf, AV_OPT_SEARCH_CHILDREN);
     encoderCtx->rc_buffer_size = bufSize;
@@ -907,4 +908,4 @@ MediaEncoder::readConfig(AVDictionary** dict, AVCodecContext* encoderCtx)
     }
 }
 
-} // namespace jami
\ No newline at end of file
+} // namespace jami