Skip to content

Commit 3ec6560

Browse files
authored
Fix bugs (introduced in PR #6622) when grabbing/recording with devicePixelRatio != 1. (#6638)
* Fix bug (introduced in PR #6622) when grabbing with devicePixelRatio != 1. * Fix video recording size bug introduced by PR #6622.
1 parent 3485871 commit 3ec6560

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/webots/gui/WbVideoRecorder.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ void WbVideoRecorder::stopRecording(bool canceled) {
345345

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

486485
QTextStream stream(&ffmpegScript);
487486
#ifndef _WIN32

src/webots/gui/WbWrenWindow.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,11 @@ QImage WbWrenWindow::grabWindowBufferNow() {
313313
mSnapshotBufferHeight = destinationHeight;
314314
mSnapshotBuffer = new unsigned char[4 * destinationWidth * destinationHeight];
315315
}
316-
const qreal ratio = devicePixelRatio();
317-
const int sourceWidth = destinationWidth * ratio;
318-
const int sourceHeight = destinationHeight * ratio;
316+
const int sourceWidth = destinationWidth;
317+
const int sourceHeight = destinationHeight;
319318
unsigned char *temp = new unsigned char[4 * sourceWidth * sourceHeight];
320319
readPixels(sourceWidth, sourceHeight, GL_BGRA, temp);
321-
flipAndScaleDownImageBuffer(temp, mSnapshotBuffer, sourceWidth, sourceHeight, ratio);
320+
flipAndScaleDownImageBuffer(temp, mSnapshotBuffer, sourceWidth, sourceHeight, 1.0);
322321
delete[] temp;
323322
WbWrenOpenGlContext::doneWren();
324323

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

331-
const int ratio = (int)devicePixelRatio();
332-
mVideoWidth = width() * ratio;
333-
mVideoHeight = height() * ratio;
330+
mVideoWidth = width();
331+
mVideoHeight = height();
334332
const int size = 4 * mVideoWidth * mVideoHeight;
335333
wr_scene_init_frame_capture(wr_scene_get_instance(), PBO_COUNT, mVideoPBOIds, size);
336334
mVideoPBOIndex = -1;

0 commit comments

Comments
 (0)