Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.52k stars 10.45k forks source link

Recorded or Displayed video puts some older frames after more recent frames – [feature request] option to select encoder #666

Open cmcguirk opened 5 years ago

cmcguirk commented 5 years ago

I downloaded scrcpy 1.9 on 7/24/2019 with the goal of recording video from my Droid Turbo onto my Windows 7 x64 PC. When I connect with USB and run scrcpy and have it display to my screen, and the video from the phone has a lot of motion, it's common for the display from scrcpy to periodically appear to show maybe 1 frame that probably would have been the correct frame to display about 1/10 of a second ago. So whatever motion was happening appears to jump backwards to where it would have been maybe 1/10th of a second ago for just one frame and then jump back to what the phone is currently displaying; it's a very jarring appearance. Depending on the size I am displaying with scrcpy, these frame jumps may happen as frequently as once a second. If I reduce the display size very small like scrcpy --max-size 400, the frame jumps are less frequent, but they still happen occasionally, maybe a few times every 10 seconds.

I have had my phone display its CPU and memory usage while running this, and it seems to display around 15.00/14.00/14.00 as the CPU usage and the bar only seems to go around 15% across the screen so I interpret that as 15% CPU usage. The phone memory remains with over 1 GB free while this happens. My PC CPU usage is only around 5% while it happens, and only 4 out of 8 GB of memory are in use; these are when I'm running scrcpy --max-size 1920.

I also tried having scrcpy do the file recording. I ran one with mp4 and one with mkv, with the --no-display option so it wouldn't need to do double work, but the mp4 and mkv files it created still have the same kinds of frame jumps I would see in the live display. I play the files in VLC, and I've checked that I'm not just getting some kind of playback issue with the mp4 and mkv files by advancing individual frames in VLC and I can still see the motion get jumped backwards for a frame.

I do not usually run it with --render-expired-frames, and when I've tried it, the frame jumps seem just as frequent, possibly more frequent. When I use ctrl+i, I often see skipped frames, but I am fairly certain I have observed these frame jumps in the display even during periods where no skipped frames are logged. The display on the phone itself always looks perfect during the whole thing, and the game doesn't feel any less responsive than it would while scrcpy was not running.

Do you have any suggestions to get it where it doesn't end up displaying or recording an older frame after it has already displayed/recorded a newer frame? I can probably share the mp4 and mkv file with google drive or something later if that would help.

cmcguirk commented 5 years ago

I was able to modify the client code and add logging statements, and I was able to determine that even though I still see the visual issue where periodically an image that would have been appropriate a fraction of a second earlier is briefly displayed, all of the PTS (Presentation Timestamp) values are being received in ascending order as they are read from the socket, and the AvPackets are processed in that same order. The bytes remaining read from the meta header for each frame matches the size of each AvPacket as it's being processed too. So I have to suspect that the problem is somewhere in the phone side; it seems to be producing the PTS values in ascending order, and without any excessive gaps in PTS value, so probably it's periodically putting out incorrect video data for some of the frames it's choosing to put out.

It might be worth noting that I've tried recording this phone screen with a couple phone apps, such as APowerRec and AZ Screen Record, and they seem to produce MP4 recordings with what looks like the same kind of visual issue. And my phone's Android version is 6.0.1.

rom1v commented 5 years ago

Oh! I never received a mail notification for this issue, I didn't see it.

Do you have any suggestions to get it where it doesn't end up displaying or recording an older frame after it has already displayed/recorded a newer frame?

My first guess would be your encoder producing out-of-order frames (B-frames), not correctly managed by scrcpy. Since we want the lowest possible latency, we want frames in order anyway.

It seems they added things related to frames out-of-order recently, and Android O and P briefly enabled B-frames: https://stackoverflow.com/a/55856811/1987178 https://developer.android.com/reference/android/media/MediaFormat.html#KEY_MAX_B_FRAMES https://developer.android.com/reference/android/media/MediaFormat.html#KEY_OUTPUT_REORDER_DEPTH

However:

t might be worth noting that I've tried recording this phone screen with a couple phone apps, such as APowerRec and AZ Screen Record, and they seem to produce MP4 recordings with what looks like the same kind of visual issue.

What about:

adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4

?

I can probably share the mp4 and mkv file with google drive or something later if that would help.

Yes, please :+1:

cmcguirk commented 5 years ago

I think when I first posted the issue my github account was flagged, since I hadn't used it in several years, so it probably didn't notify for it.

video.mp4 I most recently recorded this file using server code that I built locally with additional logging statements. It has fewer noticeable frame jumps, but the 8th frame or so seems to have a jump back. I've attached log files which are from the recording of this file too.

file.mp4 My older file.mp4 file.mkv My older file.mkv, the issue is much more obvious in these files

serverLog.txt socketReceiveLog3.txt avFrameLog3.txt

The PTS were ascending on the server, I logged the list of buffer flags and the hashCode of the codecBuffer before using it to write its contents to the socket. The hashCode values of each packet was unique, so it seems like it's not a duplication of a previous frame.

When I do:

adb shell screenrecord /sdcard/file.mp4
adb pull /sdcard/file.mp4

The resulting mp4 file looks very similar to the file.mp4 file shared above.

cmcguirk commented 5 years ago

I tried changing a few more things to see if anything would help. I tried MediaCodec.flush() after each MediaCodec.releaseOutputBuffer, that makes all the frames into keyframes, which makes the video more blurry, and does not prevent the frame jumps. I tried setting the ScreenEncoder.DEFAULT_FRAME_RATE to 30, which allowed me to go 10 seconds on the title screen without any issues, but then when I tried to play the game which does a lot more graphical stuff the issues came back. Setting the DEFAULT_FRAME_RATE to 30 still produced more than 30 frames in each second, it seemed to produce around 40 frames each second. I tried setting it to 15 fps, but it still had lots of graphical issues recording gameplay; the resulting video file from that 15 fps setting seems to produce a file with about 30 frames each second.

I suspect one of the ways that the gameplay for this game becomes more demanding on the recording system is that it probably uses a very large number of layers to display things. So it might be that the problem becomes worse the more layers are in use by the display. I don't know if there are any options to mitigate that.

rom1v commented 5 years ago

This is probably a bug in your hardware encoder :(

null-dev commented 5 years ago

I have a similar issue on LineageOS 16 on my OnePlus 3. What's really strange however, is that it doesn't happen on the stock ROM.

cmcguirk commented 5 years ago

I tried a few more things that didn't help, and then I thought to try having the server use a different codec to encode the video. I had my phone list out all of its encoders and the mimeTypes they support by adding

          MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
          MediaCodecInfo[] infoList = codecList.getCodecInfos();
          for (int i = 0; i < infoList.length; i++) {
              MediaCodecInfo codecInfo = infoList[i];

              if (!codecInfo.isEncoder()) {
                  continue;
              }

              Ln.i(codecInfo.getName());
              String[] types = codecInfo.getSupportedTypes();

              for (int j = 0; j < types.length; j++) {
                  Ln.i("supports " + types[j]);
              }

And at first I wanted to try "OMX.google.vp8.encoder", since vp8 sounded like a different family of codec, but I couldn't figure out how to get the libav part on the client app to like what my phone was sending to it. That vp8 encoder was not sending a CodecConfig packet at the start, which seemed weird, and I stopped trying with that.

But I noticed that my phone listed 2 encoders that both support mimeType "video/avc", they were named "OMX.qcom.video.encoder.avc" and "OMX.google.h264.encoder". The qcom encoder came up first when iterating, so I suspected when I used the unmodified scrcpy that the encoding was handled by that codec, and when I modified it to explicitly use that codec name for the encoder, I got the same results. When I change it to specify "OMX.google.h264.encoder", I no longer get the frame jumps. The video comes out quite well when I use that codec.

I think it might be worth considering some kind of option to specify the codec, or something that lists the video/avc codecs on the phone and lets you pick.

rom1v commented 4 years ago

(Just a reminder)

To list the encoders/decoders:

adb shell cat /system/etc/media_codecs.xml
sshock commented 4 years ago

There seem to be a lot of issues on this (#465, #1022, #1103), so I apologize if this is not the correct one to comment under. But hey, it's "666" and it's still open, so... how can I resist?

I too am running into the IllegalStateException with some new android devices (running android 9) I have and it is resolved by using scrcpy -m1024. (I did also try the scrcpy-server build you made with the KEY_FRAME_RATE changed to 30, but that didn't help.)

So for now I'll stick with the -m 1024 workaround. But here are some details that maybe will help for a long-term fix (since it would be a tragedy to have to type that in every day for the rest of my life).

Here's what the error looks like on my laptop running scrcpy:

2020-02-20 01:40:02.524 scrcpy[20694:77713] INFO: scrcpy 1.12.1 <https://github.com/Genymobile/scrcpy>
/usr/local/Cellar/scrcpy/1.12.1/share/s...ushed. 1.2 MB/s (26202 bytes in 0.021s)
[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:2698)
    at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:92)
    at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
    at com.genymobile.scrcpy.Server.scrcpy(Server.java:34)
    at com.genymobile.scrcpy.Server.main(Server.java:163)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
2020-02-20 01:40:04.237 scrcpy[20694:77713] INFO: Initial texture: 720x1280
2020-02-20 01:40:04.273 scrcpy[20694:77713] WARN: Device disconnected

Here's what the error looks like on the device (from logcat):

--------- beginning of system
02-20 01:42:24.629  2977  2989 E storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
--------- beginning of main
02-20 01:42:33.227 28429 28429 I AVUtils : createInstance(64bit) : _ZN7android19createExtendedUtilsEv
02-20 01:42:33.231 28429 28429 I AVUtils : createInstance(64bit) : _ZN7android19createExtendedUtilsEv
02-20 01:42:33.231 28429 28429 I AVUtils : Opened libavenhancements.so
02-20 01:42:33.231 28429 28429 I AVUtils : symbol _ZN7android19createExtendedUtilsEv found:  undefined symbol: _ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8_
02-20 01:42:33.231 28429 28429 I AVUtils : CREATE function success
02-20 01:42:33.231 28429 28429 I AVUtils : Opened libavenhancements.so
02-20 01:42:33.231 28429 28429 I AVUtils : symbol _ZN7android19createExtendedUtilsEv found:  (null)
02-20 01:42:33.231 28429 28429 I AVUtils : CREATE function success
02-20 01:42:33.231 28429 28429 I AVUtils : createInstance(64bit) : _ZN7android19createExtendedUtilsEv
02-20 01:42:33.231 28429 28429 I AVUtils : symbol _ZN7android19createExtendedUtilsEv found:  (null)
02-20 01:42:33.231 28429 28429 I AVUtils : CREATE function success
02-20 01:42:33.231 28429 28429 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
02-20 01:42:33.326 28429 28429 W app_process: CheckJNI: method to register "write" not in the given class. This is slow, consider changing your RegisterNatives calls.
02-20 01:42:33.327 28429 28429 I chatty  : uid=0(root) app_process identical 44 lines
02-20 01:42:33.327 28429 28429 W app_process: CheckJNI: method to register "write" not in the given class. This is slow, consider changing your RegisterNatives calls.
02-20 01:42:33.327 28429 28429 W app_process: CheckJNI: method to register "write_non_chained" not in the given class. This is slow, consider changing your RegisterNatives calls.
02-20 01:42:33.327 28429 28429 I chatty  : uid=0(root) app_process identical 7 lines
02-20 01:42:33.327 28429 28429 W app_process: CheckJNI: method to register "write_non_chained" not in the given class. This is slow, consider changing your RegisterNatives calls.
02-20 01:42:33.352 28429 28429 D AndroidRuntime: Calling main entry com.genymobile.scrcpy.Server
02-20 01:42:33.429 28429 28429 I app_process: Thread[1,tid=28429,Native,Thread*=0x7738e0dc00,peer=0x12c01da8,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
02-20 01:42:33.429 28429 28429 D MtpDeviceJNI: register_android_mtp_MtpDevice
02-20 01:42:33.429 28429 28429 I app_process: Thread[1,tid=28429,Native,Thread*=0x7738e0dc00,peer=0x12c01da8,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
02-20 01:42:33.429 28429 28429 I app_process: Thread[1,tid=28429,Native,Thread*=0x7738e0dc00,peer=0x12c01da8,"main"] recursive attempt to load library "/system/lib64/libmedia_jni.so"
02-20 01:42:33.433 28429 28443 I OMXClient: IOmx service obtained
02-20 01:42:33.434  2979  3058 I OMXMaster: makeComponentInstance(OMX.amlogic.video.encoder.avc) in omx@1.0-service process
02-20 01:42:33.434  2979  3058 D OmxComponentManagerImpl: support frame mode
02-20 01:42:33.434  2979  3058 D OmxComponentManagerImpl: getEntryByName_2_num=0, componentName:OMX.amlogic.video.encoder.avc
02-20 01:42:33.434  2979  3058 I AmlogicVideoAVCEncoder: ion_open sucess
02-20 01:42:33.434  2979  3058 W OmxLogConf: Can not read property media.omx.log_levels, using 0
02-20 01:42:33.434  2979  3058 D OmxComponentManagerImpl: IncreaseEntryNumByName pEntry->mNum=0, pEntry->mMaxNum:3,componentName:OMX.amlogic.video.encoder.avc
02-20 01:42:33.435  2979  3058 I omx_core: OMX_getHandle_num=1
02-20 01:42:33.435  2979  3058 D OmxComponent: mApkName=media.codec
02-20 01:42:33.439 28429 28443 I AmAVUtils: AmAVUtils::getComponentRole isEncoder :1 mime:video/avc
02-20 01:42:33.439 28429 28443 V AVUtils : AVUtils::getComponentRole
02-20 01:42:33.439  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.enableAndroidNativeBuffers"
02-20 01:42:33.439  2979  3058 E OMXNodeInstance: setParameter(0xf3b03bac:amlogic.encoder.avc, OMX.google.android.index.enableAndroidNativeBuffers(0x7f000000): Output:1 en=0) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.439  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.allocateNativeHandle"
02-20 01:42:33.439  2979  3058 E OMXNodeInstance: setParameter(0xf3b03bac:amlogic.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00000a): Output:1 en=0) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.439  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeANWBufferInMetadata"
02-20 01:42:33.439  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeMetaDataInBuffers"
02-20 01:42:33.439  2979  3058 E OmxVideoEncoder: setParameter: StoreMetadataInBuffersParams.nPortIndex not input port!
02-20 01:42:33.439  2979  3058 E OMXNodeInstance: setParameter(0xf3b03bac:amlogic.encoder.avc, OMX.google.android.index.storeMetaDataInBuffers(0x7f000002): Output:1 en=0 type=1) ERROR: BadPortIndex(0x8000101b)
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorFormat"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeMetaDataInBuffers"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeANWBufferInMetadata"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.prepareForAdaptivePlayback"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.configureVideoTunnelMode"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.useAndroidNativeBuffer2"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.useAndroidNativeBuffer"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.enableAndroidNativeBuffers"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.allocateNativeHandle"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.getAndroidNativeBufferUsage"
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorFormat"
02-20 01:42:33.440  2979  3058 I chatty  : uid=1046(mediacodec) HwBinder:2979_1 identical 1 line
02-20 01:42:33.440  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorFormat"
02-20 01:42:33.440  2979  3058 E OMXNodeInstance: getParameter(0xf3b03bac:amlogic.encoder.avc, ??(0x7f000007)) ERROR: UnsupportedSetting(0x80001019)
02-20 01:42:33.441 28429 28443 W OMXUtils: do not know color format 0x7f000789 = 2130708361
02-20 01:42:33.441 28429 28443 I ACodec  : setupAVCEncoderParameters with [profile: Baseline] [level: Level4]
02-20 01:42:33.441  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorAspects"
02-20 01:42:33.441  2979  3058 D OmxComponent: setConfig 1116
02-20 01:42:33.441  2979  3058 E OMXNodeInstance: setConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.441 28429 28443 W ACodec  : [OMX.amlogic.video.encoder.avc] setting color aspects failed even though codec advertises support
02-20 01:42:33.441 28429 28443 I ACodec  : [OMX.amlogic.video.encoder.avc] cannot encode color aspects. Ignoring.
02-20 01:42:33.441  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeHDRStaticInfo"
02-20 01:42:33.442  2979  3058 D OmxComponent: setConfig 1116
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: setConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f000009)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.442 28429 28443 W ACodec  : [OMX.amlogic.video.encoder.avc] setting HDRStaticInfo failed even though codec advertises support
02-20 01:42:33.442 28429 28443 I ACodec  : [OMX.amlogic.video.encoder.avc] cannot encode HDR static metadata. Ignoring.
02-20 01:42:33.442 28429 28443 I ACodec  : setupVideoEncoder succeeded
02-20 01:42:33.442 28429 28443 I AmAVUtils: AmAVUtils::isAudioExtendFormat input = video/avc
02-20 01:42:33.442  2979  3058 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorFormat"
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getParameter(0xf3b03bac:amlogic.encoder.avc, ??(0x7f000007)) ERROR: UnsupportedSetting(0x80001019)
02-20 01:42:33.442 28429 28443 W OMXUtils: do not know color format 0x7f000789 = 2130708361
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.442 28429 28443 W ACodec  : [OMX.amlogic.video.encoder.avc] getting color aspects failed even though codec advertises support
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ConfigLatency(0x6f800005)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ConfigAndroidVendorExtension(0x6f100004)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ConfigAndroidIntraRefresh(0x6f60000a)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.442  2979  3058 E OMXNodeInstance: getParameter(0xf3b03bac:amlogic.encoder.avc, ParamVideoIntraRefresh(0x6000006)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.444  2979 21074 D OmxComponent: setConfig 1116
02-20 01:42:33.444  2979 21074 E OMXNodeInstance: setConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.444 28429 28443 W ACodec  : [OMX.amlogic.video.encoder.avc] setting color aspects failed even though codec advertises support
02-20 01:42:33.444  2979 21074 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.444  2979  3058 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.444 28429 28443 W ACodec  : [OMX.amlogic.video.encoder.avc] getting color aspects failed even though codec advertises support
02-20 01:42:33.444  2979 21074 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeANWBufferInMetadata"
02-20 01:42:33.444  2979 21074 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.storeMetaDataInBuffers"
02-20 01:42:33.444  2979 21074 E OMXNodeInstance: getParameter(0xf3b03bac:amlogic.encoder.avc, ParamConsumerUsageBits(0x6f800004)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.444  2979 21074 D GraphicBufferSource: setting dataspace: 0x104, acquired=0
02-20 01:42:33.445  2979 21074 E OMXNodeInstance: getParameter(0xf3b03bac:amlogic.encoder.avc, ParamConsumerUsageBits(0x6f800004)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.445  2979  3058 D GraphicBufferSource: requesting color aspects (R:2(Limited), P:1(BT709_5), M:1(BT709_5), T:3(SMPTE170M))
02-20 01:42:33.445 28429 28429 D OpenGLRenderer: Skia GL Pipeline
02-20 01:42:33.440  2958  2958 I Binder:2958_5: type=1400 audit(0.0:1387): avc: denied { call } for scontext=u:r:surfaceflinger:s0 tcontext=u:r:mediacodec:s0 tclass=binder permissive=1 b/77924251
02-20 01:42:33.455  2958  2958 D mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
02-20 01:42:33.456  2979 28445 I OmxComponent: OMX_CommandStateSet 740 Cmd 0 nParam1 0x2
02-20 01:42:33.456  2979 28445 I OmxComponent: STATE_SET:   OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.456  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.457  2934  2934 W AshmemAllocator: ashmem_create_region(1382400) returning hidl_memory(0x7974a1a0f0, 1382400)
02-20 01:42:33.456  2958  2958 I surfaceflinger: type=1400 audit(0.0:1388): avc: denied { read } for name="gralloc.odroidn2.so" dev="mmcblk1p12" ino=492 scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=1
02-20 01:42:33.456  2958  2958 I surfaceflinger: type=1400 audit(0.0:1389): avc: denied { open } for path="/vendor/lib64/hw/gralloc.odroidn2.so" dev="mmcblk1p12" ino=492 scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=1
02-20 01:42:33.456  2958  2958 I surfaceflinger: type=1400 audit(0.0:1390): avc: denied { getattr } for path="/vendor/lib64/hw/gralloc.odroidn2.so" dev="mmcblk1p12" ino=492 scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=1
02-20 01:42:33.459  2945  3170 I gralloc : framebuffer hal alread move to hwcomposer
02-20 01:42:33.467  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.467  2934  2934 W AshmemAllocator: ashmem_create_region(1382400) returning hidl_memory(0x7974a1a0f0, 1382400)
02-20 01:42:33.467  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.468  2934  2934 W AshmemAllocator: ashmem_create_region(1048576) returning hidl_memory(0x7974a1a0f0, 1048576)
02-20 01:42:33.469  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.469  2934  2934 W AshmemAllocator: ashmem_create_region(1048576) returning hidl_memory(0x7974a1a0f0, 1048576)
02-20 01:42:33.469  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.469  2979 28445 I OmxComponent: STATE_DONE:  OMX_StateLoaded => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.469  2979 28445 I OmxComponent: OMX_CommandStateSet 740 Cmd 0 nParam1 0x3
02-20 01:42:33.469  2979 28445 I OmxComponent: STATE_SET:   OMX_StateIdle => OMX_StateExecuting : OMX.amlogic.video.encoder.avc
02-20 01:42:33.469  2979 28445 D AmlogicVideoAVCEncoder: mVideoColorFormat :0x7f000789, mVideoFrameRate: 60
02-20 01:42:33.469  2979 28445 D AmlogicVideoAVCEncoder: mStoreMetaDataInBuffers:1
02-20 01:42:33.469  2979 28445 D AmlogicVideoAVCEncoder: mVideoBitRate :8000000
02-20 01:42:33.469  2979 28445 D AmlogicVideoAVCEncoder: Video frame size is 720 x 1280
02-20 01:42:33.469  2979 28445 I OmxVideoEncoder: getParameter:432 OMX_IndexAmlogicVideoExtendCropScale
02-20 01:42:33.469  2979 28445 I AmlogicVideoAVCEncoder: get Parameter:bEnableScaling:0 param_extended->ui16ScaledWidth:0 Height:0,Flag:0, enableCroping:0, Left:0, right:0, top:0, bottom:0
02-20 01:42:33.485  2979 28445 I GXFASTENCLIB: EB block width:720, height:1280 mb_width:45, mb_height:80, block_width_num:12, block_height_num:21, block_width_n:12, block_height_n:20, block_width:4, block_height:4
02-20 01:42:33.485  2979 28445 E GXFASTENCLIB: InitFastEncode config init fai, fd:12l
02-20 01:42:33.485  2979 28445 D AMLVENC_API: InitAMVEncode Fail, dev type:2. fd:12
02-20 01:42:33.485  2979 28445 E AMLVENC : AML_HWEncInitialize Fail, error=0. handle: 0xf3b15510
02-20 01:42:33.485  2979 28445 E AmlogicVideoAVCEncoder: Failed to initialize the encoder: 0, handle: 0xf3b15510
02-20 01:42:33.485  2979 28445 E AmlogicVideoAVCEncoder: encode init failed, ret=0x80001001
02-20 01:42:33.485  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateIdle => OMX_StateExecuting : OMX.amlogic.video.encoder.avc
02-20 01:42:33.485  2979 28445 I OmxComponent: STATE_DONE:  OMX_StateIdle => OMX_StateExecuting : OMX.amlogic.video.encoder.avc
02-20 01:42:33.485  2979 28445 D GraphicBufferSource: got buffer with new dataSpace #104
02-20 01:42:33.485  2979 28446 D OmxComponent: getExtensionIndex 1123 name="OMX.google.android.index.describeColorAspects"
02-20 01:42:33.485  2979 28446 E OMXNodeInstance: getConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.486  2979 28446 D OmxComponent: setConfig 1116
02-20 01:42:33.486  2979 28446 E OMXNodeInstance: setConfig(0xf3b03bac:amlogic.encoder.avc, ??(0x7f00000c)) ERROR: UnsupportedIndex(0x8000101a)
02-20 01:42:33.486 28429 28443 D ACodec  : dataspace changed to 0x10c10000 (R:2(Limited), P:1(BT709_5), M:1(BT709_5), T:3(SMPTE170M)) (R:2(Limited), S:1(BT709), T:3(SMPTE_170M))
02-20 01:42:33.486 28429 28443 E ACodec  : [OMX.amlogic.video.encoder.avc] ERROR(0x80001001)
02-20 01:42:33.486 28429 28443 E ACodec  : signalError(omxError 0x80001001, internalError -2147483648)
02-20 01:42:33.486 28429 28442 E MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 6
02-20 01:42:33.487  2979 18779 W GraphicBufferSource: released unpopulated slots: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
02-20 01:42:33.488  2979  3058 E BufferQueueProducer: [GraphicBufferSource] disconnect: not connected (req=1)
02-20 01:42:33.488  2958  2958 W libEGL  : EGLNativeWindowType 0x712fa0e010 disconnect failed
02-20 01:42:33.488  2979 28445 I OmxComponent: OMX_CommandStateSet 740 Cmd 0 nParam1 0x2
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_SET:   OMX_StateExecuting => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 I OmxComponent: OMX.amlogic.video.encoder.avc: flush input
02-20 01:42:33.489  2979 28445 V OMX_WorkerPeer: hardware/amlogic/omx/omx_framework/WorkerPeer.cpp:flushInput:56 --------------------
02-20 01:42:33.489  2979 28445 I OmxComponent: OMX.amlogic.video.encoder.avc: flush output
02-20 01:42:33.489  2979 28445 V OMX_WorkerPeer: hardware/amlogic/omx/omx_framework/WorkerPeer.cpp:flushOutput:88 --------------------
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateExecuting => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 I chatty  : uid=1046(mediacodec) omx@1.0-service identical 2 lines
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateExecuting => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_DONE:  OMX_StateExecuting => OMX_StateIdle : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 I OmxComponent: OMX_CommandStateSet 740 Cmd 0 nParam1 0x1
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_SET:   OMX_StateIdle => OMX_StateLoaded : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 V OMX_WorkerPeer: hardware/amlogic/omx/omx_framework/WorkerPeer.cpp:flushInput:56 --------------------
02-20 01:42:33.489  2979 28445 V OMX_WorkerPeer: hardware/amlogic/omx/omx_framework/WorkerPeer.cpp:flushOutput:88 --------------------
02-20 01:42:33.489  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateIdle => OMX_StateLoaded : OMX.amlogic.video.encoder.avc
02-20 01:42:33.489  2979 28445 I chatty  : uid=1046(mediacodec) omx@1.0-service identical 1 line
02-20 01:42:33.490  2979 28445 I OmxComponent: STATE_TRANS: OMX_StateIdle => OMX_StateLoaded : OMX.amlogic.video.encoder.avc
02-20 01:42:33.490  2979 28445 I OmxComponent: STATE_DONE:  OMX_StateIdle => OMX_StateLoaded : OMX.amlogic.video.encoder.avc
02-20 01:42:33.490  2979  3715 D OmxComponentManagerImpl: DecreaseEntryNumByName pEntry->mNum=1, pEntry->mMaxNum:3,componentName:OMX.amlogic.video.encoder.avc
02-20 01:42:33.490  2979  3715 I omx_core: OMX_freeHandle_num_= 0
02-20 01:42:33.490  2979  3715 D OmxVideoEncoder: ~OmxVideoEncoder
02-20 01:42:33.492 28429 28429 D AndroidRuntime: Shutting down VM
--------- beginning of crash
02-20 01:42:33.493 28429 28429 E AndroidRuntime: FATAL EXCEPTION: main
02-20 01:42:33.493 28429 28429 E AndroidRuntime: PID: 28429
02-20 01:42:33.493 28429 28429 E AndroidRuntime: java.lang.IllegalStateException
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2698)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:92)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.genymobile.scrcpy.Server.scrcpy(Server.java:34)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.genymobile.scrcpy.Server.main(Server.java:163)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
02-20 01:42:33.493 28429 28429 E AndroidRuntime:    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
02-20 01:42:33.493 28429 28429 E scrcpy  : Exception on thread Thread[main,5,main]
02-20 01:42:33.493 28429 28429 E scrcpy  : java.lang.IllegalStateException
02-20 01:42:33.493 28429 28429 E scrcpy  :  at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2698)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:92)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:73)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.genymobile.scrcpy.Server.scrcpy(Server.java:34)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.genymobile.scrcpy.Server.main(Server.java:163)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
02-20 01:42:33.493 28429 28429 E scrcpy  :  at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)

Here's what the section from the media_codecs.xml looks like:

    <Encoders>
        <MediaCodec name="OMX.google.amrnb.encoder" type="audio/3gpp" />
        <MediaCodec name="OMX.google.amrwb.encoder" type="audio/amr-wb" />
        <MediaCodec name="OMX.google.aac.encoder" type="audio/mp4a-latm" />
        <MediaCodec name="OMX.google.flac.encoder" type="audio/flac" />

        <MediaCodec name="OMX.amlogic.video.encoder.avc" type="video/avc" >
            <Limit name="size" min="64x64" max="1920x1088" />
            <Limit name="alignment" value="16x16" />
            <Limit name="block-size" value="16x16" />
            <Limit name="blocks-per-second" min="1" max="244800" />
            <Limit name="bitrate" range="1-20000000" />
            <Limit name="concurrent-instances" max="3" />
        </MediaCodec>
        <MediaCodec name="OMX.google.mpeg4.encoder" type="video/mp4v-es" >
            <Limit name="size" min="176x144" max="640x480" />
            <Limit name="alignment" value="16x16" />
            <Limit name="block-size" value="16x16" />
            <Limit name="blocks-per-second" min="1" max="1485" />
            <Limit name="bitrate" range="192000-1440000" />
        </MediaCodec>
        <MediaCodec name="OMX.google.h263.encoder" type="video/3gpp" >
            <Limit name="size" min="176x144" max="352x288" />
            <Limit name="alignment" value="16x16" />
        </MediaCodec>
        <MediaCodec name="OMX.google.vp8.encoder" type="video/x-vnd.on2.vp8">
            <!-- profiles and levels:  ProfileMain : Level_Version0-3 -->
            <Limit name="size" min="2x2" max="896x896" />
            <Limit name="alignment" value="2x2" />
            <Limit name="bitrate" range="1-40000000" />
            <Feature name="bitrate-modes" value="VBR,CBR" />
        </MediaCodec>
    </Encoders>
rom1v commented 2 years ago

https://github.com/Genymobile/scrcpy/blob/master/README.md#encoder