Skip to content

Commit fe8fb87

Browse files
author
Daniel Flores
committed
more sensible qscale lower bound
1 parent ee40602 commit fe8fb87

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,12 @@ void VideoEncoder::initializeEncoder(
640640
// For codecs that don't support CRF (mpeg4, flv1),
641641
// use quality-based encoding via global_quality + qscale flag
642642
avCodecContext_->flags |= AV_CODEC_FLAG_QSCALE;
643-
// While qscale is similar to crf, it is likely not interchangeable.
644-
// Reuse of crf below is only intended to work in VideoEncoder tests where
645-
// crf = 0
646-
avCodecContext_->global_quality =
647-
FF_QP2LAMBDA * videoStreamOptions.crf.value();
643+
// Reuse of crf below is only intended to work in tests where crf = 0
644+
// Use qmin as lower bound for best possible quality
645+
int qp = videoStreamOptions.crf.value() <= avCodecContext_->qmin
646+
? avCodecContext_->qmin
647+
: videoStreamOptions.crf.value();
648+
avCodecContext_->global_quality = FF_QP2LAMBDA * qp;
648649
}
649650
int status = avcodec_open2(avCodecContext_.get(), avCodec, &options);
650651
av_dict_free(&options);

0 commit comments

Comments
 (0)