Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep streaming when rotating device #1480

Open
punto338 opened this issue May 11, 2024 · 6 comments
Open

How to keep streaming when rotating device #1480

punto338 opened this issue May 11, 2024 · 6 comments

Comments

@punto338
Copy link

Hello, I have a problem when streaming in landscape mode. I want to keep streaming when rotating screen so video output now should be in portrait mode. I have this code but it seems release() method cancels the streaming. I need to keep sending video without stopping streaming and starting again, any idea?

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if (genericStream != null && genericStream.isOnPreview()) {
            genericStream.stopPreview();
            genericStream.release();
            mCameraView.getHolder().addCallback(this);
        }
    }
@pedroSG94
Copy link
Owner

Hello,

You have a code example to support rotation here:
https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/rotation

@punto338
Copy link
Author

punto338 commented May 17, 2024

Hello,

You have a code example to support rotation here: https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/rotation

I am trying to streaming portrait and landscape mode and both make output of 1920x1080, so in portrait mode I get black space on the sides, is any way to make the output same size as the video? I see OK when in the device which is streaming but in the "player" device its wrong, see next comment:

@punto338
Copy link
Author

punto338 commented May 17, 2024

See pictures, first one is landscape, which is OK, and the other one is portrait mode but it seems video is outputing in landscape mode:

WhatsApp Image 2024-05-17 at 12 15 03 (1)
WhatsApp Image 2024-05-17 at 12 15 03

@pedroSG94
Copy link
Owner

Hello,

This is the expected result.

You can't change the video size while you are streaming/recording so the video is adapted depend of the device orientation to avoid distortion.
You can choose use 1080x1920 and you will have the same case but inverted (portrait is filled and landscape with black borders).

@punto338
Copy link
Author

punto338 commented May 17, 2024

I mean I am not trying to change video size while streaming. Use case:

-I have portrait camera, it show in my preview fullscreen and good, then I start recording and in the player I get an output of 1920x1080 with the streaming small in the middle, and black on the sides

This is my code. Its working in landscape but not in portrait. bestSize is 2400 width 1080 height

Size bestSize = getBestCameraResolution();
genericStream.getGlInterface().setAspectRatioMode(AspectRatioMode.Fill);
genericStream.getGlInterface().setAutoHandleOrientation(true);
genericStream.prepareVideo(bestSize.getWidth(), bestSize.getHeight(), 1200 * 1000);
genericStream.prepareAudio(32000, true, 128 * 1000);

@punto338
Copy link
Author

punto338 commented May 17, 2024

@pedroSG94 I was able to fix this with the rotation in prepareVideo() method with this code, similar to the example you gave:

genericStream.prepareVideo(width, height, vBitrate, rotation = rotation)

 genericStream.prepareVideo(
                    bestSize.getWidth(),
                    bestSize.getHeight(),
                    1200 * 1000,
                    30,
                    2,
                    getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? 90 : 0
            );

How can I set just the orientation like you using Java, without setting fps and iFrameInterval param? If not possible, which are the default values for fps and iFrameInterval ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants