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

Add --no-video (to mirror audio only) #3978

Merged
merged 14 commits into from
May 15, 2023
Merged

Add --no-video (to mirror audio only) #3978

merged 14 commits into from
May 15, 2023

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented May 7, 2023

As a first step, rename --no-display to --no-mirror:

  • the option impacts both video and audio playback, so "no display" is not an appropriate name
  • it is confusing with the option --display= which is totally unrelated (it refers to the device display)

Using the short version -N works as before.

Using --no-display still works, but generates a warning:

WARN: --no-display is deprecated, use --no-mirror instead.

Then add a new option --no-video:

scrcpy --no-video

And adapt recording to audio files:

scrcpy --no-video --record=file.opus
scrcpy --no-video --audio-codec=aac --record-file=file.aac
# .m4a/.mp4 and .mka/.mkv are also supported for both opus and aac

To record only:

scrcpy --no-mirror --record=file.opus

The opus muxer has been added to the prebuilt FFmpeg for windows releases: https://github.com/rom1v/scrcpy-deps/commits/6.0-scrcpy-3

Fixes #3842


Please review and test. Here is a release of this PR:

rom1v added 12 commits May 8, 2023 16:40
The option impacts both video and audio playback, so "no display" is not
an appropriate name.

PR #3978 <#3978>
If mirroring is disabled, control must also be disabled.

PR #3978 <#3978>
The async processors use the socket file descriptors from the
connection. Therefore, the connection must not be closed before all
async processor threads are joined.

PR #3978 <#3978>
Contrary to the other tasks (controller and audio capture/encoding), the
screen encoder was executed synchronously. As a consequence,
scrcpy-server could not terminate until the screen encoder returned.

Convert it to an async processor. This allows to terminate on controller
error, and this paves the way to disable video mirroring.

PR #3978 <#3978>
Some server parameters may depend on one another. For example,
audio_bit_rate is meaningless if audio is false.

But it is inconsistent to disable some parameters based on these
dependencies checks, but not others. Handling all dependencies between
parameters would add too much complexity for no benefit.

So just pass individual parameters independently.

PR #3978 <#3978>
Similar to --no-audio, add --no-video to play audio only.

Fixes #3842 <#3842>
PR #3978 <#3978>
Convert either the filename extension or the explicit record format
to a sc_record_format using the same function.

PR #3978 <#3978>
Several checks are performed when opts->record_filename is not NULL.
Group them in a single block.

PR #3978 <#3978>
These are just aliases for mp4 and mkv when there is no video stream.

PR #3978 <#3978>
Use the FFmpeg opus muxer to record an opus file.

PR #3978 <#3978>
It is just an alias for mp4.

PR #3978 <#3978>
rom1v added a commit that referenced this pull request May 8, 2023
Use a build which includes the opus muxer, to support recording to .opus
files.

Refs <https://github.com/rom1v/scrcpy-deps/commits/6.0-scrcpy-3>
PR #3978 <#3978>
rom1v added a commit that referenced this pull request May 8, 2023
Document how to record audio-only to .opus and .aac files.

PR #3978 <#3978>
@Piripe
Copy link

Piripe commented May 11, 2023

Just tried the --no-video, it works great.
I have no need to test other features of this PR, but if you want I can.

@rom1v
Copy link
Collaborator Author

rom1v commented May 11, 2023

@Piripe Thank you for your tests 👍

If you could test recording only the audio to .opus and .aac and play it with some player (vlc, firefox, other…) to confirm that everything is ok, that would be great :)

@Piripe
Copy link

Piripe commented May 11, 2023

I tried recording only the audio with and without the mirroring, it works great!



I also made a little AHK script (I edited the script in the autoadb issues) using autoadb and scrcpy, I really like this way to mirror my phone 😀

2023-05-12.00-16-17_.mp4

(Note: I'm REALLY unorganized, as you can see in my taskbar)

The script:

#NoTrayIcon
#Persistent

global hAutoadb

/* Setup Tray icon and add item that will handle
 * double click events
 */
Menu Tray, Icon
Menu Tray, Icon, icon.ico
Menu Tray, Add, Show / Hide autoadb, TrayClick
Menu Tray, Add, Mirror Display, DisplayClick
Menu Tray, Default, Mirror Display

;// Run autoadb hidden
DetectHiddenWindows On
Run autoadb scrcpy --no-video,, Hide, PID
WinWait ahk_pid %PID%
hAutoadb := WinExist()
DetectHiddenWindows Off
return

TrayClick:
OnTrayClick()
return

DisplayClick:
Run scrcpy --no-audio --turn-screen-off --stay-awake --show-touches -b 30M,,, PID
WinWait ahk_pid %PID%
hScrcpy := WinExist()
WinHide ahk_id %hScrcpy%
return

;// Show / hide Autoadb on double click
OnTrayClick() {
	if DllCall("IsWindowVisible", "Ptr", hAutoadb) {
		WinHide ahk_id %hAutoadb%
	
	} else {
		WinShow ahk_id %hAutoadb%
		WinActivate ahk_id %hAutoadb%
	}
}

@kevsestrella
Copy link

Hi, will this work with v4l2? Currently, v4l2 with no display with --required-audio doesn't stream audio

@rom1v
Copy link
Collaborator Author

rom1v commented May 12, 2023

Hi, will this work with v4l2? Currently, v4l2 with no display with --required-audio doesn't stream audio

I plan to add --no-mirror-video and --no-mirror-audio later (where --no-mirror would be an alias for both), so that you could use:

scrcpy --no-mirror-video --v4l2-sink=…

rom1v added 2 commits May 15, 2023 14:28
Use a build which includes the opus muxer, to support recording to .opus
files.

Refs <https://github.com/rom1v/scrcpy-deps/commits/6.0-scrcpy-3>
PR #3978 <#3978>
Document how to record audio-only to .opus and .aac files.

PR #3978 <#3978>
@rom1v
Copy link
Collaborator Author

rom1v commented May 16, 2023

Question about the option name: in this MR, --no-display has been renamed to --no-mirror.

I'm wondering if it should be called --no-playback instead (and --no-video-playback/--no-audio-playback for individual streams)?

For example, if we use a V4L2 think without a scrcpy window (scrcpy --no-mirror --v4l2-sink=/dev/video2), then we can consider we are still "mirroring" the device?

What do you think?

@Piripe
Copy link

Piripe commented May 17, 2023

Yeah, it would be more intuitive

rom1v added a commit that referenced this pull request May 24, 2023
This option impacts video and audio _playback_. For example, if we use
V4L2, the device is still "mirrored" (via V4L2), even if playback is
disabled. Therefore, "playback" is more approriate than "mirror".

The initial option --no-display option was renamed to --no-mirror by
commit 6928acd, but this has never been
released, so it is ok to rename it one more time.

Refs #3978 <#3978 (comment)>
rom1v added a commit that referenced this pull request May 27, 2023
This option impacts video and audio _playback_. For example, if we use
V4L2, the device is still "mirrored" (via V4L2), even if playback is
disabled. Therefore, "playback" is more approriate than "mirror".

The initial option --no-display option was renamed to --no-mirror by
commit 6928acd, but this has never been
released, so it is ok to rename it one more time.

Refs #3978 <#3978 (comment)>
PR #4033 <#4033>
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.

3 participants