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

Improve orientation support #4441

Merged
merged 5 commits into from
Nov 23, 2023
Merged

Improve orientation support #4441

merged 5 commits into from
Nov 23, 2023

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Nov 20, 2023

Problems

There are currently two options to rotate the video:

As a consequence, in particular, it was not possible to record a vertical video from a camera capture.

Changes

New orientation option

Introduce a new option --orientation (and separate options --display-orientation and --record-orientation if needed) which supports the 8 possible orientations (4 rotations × 2 flips):

scrcpy --orientation=0
scrcpy --orientation=90       # 90° clockwise
scrcpy --orientation=180      # 180°
scrcpy --orientation=270      # 270° clockwise
scrcpy --orientation=flip0    # hflip
scrcpy --orientation=flip90   # hflip + 90° clockwise
scrcpy --orientation=flip180  # vflip (hflip + 180°)
scrcpy --orientation=flip270  # hflip + 270°

The rotation is expressed in degrees clockwise so that --orientation=90 works for vertical video from a camera (it's more natural than --orientation=270 or --orientation=-90).

It is possible to change the display orientation dynamically using shortcuts:

  • rotate display left: MOD+
  • rotate display right: MOD+
  • flip display horizontally: MOD+Shift+ or MOD+Shift+
  • flip display vertically: MOD+Shift+ or MOD+Shift+

The rotation is applied to a recorded file by writing a display transformation to the MP4 or MKV target file.
Flipping is not supported for recording, so only the 4 first values are allowed when recording.

For MKV files, unfortunately, some players currently do not handle it properly:

MP4 files are correctly handled by these 2 players (and remuxing an MKV file to an MP4 file also fixes the issue).

--rotation is now deprecated.

Locked video orientation adaptation

For consistency, --lock-video-orientation has been adapted to express the value as a number of degrees clockwise, and the values 1, 2 and 3 are deprecated:

  • --lock-video-orientation=0 → unchanged
  • --lock-video-orientation=1--lock-video-orientation=270 (now, it's clockwise!)
  • --lock-video-orientation=2--lock-video-orientation=180
  • --lock-video-orientation=3--lock-video-orientation=90 (now, it's clockwise!)

Result

Now, it is possible to capture and record a rotated video from the camera:

scrcpy --video-source=camera --camera-size=1920x1080 --orientation=90 --record=vertical.mp4

Binary

Please review and test.

Here is a binary for Windows:

@rp1231
Copy link

rp1231 commented Nov 21, 2023

Works fine for me but I get a lot of audio feedback when using this option on my pc speakers:
scrcpy --video-source=camera --camera-size=1920x1080 --orientation=90
Any way to mitigate this issue?

Also does this mean that it's possible to use the phone as a webcam on windows as well?

@rom1v
Copy link
Collaborator Author

rom1v commented Nov 21, 2023

Works fine for me but I get a lot of audio feedback when using this option on my pc speakers

You can disable audio capture (--no-audio), you won't get any audio at all.
Or you can disable audio playback (--no-audio-playback), the audio will still be captured and recorded, but not played.

Also does this mean that it's possible to use the phone as a webcam on windows as well?

You can display the webcam in a window, then you can probably capture it with OBS and expose it as a webcam on Windows (apparently this is what Mishaal Rahman did for his recent article, but I have never tested).

@rom1v
Copy link
Collaborator Author

rom1v commented Nov 21, 2023

A new option --v4l2-orientation should also be added (and automatically set with --orientation) to orient a v4l2 video stream.

However, just setting a display matrix does not work, we must create and apply an AVFilter "transpose". Is someone interested in adding this feature for v4l2? (The FFmpeg sample decode_filter_video.c might help)

Deprecate the option --rotation and introduce a new option
--display-orientation with the 8 possible orientations (0, 90, 180, 270,
flip0, flip90, flip180 and flip270).

New shortcuts MOD+Shift+(arrow) dynamically change the display
(horizontal or vertical) flip.

Fixes #1380 <#1380>
Fixes #3819 <#3819>
PR #4441 <#4441>
For consistency with the new --display-orientation option, express the
--lock-video-orientation in degrees clockwise:

 * --lock-video-orientation=0 -> --lock-video-orientation=0
 * --lock-video-orientation=3 -> --lock-video-orientation=90
 * --lock-video-orientation=2 -> --lock-video-orientation=180
 * --lock-video-orientation=1 -> --lock-video-orientation=270

PR #4441 <#4441>
Add an option to store the orientation to apply in a recorded file.

Only rotations are supported (not flips).

PR #4441 <#4441>
Add a shortcut to set both the display and record orientations.

PR #4441 <#4441>
@rom1v rom1v merged commit 94031df into dev Nov 23, 2023
Gasol added a commit to Gasol/ya-webadb that referenced this pull request Nov 6, 2024
Introduce new classes and enums to handle Scrcpy version 2.3 options.
This update includes new display orientation options and modifies the
existing interfaces to accommodate additional settings.

See Genymobile/scrcpy#4441
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

Successfully merging this pull request may close these issues.

2 participants