Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change capture FPS #488

Closed
squareSphere29 opened this issue Apr 6, 2019 · 13 comments
Closed

Change capture FPS #488

squareSphere29 opened this issue Apr 6, 2019 · 13 comments

Comments

@squareSphere29
Copy link

Could you add a command line to change the capture fps (i.e. to 30fps)? I believe it is locked/capped at 60fps at the moment.

@rom1v
Copy link
Collaborator

rom1v commented Apr 6, 2019

I already tried some time ago, by requesting a specific FPS here, but it has no effect: the encoder takes one frame on every surface update (it's not a constant FPS).

@mtvg
Copy link

mtvg commented Nov 12, 2019

This would be an awesome feature, especially for over wifi capture. Slowing down to even lower fps would be great.
Is there any way to skip frames before it reaches the encoder, based on timestamp? So If the SurfaceFlinger is sending 60 frames in 1 second, only send a few to the encoder (making sure the last frame is sent after some timeout if no new frame is coming)

@rom1v
Copy link
Collaborator

rom1v commented Nov 12, 2019

This is supported since Android Q (KEY_MAX_FPS_TO_ENCODER):

diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
index 52f6f26..a55e84a 100644
--- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
@@ -6,6 +6,7 @@ import android.graphics.Rect;
 import android.media.MediaCodec;
 import android.media.MediaCodecInfo;
 import android.media.MediaFormat;
+import android.os.Build;
 import android.os.IBinder;
 import android.os.Looper;
 import android.view.Surface;
@@ -157,6 +158,9 @@ public class ScreenEncoder implements Device.RotationListener {
         format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval);
         // display the very first frame, and recover from bad quality when no new frames
         format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, MICROSECONDS_IN_ONE_SECOND * REPEAT_FRAME_DELAY / frameRate); // µs
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            format.setFloat(MediaFormat.KEY_MAX_FPS_TO_ENCODER, 10f);
+        }
         return format;
     }

@mtvg
Copy link

mtvg commented Nov 12, 2019

🤯 Thank you! Works perfectly, exactly what I was looking for.

rom1v added a commit that referenced this issue Nov 17, 2019
Add an option to limit the capture frame rate. It only works for devices
with Android >= 10.

Fixes <#488>
@rom1v
Copy link
Collaborator

rom1v commented Nov 17, 2019

Implemented --max-fps option on dev.

@rom1v rom1v closed this as completed Nov 17, 2019
@shiwf
Copy link

shiwf commented Dec 19, 2019

I've tried to set KEY_MAX_FPS_TO_ENCODER in AndroidO(Samsung Galalxy S7) and P(Samsung Galalxy S8+), they all could work. Actually, this key was available since O, they make it public until Android10.

rom1v added a commit that referenced this issue Dec 19, 2019
KEY_MAX_FPS_TO_ENCODER existed privately before Android 10:
<#488 (comment)>
@rom1v
Copy link
Collaborator

rom1v commented Dec 19, 2019

@shiwf Ah yes, it works even on Android 6.

Thank you: 83d4826

rom1v added a commit that referenced this issue Dec 19, 2019
KEY_MAX_FPS_TO_ENCODER existed privately before Android 10:
<#488 (comment)>
@vegaskukichyo
Copy link

vegaskukichyo commented Dec 22, 2019

Hi, thank you for this amazing tool. I use it for livestreaming mobile games. I do not have a high-end computer, so frames are skipped, but fps stays around 55-60. I stream at 30fps, so capping the output at 30fps would eliminate frame drop and improve the smoothness of my stream.

I am on Android 9 (OnePlus 7 Pro). I saw your commit with the added max-fps command for Android <10. I do not know how to compile the program, however. I use your pre-built archive, but I would like this option. Do I need to learn how and recompile the program, or could you upload a modified executable/server with this option? My archive already contains all dependencies, as with all of your prebuilt archives.

Thank you.

@rom1v
Copy link
Collaborator

rom1v commented Dec 22, 2019

I do not know how to compile the program, however.

BUILD

Do I need to learn how and recompile the program, or could you upload a modified executable/server with this option?

Sorry, I can't for now (holidays...).

@vegaskukichyo
Copy link

Thanks for your quick reply. It would be quite the effort and time for me to teach myself to build the program, even with your excellent instructions. I don't have much experience with any of that.

I hope you have a great holiday! Do you intend to implement these changes in a new version sometime soon (in the new year)? I hope so.

If I could donate even a few dollars to support your efforts and your project, I would also like to do that. I know you've put a lot of work into this.

Again, happy holidays, and thank you for all your hard work!

@rom1v
Copy link
Collaborator

rom1v commented Jan 3, 2020

  • scrcpy.exe
    SHA256: a81ee325c6cd03ff83d58b5900a9a8286c1fbec8685f67210c4e6830c2878159
  • scrcpy-server
    SHA256: 0ae5675a571e91a3d4ec900c51b29b15fcd5317cf76daf1ad875d4054c8f1a55

@vegaskukichyo
Copy link

Awesome, thank you! I just had an update come in that brought me to Android 10, though. I have a secondary device that I use sometimes that is on Android 9, so I will install this too. Thanks!

I hope you had a good holiday!

@rom1v
Copy link
Collaborator

rom1v commented Apr 29, 2020

@shiwf @vegaskukichyo Released in v1.13.

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

No branches or pull requests

5 participants