diff --git a/humble-video-native/src/main/gnu/src/io/humble/video/Encoder.cpp b/humble-video-native/src/main/gnu/src/io/humble/video/Encoder.cpp index 0b657a09..ce63cde2 100644 --- a/humble-video-native/src/main/gnu/src/io/humble/video/Encoder.cpp +++ b/humble-video-native/src/main/gnu/src/io/humble/video/Encoder.cpp @@ -400,29 +400,6 @@ Encoder::encodeAudio(MediaPacket* aOutput, MediaAudio* samples) { if (samples) { // make copy so we can modify meta-data inputAudio = MediaAudio::make(samples, false); - RefPointer inputAudioTb = inputAudio->getTimeBase(); - /** - * check time stamps and drop frames when needed if the time - * base of the input frame cannot be converted to the encoder - * time base without rounding. - * - */ - int64_t inTs = coderTb->rescale(inputAudio->getTimeStamp(), inputAudioTb.value(), Rational::ROUND_DOWN); - if (mLastPtsEncoded != Global::NO_PTS) { - if (inTs <= mLastPtsEncoded) { - VS_LOG_DEBUG( - "Encoder@%p Dropping frame with timestamp %lld (if coder supports higher time-base use that instead)", - this, - inputAudio->getPts()); - dropFrame = true; - } - } - if (!dropFrame) { - mLastPtsEncoded = inTs; - inputAudio->setTimeBase(coderTb.value()); - // set the timestamp after the timbase as setTimeBase does a conversion. - inputAudio->setTimeStamp(inTs); - } } if (!(codec->getCapabilities() & Codec::CAP_VARIABLE_FRAME_SIZE)) { // this codec requires that the right number of audio samples @@ -457,6 +434,31 @@ Encoder::encodeAudio(MediaPacket* aOutput, MediaAudio* samples) { } else inputAudio = 0; } + if (inputAudio) { + RefPointer inputAudioTb = inputAudio->getTimeBase(); + /** + * check time stamps and drop frames when needed if the time + * base of the input frame cannot be converted to the encoder + * time base without rounding. + * + */ + int64_t inTs = coderTb->rescale(inputAudio->getTimeStamp(), inputAudioTb.value(), Rational::ROUND_DOWN); + if (mLastPtsEncoded != Global::NO_PTS) { + if (inTs <= mLastPtsEncoded) { + VS_LOG_DEBUG( + "Encoder@%p Dropping frame with timestamp %lld (if coder supports higher time-base use that instead)", + this, + inputAudio->getPts()); + dropFrame = true; + } + } + if (!dropFrame) { + mLastPtsEncoded = inTs; + inputAudio->setTimeBase(coderTb.value()); + // set the timestamp after the timbase as setTimeBase does a conversion. + inputAudio->setTimeStamp(inTs); + } + } // now a sanity check if (!(!samples || !inputAudio || inputAudio->getNumSamples() == getFrameSize())) { VS_THROW(HumbleRuntimeError::make("not flushing, but samples returned (%ld) are less than frame size (%ld)",