Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.75k stars 10.47k forks source link

Fails to initialize on Android Wear smartwatch #82

Closed parkerlreed closed 6 years ago

parkerlreed commented 6 years ago
[parker@gpdpocket x]$ scrcpy 
/usr/local/share/scrcpy/scrcpy-server.jar: 1 file pushed. 2.5 MB/s (19334 bytes in 0.007s)
ERROR: Exception on thread Thread[main,5,main]
java.lang.IllegalArgumentException: Failed to initialize video/avc, error 0xfffffffe
        at android.media.MediaCodec.native_setup(Native Method)
        at android.media.MediaCodec.<init>(MediaCodec.java:1776)
        at android.media.MediaCodec.createEncoderByType(MediaCodec.java:1742)
        at com.genymobile.scrcpy.ScreenEncoder.createCodec(ScreenEncoder.java:115)
        at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:57)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:22)
        at com.genymobile.scrcpy.Server.main(Server.java:78)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
Invalid return value 0 for stream protocol
Invalid return value 0 for stream protocol
Invalid return value 0 for stream protocol
Invalid return value 0 for stream protocol
Invalid return value 0 for stream protocol
ERROR: Could not open video stream
INFO: Initial texture: 320x320

Asus Zenwatch 2 on Android Wear 2.0.

rom1v commented 6 years ago

I don't have a smart watch, but the documentation of createEncoderByType() says:

Note: It is preferred to use findEncoderForFormat(MediaFormat) and createByCodecName(String) to ensure that the resulting codec can handle a given format.

Maybe you could try replacing this call as suggested. Not sure it will work better.

parkerlreed commented 6 years ago

Is there a way to query what it supports via adb?

parkerlreed commented 6 years ago

I got my environment setup so I can build the server. What exactly would I change in that call to test it out?

parkerlreed commented 6 years ago

I just realized the watch has NO encoders. Only decoders. screen1

That's probably the issue.

parkerlreed commented 6 years ago

Thanks, was going to close it out myself as I assumed there wasn't really anything that could be done for it.

rom1v commented 6 years ago

Maybe you could test using screenrecord:

adb shell screenrecord /sdcard/file.mp4
elig0n commented 6 years ago

@parkerlreed how does one get to that codec information on android please ?

parkerlreed commented 6 years ago

@elig0n Just an application that shows it. At the time I just found a random application online but it seems there's one on the store https://play.google.com/store/apps/details?id=net.tyniw.mediacodecinfo.application

rom1v commented 6 years ago

@parkerlreed Does screenrecord work for you (like @elig0n)?

parkerlreed commented 6 years ago

@rom1v I seem to have my charger but not my watch... I'll see if I can dig it out and give it a test.

rom1v commented 6 years ago

@parkerlreed I just created a project to give more infos about video codecs available: CheckVideoCodecs.

Please post its results for your watch.

kaushiknadig commented 6 years ago

Hi, I faced the same error above. and @rom1v I tried screen record. It says the following.

ERROR: unable to create video/avc codec instance
WARNING: failed at 454x454, retrying at 1280x720
ERROR: unable to create video/avc codec instance

Seems like android wear watches does not have encoders at all.

parkerlreed commented 5 years ago

This was never Android 4. Most watches were on Marshmallow at the time (and I'm hitting the same on Nougat)

Also sorry for the late response. Just circled back around to this. I am unable to build the CheckVideoCodecs

[parker@stealth CheckVideoCodecs]$ make run 
./gradlew assembleDebug

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
make: *** [Makefile:8: build] Error 1
andreluigo commented 5 years ago

I am facing the same issue with my Amazfit Stratos... I lost touch function and need to confirm the code on the screen to pair the watch again but i am getting these erros:

C:\Windows\system32>"D:\Downloads\Compressed\scrcpy-win64-v1.9\scrcpy-win64\scrcpy.exe" D:\Downloads\Compressed\scrcpy-win64-v1.9\scrcpy-win64\scr...erver.jar: 1 file pushed. 2.0 MB/s (22470 bytes in 0.011s) INFO: Initial texture: 320x296 ERROR: Could not open video stream

Other times:

C:\Windows\system32>"D:\Downloads\Compressed\scrcpy-win64-v1.9\scrcpy-win64\scrcpy.exe" D:\Downloads\Compressed\scrcpy-win64-v1.9\scrcpy-win64\scr...erver.jar: 1 file pushed. 3.2 MB/s (22470 bytes in 0.007s) [server] ERROR: Exception on thread Thread[main,5,main] java.lang.IllegalArgumentException: Failed to initialize video/avc, error 0xfffffffe at android.media.MediaCodec.native_setup(Native Method) at android.media.MediaCodec.(MediaCodec.java:486) at android.media.MediaCodec.createEncoderByType(MediaCodec.java:456) at com.genymobile.scrcpy.ScreenEncoder.createCodec(ScreenEncoder.java:137) at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:62) at com.genymobile.scrcpy.Server.scrcpy(Server.java:32) at com.genymobile.scrcpy.Server.main(Server.java:133) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:249) ERROR: Could not open video stream INFO: Initial texture: 320x296

Some can help me please? Tested at Galaxy S8 and worked like a charm.

rom1v commented 5 years ago

@andreluigo Is it Android 4?

Anyway, it seems "smart watches" don't have a H.264 encoder.

andreluigo commented 5 years ago

@andreluigo Is it Android 4?

No. It's newer. Actually O.S. of Amazfit is Watch 2.0 (based on Android, i guess).

odbol commented 3 years ago

I wonder if this could be fixed by using "video/raw" encoding instead of "video/avc"? Wear does support raw video encoding, and ffmpeg can convert it: https://developer.android.com/training/wearables/apps/debugging?hl=en#screenrecord

msugakov commented 2 years ago

This issue seems closed but I'm failing to find a solution. What's the way to make it work with Wear OS?

parkerlreed commented 2 years ago

There's nothing special. You just need a watch that is new enough to support it (hardware video encoding). Works right away on my Galaxy Watch4 Classic.