Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7131930 authored by Sultanxda's avatar Sultanxda Committed by Scott Mertz
Browse files

libstagefright: Scale up bitrate for HSR videos

Currently, bitrate is scaled up only for HFR (high-framerate recording) and not HSR (high-speed recording). Not scaling up the bitrate for HSR results in poor video quality.

Scale up the bitrate for HSR the same way that it is scaled up for HFR to fix the poor video quality.

CYNGNOS-952
Change-Id: I6ec82bafd1e90292886fe70555c6a9af07fc7826
parent 92820ed0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -120,6 +120,25 @@ status_t ExtendedUtils::HFR::initializeHFR(
    if (meta->findInt32(kKeyHSR, &hsr) && hsr > 0) {
        ALOGI("HSR cue found. Override encode fps to %d", hsr);
        format->setInt32("frame-rate", hsr);

        int maxBitRate;
        MediaProfiles *profiles = MediaProfiles::getInstance();
        maxBitRate = profiles->getVideoEncoderParamByName("enc.vid.bps.max", videoEncoder);
        if (maxBitRate < 0) {
            ALOGE("Failed to query max bitrate for HSR");
            return ERROR_UNSUPPORTED;
        }

        int32_t frameRate = 0, bitRate = 0;
        CHECK(meta->findInt32(kKeyFrameRate, &frameRate));
        CHECK(format->findInt32("bitrate", &bitRate));

        // scale the bitrate proportional to the hsr ratio
        // to maintain quality, but cap it to max-supported.
        bitRate = (hsr * bitRate) / frameRate;
        bitRate = bitRate > maxBitRate ? maxBitRate : bitRate;
        format->setInt32("bitrate", bitRate);

        return retVal;
    }