scrcpy
                                
                                 scrcpy copied to clipboard
                                
                                    scrcpy copied to clipboard
                            
                            
                            
                        [server] ERROR: Encoding error: java.lang.IllegalStateException: null WARN: Device disconnected
Environment
- OS: Windows 11
- scrcpy version: 1.23
- installation method: windows release
- device model: Redmi Note 10 Pro
- Android version: 12
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
C:\Users\Admin\Downloads\scrcpy-win64\scrcpy-ser...ed, 0 skipped. 16.1 MB/s (41123 bytes in 0.002s)
[server] INFO: Device: Xiaomi M2101K6G (Android 12)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2400
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(Unknown Source:9)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:152)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
        at com.genymobile.scrcpy.Server.main(Server.java:331)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(Unknown Source:24)
Press any key to continue . . .
that's all i got 2 device Redmi note 4x (it's work perfectly) Redmi note 10 Pro (as the error above)
EDIT by @rom1v: It looks like a bug in MIUI 13. You'll have to wait until Xiaomi fixes the issue.
EDIT: for new users, please ignore this comment, it was just an initial test to investigate the issue.
I added some logs. Could you replace this binary in v1.23 please, and post the output:
- scrcpy-serversha256:479228ed980190367875078a9979426f6e9067d8a395d4250dcf0be2469a76c6
diff
diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
index e95896d3..8b2e8707 100644
--- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
@@ -104,6 +104,7 @@ public class ScreenEncoder implements Device.RotationListener {
                     codec.stop();
                 } catch (IllegalStateException | IllegalArgumentException e) {
                     Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
+                    Ln.i("downsizeOnError=" + downsizeOnError + "; firstFrameSent=" + firstFrameSent);
                     if (!downsizeOnError || firstFrameSent) {
                         // Fail immediately
                         throw e;
@@ -166,6 +167,8 @@ public class ScreenEncoder implements Device.RotationListener {
                     IO.writeFully(fd, codecBuffer);
                     if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) {
                         // If this is not a config packet, then it contains a frame
+                        if (!firstFrameSent)
+                            Ln.i("FIRST FRAME SENT");
                         firstFrameSent = true;
                     }
                 }
C:\Users\Admin\Downloads\scrcpy-win32-v1.23\scrc...ed, 0 skipped. 36.4 MB/s (61061 bytes in 0.002s)
[server] INFO: Device: Xiaomi M2101K6G (Android 12)
INFO: Renderer: direct3d
[server] INFO: FIRST FRAME SENT
INFO: Initial texture: 1080x2400
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: downsizeOnError=true; firstFrameSent=true
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(Unknown Source:9)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:153)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
        at com.genymobile.scrcpy.Server.main(Server.java:331)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(Unknown Source:24)
WARN: Killing the server...
OK, thanks, that's what I thought.
So the encoder is able to produce one frame, then it fails… :( Maybe I should revert 2eb6fe7d81c15912a2252f229d317ae03f618a33.
Does it work if you execute scrcpy -m1024?
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>scrcpy -d -m1024
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
C:\Users\Admin\Downloads\scrcpy-win32-v1.23\scrc...ed, 0 skipped. 25.3 MB/s (61061 bytes in 0.002s)
[server] INFO: Device: Xiaomi M2101K6G (Android 12)
[server] INFO: FIRST FRAME SENT
INFO: Renderer: direct3d
INFO: Initial texture: 464x1024
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: downsizeOnError=true; firstFrameSent=true
WARN: Device disconnected
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(Unknown Source:9)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:153)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
        at com.genymobile.scrcpy.Server.main(Server.java:331)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(Unknown Source:24)``
still same got error lol.. i tried to change encoder to
    --encoder 'c2.android.avc.encoder'
    --encoder 'OMX.google.h264.encoder' 
but it's freeze frame
Does it work with screenrecord:
adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4
?
EDIT: fixed.
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>scrcpy --record file.mp4 -d
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
C:\Users\Admin\Downloads\scrcpy-win32-v1.23\scrc...ed, 0 skipped. 25.1 MB/s (61061 bytes in 0.002s)
[server] INFO: Device: Xiaomi M2101K6G (Android 12)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2400
[server] INFO: FIRST FRAME SENT
INFO: Recording started to mp4 file: file.mp4
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: downsizeOnError=true; firstFrameSent=true
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(Unknown Source:9)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:153)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
        at com.genymobile.scrcpy.Server.main(Server.java:331)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(Unknown Source:24)
INFO: Recording complete to mp4 file: file.mp4
WARN: Device disconnected
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>
did i use the right command?
 --record file.mp4
Sorry, I forgot adb shell:
adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4
Microsoft Windows [Version 10.0.22000.493]
(c) Microsoft Corporation. All rights reserved.
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>adb pull /sdcard/file.mp4
adb server version (39) doesn't match this client (41); killing...
* daemon started successfully
/sdcard/file.mp4: 1 file pulled, 0 skipped. 19.7 MB/s (1229492 bytes in 0.060s)
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4
is it right? or im too dumb on this command? ahhahaha i put the adb shell screenrecord /sdcard/file.mp4 1st
then nothing happen and i put adb pull /sdcard/file.mp4 on next
anyway its pull the file, i can see file.mp4 on the folder
anyway its pull the file, i can see file.mp4 on the folder
And it is correct? You can play it?
yes i can play it without problem
What's its resolution? Any logs when you record with screenrecord in your console?
If you reduce the definition even more?
scrcpy -m400
?
For some reason, your device encoder fails with the parameters scrcpy uses for encoding.
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>scrcpy -m400
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
* daemon not running; starting now at tcp:5037
* daemon started successfully
C:\Users\Admin\Downloads\scrcpy-win32-v1.23\scrc...hed, 0 skipped. 2.5 MB/s (61061 bytes in 0.023s)
[server] INFO: Device: Xiaomi M2101K6G (Android 12)
[server] INFO: FIRST FRAME SENT
INFO: Renderer: direct3d
[server] ERROR: Encoding error: java.lang.IllegalStateException: null
[server] INFO: downsizeOnError=true; firstFrameSent=true
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalStateException
        at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
        at android.media.MediaCodec.dequeueOutputBuffer(Unknown Source:9)
        at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:153)
        at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:101)
        at com.genymobile.scrcpy.Server.main(Server.java:331)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(Unknown Source:24)
INFO: Initial texture: 184x400
WARN: Device disconnected
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>adb shell screenrecord /sdcard/file.mp4
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>adb pull /sdcard/file.mp4
/sdcard/file.mp4: 1 file pulled, 0 skipped. 29.2 MB/s (206850495 bytes in 6.759s)
C:\Users\Admin\Downloads\scrcpy-win32-v1.23>
it's so sad on Redmi Note 10 Pro after update hahaha
You can play with the encoder settings: see https://github.com/Genymobile/scrcpy/issues/2819#issuecomment-976380273
Maybe you'll find what parameter your device does not like.
I have something similar when I try to mirror one of my Android devices:
scrcpy 1.23 https://github.com/Genymobile/scrcpy C:\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 29.7 MB/s (41123 bytes in 0.001s) adb.exe: error: more than one device and emulator ERROR: "adb reverse" returned with value 1 WARN: 'adb reverse' failed, fallback to 'adb forward' [server] INFO: Device: amltd TETON_P8303 (Android 5.0.2) INFO: Renderer: direct3d INFO: Initial texture: 800x480 [server] ERROR: Encoding error: java.lang.IllegalStateException: null WARN: Device disconnected [server] ERROR: Exception on thread Thread[main,5,main] java.lang.IllegalStateException at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method) at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:1033) at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:152) at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:102) at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:74) at com.genymobile.scrcpy.Server.scrcpy(Server.java:101) at com.genymobile.scrcpy.Server.main(Server.java:331) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:249)
same issue after update to android 12, any update?
I'm having the same issues in Redmi Note 10 Pro after updating to MIUI 13 and Android 12, any fixes found?
EDIT: changing the encoder works: --encoder 'OMX.google.h264.encoder' EDIT2: you can control the phone but it freezes on PC screen.
I am having the same issue on Redmi Note 10, MIUI 13 and Android 12... I just downloaded the Win64 "zip" version from release section, connected USB cable and opened "scrcpy-noconsole.vbs". It shows the screen for 1 second and as soon as I interact, it closes out.
Checking the "scrcpy-console.bat" file gave me the exact same error as OP as well. Here's the screenshot:

Probably a bug in their custom ROM (for Android 12). Scrcpy works fine with other Android 12 devices.
I am having the same issue on Redmi Note 10, MIUI 13 and Android 12... I just downloaded the Win64 "zip" version from release section, connected USB cable and opened "scrcpy-noconsole.vbs". It shows the screen for 1 second and as soon as I interact, it closes out.
Checking the "scrcpy-console.bat" file gave me the exact same error as OP as well. Here's the screenshot:
me redmi note 10(mojit) xiaomi.eu miui13 also the same , cant use scrcpy anymore ..
It seems a lot of people are having issues with the encoder lately and can't use scrcpy anymore. Hope the author finds a fix.
Hope the author finds a fix.
I have currently no device with this ROM to reproduce, but I think the fix is to wait for Xiaomi to fix the bug in the latest version of their custom rom. :/
Hope the author finds a fix.
I have currently no device with this ROM to reproduce, but I think the fix is to wait for Xiaomi to fix the bug in the latest version of their custom rom. :/
What's sad about this is it's gonna take months before this gets fixed for RN10/Xiaomi users haha. Understandable on your side tho. Thanks for the efforts!
Hope the author finds a fix.
I have currently no device with this ROM to reproduce, but I think the fix is to wait for Xiaomi to fix the bug in the latest version of their custom rom. :/
As I said in another comment, this is happening to me right now on my Xiaomi Mi A1 but not with MUI. I'm using LineageOS 18.1 (android 11) on this device. Before, on the same device, but with LineageOS 16.1 (android 9), it was working fine.
I don't know if, and how, this information would help tho
Hope the author finds a fix.
I have currently no device with this ROM to reproduce, but I think the fix is to wait for Xiaomi to fix the bug in the latest version of their custom rom. :/
As I said in another comment, this is happening to me right now on my Xiaomi Mi A1 but not with MUI. I'm using LineageOS 18.1 (android 11) on this device. Before, on the same device, but with LineageOS 16.1 (android 9), it was working fine.
I don't know if, and how, this information would help tho
Ok, I don't know if I'm doing it well with github (not used on commenting here), but I'm managed to make it work.
I notice that, when using another encoder, scrcpy would just stop executing itself without any error :
scrcpy --encoder OMX.qcom.video.encoder.avc
Gave me this :
scrcpy 1.23 <https://github.com/Genymobile/scrcpy>
C:\XXX\scrcpy-win64-v1.... file pushed, 0 skipped. 51.4 MB/s (41123 bytes in 0.001s)
[server] INFO: Device: Xiaomi Mi A1 (Android 11)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x1920
But nothing else.
But if I run scrcpy again (without any command parameter, just clicking scrcpy.exe) while the other instance is running, it works perfectly fine ! I have no idea why, but maybe that could help someone here.
still same problem but on android 12 based miui 13 redmi note 10 pro.
Microsoft Windows [Version 10.0.19044.1586] (c) Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>scrcpy --encoder OMX.qcom.video.encoder.avc scrcpy 1.22 https://github.com/Genymobile/scrcpy D:\scrcpy-win64-v1.22\scrcpy-server: 1 file pushed, 0 skipped. 10.7 MB/s (40955 bytes in 0.004s) [server] INFO: Device: Xiaomi M2101K6G (Android 12) INFO: Renderer: direct3d INFO: Initial texture: 1080x2400 [server] ERROR: Encoding error: java.lang.IllegalStateException: null WARN: Device disconnected [server] ERROR: Exception on thread Thread[main,5,main] java.lang.IllegalStateException at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method) at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3535) at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:147) at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:99) at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73) at com.genymobile.scrcpy.Server.scrcpy(Server.java:100) at com.genymobile.scrcpy.Server.main(Server.java:326) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:363)
C:\WINDOWS\system32>
I have the same problem, aunt. I hope to be able to solve it soon. Thanks for the application is very good to be free
Just like what I said in the issue I opened prior to this, using scrcpy --encoder 'OMX.google.h264.encoder' works for a few frames then hangs. Is there anyway to refresh the frames every n seconds? I tried opening in Vysor and whenever I change the resolution, the frozen frame updates
i have the same problem. with my xiaomi redmi note 10 pro.... :(
Same issue, Redmi Note 8