ThibaultBee / StreamPack

SRT/RTMP/RTMPS live streaming libraries for Android
https://thibaultbee.github.io/StreamPack/index.html
Apache License 2.0
196 stars 70 forks source link

[Feat]: Lock resolution to starting orientation #75

Closed SteveMac555 closed 8 months ago

SteveMac555 commented 1 year ago

Version

2.5.2

Environment that reproduces the issue

Use case description

When recording the screen and selecting 1920x1080 as the resolution, in portrait mode the receiving side has black around the phone screen - as a full frame 1920x1080 video.

If the phone is in portrait, an option to lock this to 1080x1920 for example, so that the video is resized correctly on the receiving end.

Proposed solution

An option in settings to lock the resolution to the starting orientation, and flip the resolution so that it is resized correctly.

Alternative solutions

No response

SteveMac555 commented 1 year ago

I've just noticed that it does check for portrait landscape etc. but it doesn't work on the devices I've tested. Pixel 7, Pixel 6 Pro, ASUS ROG, So it always broadcasts in landscape.

The rotation degrees passed into isPortrait is always 0, regardless of the device orientation. I've tried manually returning 'true' and that does fix the output video size, but the actual video data inside is wrong size/maybe aspect so not sure where else to alter?

Is it possible to check whether we're in portrait/landscape by doing device portrait = width > height

Thank you.

ThibaultBee commented 1 year ago

Hi,

I am not sure to fully understand the whole issue. Could make screenshot of what the stream looks like and what you expect. Could you also point where you have read rotation degrees?

There has been changed on the management on the orientation on the main branch. Could you test it with the screenrecorder sample?

SteveMac555 commented 1 year ago

Hi,

I've attached a screenshot from OBS receiving the SRT feed here: https://imgur.com/a/HhYi9dc - It shows the video being received in 1920x1080 with the phone centered and scaled in the middle. As I am in portrait mode, I was expecting to receive a portrait resolution of the phone. (Like this, https://imgur.com/a/Afmmw9e) as it does with Larix Screencaster and other screencasting apps.

This is from the main branch, screenrecorder demo from a couple of days ago. I will double check where I was reading the orientation as I know there were a few places, but isPortrait was always returning false as I recall.

Thanks

ThibaultBee commented 1 year ago

Hmm, might be here: https://github.com/ThibaultBee/StreamPack/blob/3a9af52fd6f34c2dac308ece85a2a38c6d64760e/core/src/main/java/io/github/thibaultbee/streampack/streamers/bases/BaseScreenRecorderStreamer.kt#L50C15-L50C15

Instead of FixedOrientationProvider(orientation = 0), you could try to use DeviceOrientationProvider()

SteveMac555 commented 1 year ago

Hello,

Thank you - I can confirm that changing that has resized the output and I am receiving it in the correct size/orientation. However the image that is captured inside is not scaled properly - Image here: https://imgur.com/a/vovZArx

EDIT: I could be way off, but as its now a rotated resolution, could that problem in the image above be related to the FullFrameRect FULL_RECTANGLE_COORDS / FULL_RECTANGLE_TEX_COORDS as the positions would have changed?

Thanks

ThibaultBee commented 1 year ago

Hello,

Could you try to invert setDefaultBufferSize in VideoMediaCodecEncoder?

SteveMac555 commented 1 year ago

Hi,

Almost there! Inverting the values of setDefaultBufferSize() produced this, correct width, half height, with the bottom half cut off.

https://imgur.com/a/gfmYL5A

This was with: setDefaultBufferSize(minOf(height, width),maxOf(height, width))

SteveMac555 commented 1 year ago

Not sure if it's the right way to do it, but flipping the start resolution and adding an option of: Size(1080, 1920), has done the trick! - Plus the two changes you mentioned above. Thank you!

ThibaultBee commented 10 months ago

Hi, I reworked how the orientation works. Could you check screen recording in portraint in the main branch?

ThibaultBee commented 8 months ago

Released in 2.6.0. Please reopen the issue if it is not fixed.