Skip to content

Commit

Permalink
Fix bugs (introduced in PR cyberbotics#6622) when grabbing/recording …
Browse files Browse the repository at this point in the history
…with devicePixelRatio != 1. (cyberbotics#6638)

* Fix bug (introduced in PR cyberbotics#6622) when grabbing with devicePixelRatio != 1.

* Fix video recording size bug introduced by PR cyberbotics#6622.
  • Loading branch information
brettle authored Aug 26, 2024
1 parent 3485871 commit 3ec6560
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/webots/gui/WbVideoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ void WbVideoRecorder::stopRecording(bool canceled) {

void WbVideoRecorder::writeSnapshot(unsigned char *frame) {
QString fileName = nextFileName();
FrameWriterThread *thread =
new FrameWriterThread(frame, fileName, mVideoResolution * mScreenPixelRatio, mScreenPixelRatio, mVideoQuality);
FrameWriterThread *thread = new FrameWriterThread(frame, fileName, mVideoResolution, 1, mVideoQuality);
connect(thread, &QThread::finished, this, &WbVideoRecorder::terminateSnapshotWrite);
thread->start();
}
Expand Down Expand Up @@ -480,8 +479,8 @@ void WbVideoRecorder::createMpeg() {
if (ffmpegScript.open(QIODevice::WriteOnly)) {
// bitrate range between 4 and 24000000
// cast into 'long long int' is mandatory on 32-bit machine
long long int bitrate = (long long int)mVideoQuality * mMovieFPS * mVideoResolution.width() * mVideoResolution.height() /
256 / (mScreenPixelRatio * mScreenPixelRatio);
long long int bitrate =
(long long int)mVideoQuality * mMovieFPS * mVideoResolution.width() * mVideoResolution.height() / 256;

QTextStream stream(&ffmpegScript);
#ifndef _WIN32
Expand Down
12 changes: 5 additions & 7 deletions src/webots/gui/WbWrenWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,11 @@ QImage WbWrenWindow::grabWindowBufferNow() {
mSnapshotBufferHeight = destinationHeight;
mSnapshotBuffer = new unsigned char[4 * destinationWidth * destinationHeight];
}
const qreal ratio = devicePixelRatio();
const int sourceWidth = destinationWidth * ratio;
const int sourceHeight = destinationHeight * ratio;
const int sourceWidth = destinationWidth;
const int sourceHeight = destinationHeight;
unsigned char *temp = new unsigned char[4 * sourceWidth * sourceHeight];
readPixels(sourceWidth, sourceHeight, GL_BGRA, temp);
flipAndScaleDownImageBuffer(temp, mSnapshotBuffer, sourceWidth, sourceHeight, ratio);
flipAndScaleDownImageBuffer(temp, mSnapshotBuffer, sourceWidth, sourceHeight, 1.0);
delete[] temp;
WbWrenOpenGlContext::doneWren();

Expand All @@ -328,9 +327,8 @@ QImage WbWrenWindow::grabWindowBufferNow() {
void WbWrenWindow::initVideoPBO() {
WbWrenOpenGlContext::makeWrenCurrent();

const int ratio = (int)devicePixelRatio();
mVideoWidth = width() * ratio;
mVideoHeight = height() * ratio;
mVideoWidth = width();
mVideoHeight = height();
const int size = 4 * mVideoWidth * mVideoHeight;
wr_scene_init_frame_capture(wr_scene_get_instance(), PBO_COUNT, mVideoPBOIds, size);
mVideoPBOIndex = -1;
Expand Down

0 comments on commit 3ec6560

Please sign in to comment.