Openvidu Browser : Switching Camera (Android)

Hello OpenVidu members!

I’ve performed a global search on the forum for my problem and looked online (SO, official documentation …) without any success.
I’m really sorry about the length of this topic and I try to be as exhaustive as possible because I feel really stuck with my issue.

TLDR : issue with recorded video dimension when recording from browser on Android + issue to record video after switching from back to front camera (different dimension ratio)

I use openVidu (2.17.0) and have to record the publisher for 2 videos during a session directly from the browser. I use OV browser.
First video will use the back camera and second one will use the front camera. (I use for my test a Redmi Note 7 phone on Google Chrome with Android 10)

Here’s my scenario :

  1. I create the session and connection for my publisher
  2. I use geUserMedia function with specific constraints to ensure at least a 720p video format and get the deviceId
  3. I then call initPublisher function with the deviceId as videosource parameters and width and height of the settings of the stream (“widthxheight”) as resolution parameter. Once this step is performed i use the “publish” function
  4. I use the OV REST API and call recordings/start endpoint using “COMPOSED” as “outputMode” and same resolution as the one given to initPublisher function at step 3

This first part works “fine” and I can have a decent video.

First issue :

  1. I expect a portrait mode video because I use the phone in portrait mode but i still have a 16/9 ratio instead of 9/16 ratio. After some research it appears that width and height are inverted in some case on Android (Width and height constraint inverted in android chrome · Issue #245 · serratus/quaggaJS · GitHub) > Video is cropped and I can’t get the full recorder video as intended
  2. Looking at PublisherProperties | OpenVidu Browser - v2.17.0 does it means I can’t use specific dimension with 9/16 ratio ?

Second part :
After I stopped my first recording :

  1. I try to switch my camera from back to front (using OV doc “Advanced feature : switch camera”), this part looks ok. I use the solution where i initialize a new Publisher.
  2. I then call again the OV API : recordings/start

2 behaviors :

  1. I get back a 500 from OV and looking at logs I can see a generic : (This error message seems generic and doesn’t said much about the real issue. This error disappear if I change the dimension sent to the endpoint)

Couldn’t initialize recording container. Error: File /opt/openvidu/recordings/ses_XXX/YYY.mp4 does not exist and hasn’t been created in 30 seconds.

  1. If i change the dimension parameter sent to recordings/start endpoint to fit with the dimension set when i called the initPublisher function I can record the video but I also have a really bad cropped and useless video.

It looks like OV doesn’t like switching video dimension and having specific aspect ratio while being connected to a specific session.

Have you also got this situation before and do you know how to handle this scenario correctly ? (how to record 2 differents camera (one at a time) with different ratio without cropping them)

Thank you really much for your help and have a good day

Hi,

I think that INDIVIDUAL recording will actually give you much better results for this use case. COMPOSED recording allows you to mix different streams into one video in real time. The default layout uses a simple algorithm to distribute the videos evenly throughout the available space. But doing so it may trim videos and ignore original orientations. Of course, you can implement your own layouts to specifically fit your needs.

But again, I think that INDIVIDUAL recording will behave much better in your case. This mode just dumps into disk the video data as it reaches the server side, without any kind of processing. And if you have a single video every time you record, then you don’t need the mixing feature that COMPOSED recording provides. So the video of the phone will be stored with its original resolution, framerate and orientation, and the CPU usage in the server side will be much lower.

Two notes:

  • If Android Chrome is messing around with the resolution, then that problem is beyond openvidu-browser’s control. openvidu-browser is just a simple wrapper around native Web API. If certain platforms on specific devices behave differently than the native Web API expects, then that should be handled in the application’s code. The PublisherProperties resolution parameter is not limited to the 3 resolutions stated by the documentation (that is in fact a little bit outdated). You can set any width x height you want. The browser will do its best effort to honor it.
  • The 500 error is a different matter. That shouldn’t happen. If I have understood correctly, it happens if you tried to record in COMPOSED mode setting with a specfic resolution?

Cheers.

1 Like

Hello Pablo

First of all thank you very much for your quick and precise answer regarding my long post.
I really appreciate you took time to understand my issue, thank you

I have updated my code to use individual output mode and results look better (i had to adapt the way openvidu handle video into the zip archive)

I still have a question regarding the video dimension recorded on OpenVidu vs the dimension in the local mediastream on the device :

  • calling getUserMedia function with constraints to ensure 720p resolution
  • getting back a stream object and when I display its settings I can see height 720px and width 1280px
  • calling initPublisher (Openvidu Browser) with the stream + resolution of “1280x720”
  • calling start and stop OpenVidu REST API and downloaded zip archive to get my videos
  • looking at downloaded videos dimension : I’ve got smaller dimension and dimension changes while I play the video (starts with 720x405 and finish with 960x540 ratio for example)

My guess is the dimension evolve regarding user internet connection but I wonder if there’s a way to force OpenVidu Browser to send 720p stream to the server no matter other parameters. (Maybe not an OpenVidu issue as you mentionned it in your first note)


The 500 error might be happening because of wrong resolution given to the server with a composed output mode such as portrait mode dimension and a landscape resolution given at the first time ? Then the server tries to scale the portrait video to the landscape resolution and an overflow happens ? I’ll try to reproduce the issue and give a code snippet but the idea was :

  • first video recorded in 720p in landscape mode (or portrait because it seems that width and height was inverted)
  • calling a second time the start endpoint of the API (after i stopped and used replaceTrack to use the front camera) with new dimension : delay with the server answer and 500 returned, looking at log directly on OpenVidu server telling me it can’t initialize recording container