diff --git a/src/MediaFX/encoder.cpp b/src/MediaFX/encoder.cpp index 617b3f8..63ab618 100644 --- a/src/MediaFX/encoder.cpp +++ b/src/MediaFX/encoder.cpp @@ -76,6 +76,7 @@ void Encoder::setFrameSize(const QSize& frameSize) return; } m_frameSize = frameSize; + m_frameByteSize = frameSize.width() * frameSize.height() * 4; emit frameSizeChanged(); } } @@ -193,6 +194,16 @@ bool Encoder::encode(const QAudioBuffer& audioBuffer, const QByteArray& videoDat emit encodingError(); return false; } + if (audioBuffer.format().sampleRate() != sampleRate()) { + qmlWarning(this) << "Audio buffer has incorrect sampleRate"; + emit encodingError(); + return false; + } + if (videoData.size() != m_frameByteSize) { + qmlWarning(this) << "Video buffer has incorrect byte size"; + emit encodingError(); + return false; + } AVPacket* videoPacket = m_videoStream->packet(); videoPacket->flags |= AV_PKT_FLAG_KEY; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-type-reinterpret-cast) diff --git a/src/MediaFX/encoder.h b/src/MediaFX/encoder.h index dfb027d..87bb36f 100644 --- a/src/MediaFX/encoder.h +++ b/src/MediaFX/encoder.h @@ -71,6 +71,7 @@ public slots: bool m_isValid = false; QSize m_frameSize; + int m_frameByteSize = 0; Rational m_frameRate = DefaultFrameRate; int m_sampleRate = DefaultSampleRate; QString m_outputFileName;