apivideo/api.video-reactnative-live-stream

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

eightyfive opened this issue · 21 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.

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?

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 🙏

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

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 🙏

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.

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

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

Both apk (StreamPack camera) crash on launch.

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.

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?

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

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.

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

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".

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

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 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?

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

Hi,

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

This should be fixed in v1.2.2.