Skip to content

Android: record at real screen resolution#140

Open
jymden wants to merge 3 commits into
Isvisoft:masterfrom
jymden:fix-android-resolution
Open

Android: record at real screen resolution#140
jymden wants to merge 3 commits into
Isvisoft:masterfrom
jymden:fix-android-resolution

Conversation

@jymden

@jymden jymden commented Jun 5, 2026

Copy link
Copy Markdown

This PR updates Android screen recording to use the device’s real physical display resolution instead of downscaling to a fixed maximum size. The recording size is now calculated dynamically from the display metrics, with even-number rounding for encoder compatibility.

It also updates the bitrate based on pixel count and ensures the same width/height are used for both MediaRecorder and VirtualDisplay, avoiding scaling or cropping mismatches. Tested on Samsung Galaxy S24 / Android 16 with and without microphone audio.

Also updated some dependencies.

Summary by CodeRabbit

  • Improvements

    • Enhanced screen recording: more accurate resolution detection (including older Android devices), rounding to encoder-friendly dimensions, and dynamic bitrate calculation for better recording quality and stability.
    • Minor formatting and stability tweaks to reduce recording issues across device types.
  • Chores

    • Updated flutter_foreground_task dependency to a newer compatible version.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2525250f-14d4-421b-8368-593845ae73b5

📥 Commits

Reviewing files that changed from the base of the PR and between b251260 and a87e9cb.

📒 Files selected for processing (1)
  • flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt

📝 Walkthrough

Walkthrough

This PR refactors the Android screen recording plugin to improve display metrics collection and introduce dynamic bitrate computation. The plugin now obtains display dimensions via the activity's window manager, calculates resolution using physical pixels with even-number rounding, and computes encoder bitrate dynamically based on total pixel count instead of using fixed values.

Changes

Android screen recording encoder optimization

Layer / File(s) Summary
Display metrics retrieval and resolution calculation
flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt
For Android < API 30, DisplayMetrics is populated via windowManager.defaultDisplay?.getRealMetrics() instead of appContext.display. Class declaration formatting and small whitespace edits included. Resolution now uses physical pixel dimensions directly and rounds width/height to even numbers, removing prior max-resolution scaling logic.
Bitrate calculation and encoder parameter setup
flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt
New calculateBitrate(width, height) helper selects bitrate tiers based on total pixel count. MediaRecorder encoding bitrate is set using this function instead of the previous fixed formula.
Dependency version update
flutter_screen_recording/pubspec.yaml
flutter_foreground_task dependency bumped from ^9.1.0 to ^9.2.2.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through pixels bright,
Where metrics flow and bitrates bite,
From appContext to windows true,
Even numbers make encoding new,
Dependent tasks hop ever right! 🎬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Android: record at real screen resolution' clearly and concisely summarizes the main change: switching Android screen recording to use device's real physical display resolution instead of a downscaled approach.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt (1)

160-166: 💤 Low value

Remove dead commented code.

The commented-out code at lines 160-162 is no longer needed and should be deleted to keep the codebase clean.

♻️ Suggested cleanup
                    } else {
-//                        `@SuppressLint`("NewApi")
-//                        val defaultDisplay = appContext.display
-//                        defaultDisplay?.getMetrics(metrics)
                        `@Suppress`("DEPRECATION")
                        val defaultDisplay = activityBinding!!.activity.windowManager.defaultDisplay
                        `@Suppress`("DEPRECATION")
                        defaultDisplay?.getRealMetrics(metrics)
                    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt`
around lines 160 - 166, Remove the dead commented-out block that references
appContext.display and getMetrics (the commented `@SuppressLint`("NewApi") lines)
in FlutterScreenRecordingPlugin.kt; keep the working code that uses
activityBinding!!.activity.windowManager.defaultDisplay and
defaultDisplay?.getRealMetrics(metrics) (variables: appContext, activityBinding,
defaultDisplay, metrics) so the file contains no obsolete commented code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt`:
- Around line 160-166: Remove the dead commented-out block that references
appContext.display and getMetrics (the commented `@SuppressLint`("NewApi") lines)
in FlutterScreenRecordingPlugin.kt; keep the working code that uses
activityBinding!!.activity.windowManager.defaultDisplay and
defaultDisplay?.getRealMetrics(metrics) (variables: appContext, activityBinding,
defaultDisplay, metrics) so the file contains no obsolete commented code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d8a7fd27-b0a4-4c20-af65-046dbe104d38

📥 Commits

Reviewing files that changed from the base of the PR and between 358745e and b251260.

⛔ Files ignored due to path filters (1)
  • flutter_screen_recording/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • flutter_screen_recording/android/src/main/kotlin/com/isvisoft/flutter_screen_recording/FlutterScreenRecordingPlugin.kt
  • flutter_screen_recording/pubspec.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant