api.video-reactnative-live-stream icon indicating copy to clipboard operation
api.video-reactnative-live-stream copied to clipboard

Failed to create codec for: {mime=video/avc, width=720, height=1280}

Open eightyfive opened this issue 3 years ago • 16 comments

Describe the bug README example failing on Samsung Galaxy J7 Prime device (Android).

Error while updating property 'video' of a view managed by: ReactNativeLiveStreamView

null

Failed to create codec for: {mime=video/avc, width=720, height=1280}

[stack trace]

To Reproduce Steps to reproduce the behavior:

  1. Try to run the README example

Expected behavior App to not crash. Maybe handle unsupported codec on devices gracefully?

Smartphone (please complete the following information):

  • Device: Samsung Galaxy J7 Prime
  • OS: Android
  • Version 1.2.1

Additional context I packaged react-native-livestream into custom Expo dev-client.

eightyfive avatar Oct 13 '22 09:10 eightyfive

It works with 360p resolution.

<LiveStreamView
  video={{
    fps: 30,
    resolution: "360p",
    bitrate: 2 * 1024 * 1024, // # 2 Mbps
  }}

How can I detect what resolution/codec is supported on my device?

eightyfive avatar Oct 13 '22 09:10 eightyfive

Instead of opening a new issue, I am gonna ask here for now instead.

Still running the README example. I can make it work with "resolution": "360p" as explained above. But now, after I stopStreaming the first time, the "camera view" freezes.

This is how it goes:

  1. Mount screen ✅
  2. Do not start streaming yet
  3. Move camera around, the "camera view" works ✅
  4. Start streaming
  5. onConnecttionSuccess event is fired ✅
  6. Move camera around, the "camera view" works ✅
  7. Stop streaming
  8. onDisconnect event is fired ✅
  9. Move camera around, the "camera view" works ✅
  10. Start streaming again
  11. onConnecttionSuccess event is fired ✅
  12. "Camera view" does NOT work ❌
  13. Stop streaming
  14. Button changes color red --> white (so not the screen freezing) ✅
  15. onDisconnect event is NOT fired ❌

No JS errors, no crash. Just the "camera view" freezing.

Any help/hint would be appreciated 🙏

eightyfive avatar Oct 13 '22 09:10 eightyfive

So if I re-mount the Screen. The "camera view" works again.

eightyfive avatar Oct 13 '22 09:10 eightyfive

Follow-up:

I could get it to work by mounting/unmounting <LiveStreamView /> based on streaming: boolean.

While everything now "works", I'm not closing the issue just yet. If possible I would like some background about:

  1. How to detect supported codec on device (if possible)?
  2. Is the mounting/unmounting required or is it a bug?

Cheers 🙏

eightyfive avatar Oct 13 '22 10:10 eightyfive

Hi there,

  1. You are not the first one to have this issue. AVC/h.264 in 720p should be supported by your device. I am going to ask you to install apk to check what is going on. If it is ok for you. And for your question there is no way to detect supported codec/resolution on this library.

  2. Please open another issue.

ThibaultBee avatar Oct 13 '22 10:10 ThibaultBee

  1. It's ok for me.
  2. Done.

eightyfive avatar Oct 13 '22 13:10 eightyfive

Nice.

1/ So, could you check that you got the same issue with that application with the same settings (h.264 and 720p)? https://github.com/ThibaultBee/StreamPack/suites/8737375436/artifacts/395412454 2/ Check it does not happen with the same application (but with a small change) https://github.com/ThibaultBee/StreamPack/suites/8758666052/artifacts/396981234

ThibaultBee avatar Oct 13 '22 14:10 ThibaultBee

Both apk (StreamPack camera) crash on launch.

eightyfive avatar Oct 13 '22 14:10 eightyfive

I am surprised that your phone does not have an AVC encoder that support 720p. Maybe an application that dump encoder and their capabilities would be nice.

ThibaultBee avatar Oct 13 '22 15:10 ThibaultBee

Could you install a tool like that: https://play.google.com/store/apps/details?id=com.parseus.codecinfo&hl=en_US&gl=US Find all AVC/h.264 video encoders, dump or screenshot their info and upload everything here?

ThibaultBee avatar Oct 13 '22 15:10 ThibaultBee

I installed the dump app.

It turns out I do have a video/avc h264 decoder & encoder.

Decoder max resolution: 2048x2048

Encoder max resolution: 1808x1808

image

image

image

image

eightyfive avatar Oct 13 '22 15:10 eightyfive

I don't get yet why Android does not return this codec when we request an h.264 encoder that supports 720p. Maybe because it is a software encoder?... It is not a really great idea to stream from a software encoder. Anyway, can you lower the bitrate? The max supported bitrate is 2 Mbps.

ThibaultBee avatar Oct 13 '22 15:10 ThibaultBee

I just tried with another Android device and both issues are resolved.

Now the strange thing, they both run: Android 8.1.0 Oreo (API 26).

So it's really a hardware issue:

  • KO: Galaxy J7 Prime
  • OK: Razer Phone 2

eightyfive avatar Oct 14 '22 02:10 eightyfive

If you look at the encoder in your second phone, I am pretty sure that it has an AVC/H.264 hardware encoder. That's why.

Could you test this APK: https://github.com/ThibaultBee/StreamPack/suites/8771926395/artifacts/397982074 I have forced the usage of "OMX.google.h264.encoder".

ThibaultBee avatar Oct 14 '22 07:10 ThibaultBee

I have the same issue with Samsung A20E. StreamPack from suite 1 and 2 is crashing Suite 3 where you forced h264 encoder is working for me

endrits079 avatar Oct 17 '22 21:10 endrits079

Hi, This crash seems to be related to few models of Samsung. On these models, for an unknown reason, the MediaCodec API does not find an encoder that matches the expected configuration althought there is such encoder in the phone. We are waiting to find one of this device. We will let you know when this issue is fixed.

ThibaultBee avatar Oct 25 '22 15:10 ThibaultBee

Hi,

Could anyone test with https://github.com/ThibaultBee/StreamPack/suites/9154470311/artifacts/425992879?

ThibaultBee avatar Nov 07 '22 07:11 ThibaultBee

@ThibaultBee tested it with the device I was having trouble and seems to be working, btw do you have any library to play hls or rtmp?

endrits079 avatar Nov 07 '22 19:11 endrits079

Sorry, we haven't tested any RN player. I will make a new release to fix this issue.

ThibaultBee avatar Nov 08 '22 08:11 ThibaultBee

Hi,

Could you check that your issue is fixed in the main branch?

ThibaultBee avatar Jan 06 '23 14:01 ThibaultBee

This should be fixed in v1.2.2.

ThibaultBee avatar Jan 11 '23 10:01 ThibaultBee