-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Is there a way to capture only a frame or screenshot rather than a video stream? #684
Comments
does ascreenshot not accomplish what you need? |
It requires some investigations to do it in Java without an Android context (I have no time to do this now). Sometimes, the implementation of an existing command may help:
But in this case, it's implemented in C++: https://github.com/aosp-mirror/platform_frameworks_base/blob/master/cmds/screencap/screencap.cpp |
This is what I am wanting, I am not sure what you are suggesting.
This is similar to what I was already using, but with the stdout captured by the process and handled without writing to disk. This method, however does take about 1-2 seconds to work. I did find a method that allows me to access a screenshot in about 0.07s. Which is much better, giving me about 14 fps maximum. Not ideal, but much better than using the screencap shell command.
|
Sorry, I thought I was in the wrong repo. I know that https://github.com/IntergalacticPenguin/mobile-toolkit has a feature to take screenshots that works pretty well for me. But I believe they are using screencap under the hood, so if that does not work for your use case then it may not work for you. |
I looked into this a little bit more, and found that Something of this sort: try{
Process process = Runtime.getRuntime().exec("/system/bin/screencap");
BufferedReader ob = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int currentChar;
while (( currentChar = ob.read()) != -1) {
buffer.putChar((char) currentChar);
}
} catch(Exception e){
System.out.println(e);
} But this is about as fast as calling I am wondering, how is Am I missing something fundamental? |
As you mentioned above, that's exactly what I've implemented in DroidCast.
IMO, the reason behind this is IPC (via Android binder) seems more efficient than creating new Process and then getting the job done. |
One good reason to add this feature directly to scrcpy is that some applications block taking a screenshot, and this affects the adb |
Yes.
What is the exact command you execute? Did you try with:
? |
Actually, I just did
I'll have to see if those behave differently, though I don't understand why they would. Edit: actually, I think you have a typo. Shouldn't those commands be:
Both of these result in empty files for me with protected apps. Both work on the home screen. |
I can confirm that I'm having the same issue. Is there any way to solve it? |
In case anyone else is looking for a workaround: scrcpy -r tmp.mp4
ffmpeg -i tmp.mp4 -vframes 1 sshot.png Taking a screenshot of the streaming window is of course also an option (and results in better quality). |
This pull request will capture a screenshot. |
Almost there... In my case it's always generating a screenshot with a "Refreshing..." toast message, as you can see in the screenshot below: |
On Windows, this can be run with PowerShell:
The screenshot will be saved on your default "Pictures" folder, usually at |
I'm late to the party but I use this to take a screenshot and generate a time base name, so we can take any number of screenshots without worrying about the name or avoiding to replace a screenshot already taken.
|
@danfmaia - "Refreshing..." originates from React Native's Fast Refresh, which is triggered because you are outputting a new file into the current folder (which is monitored by watchman).
|
produces a weird png file which cannot be open. A normal png starts with magic number |
Windows PowerShell only writes UTF-16: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_character_encoding?view=powershell-7.4#character-encoding-in-windows-powershell Either upgrade to PowerShell (previously known as PowerShell core) or use cmd. |
@yume-chan Thanks, that works. PS Core 7.4.2 (Windows Terminal) and CMD. |
I am looking for a minimalized version of what the video stream part of scrcpy does.
It is apparently not so straightforward to take a screenshot of an android device outside of the android context. I imagine similar frustrations occurred while learning how to attain the video stream. Is there a way to only attain one frame or a screenshot at the time of a request?
The text was updated successfully, but these errors were encountered: