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

Start scrcpy 2.0 by NodeJS but cannot receive "Recording Started" in stdout pipe #3933

Open
2 tasks done
Jellyswat opened this issue Apr 20, 2023 · 10 comments
Open
2 tasks done

Comments

@Jellyswat
Copy link

Jellyswat commented Apr 20, 2023

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: macOS
  • scrcpy version: 2.0
  • installation method: brew
  • device model: All device
  • Android version: All version

Describe the bug
Hi,
I just start scrcpy 2.0 by NodeJs but cannot receive "Recording Started" in stdout pipe.

I tried scrcpy 1.24 Its ok. So i think this is a new bug from 1.45 to 2.0

More Information:
I guess its something wrong between buffer area? Maybe print but not '\n' or cout but not "<< endl;" ? Just a guess

@rom1v
Copy link
Collaborator

rom1v commented Apr 20, 2023

I just start scrcpy 2.0 by NodeJs

What does it mean?

What is the full console output?

See commit a039124.

@Jellyswat
Copy link
Author

I use NodeJs to start scrcpy code like this

// start scrcpy by JS subprocess module
let subProcess = childProcess.spawn(command, { shell: true });

// listen scrcpy's stdout
subProcess.stdout.on('data', async res => { console.log(res); });

Command
scrcpy --serial ${deviceId} --port 12345 --crop 100:100:0:0 --no-display --record ${videoPath} --no-audio

Console output

// this is the console i got at the first time
/opt/homebrew/Cellar/scrcpy/2.0_1/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 29.2 MB/s (52867 bytes in 0.002s)
[server] INFO: Device: Xiaomi M2011K2C (Android 12)

// When I kill the child process, I got the following console at the same time
 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
INFO: Recording started to mp4 file: /Users/xxx/cache/15883504-android-scrcpy-video-1681988923815.mp4
INFO: Recording complete to mp4 file: /Users/xxx/cache/15883504-android-scrcpy-video-1681988923815.mp4

@rom1v
Copy link
Collaborator

rom1v commented Apr 20, 2023

So you get the adb and server logs immediately, but the client logs when you exit. There is additional buffering somewhere…

@Jellyswat
Copy link
Author

Yes.
I want to got the console output like INFO: Recording started immediately~

When I use 1.24, it's normal, but 2.0 doesn't work anymore. Is there any suggestion?

@rom1v
Copy link
Collaborator

rom1v commented Apr 20, 2023

Maybe related: in 2.0, info logs are printed to stdout rather than stderr: 4a25f3e

@Jellyswat
Copy link
Author

I listen to stderr like subProcess.stderr.on('data', async res => { console.log(res); });

But i got the same situation. Not fixed..

@Jellyswat
Copy link
Author

@rom1v
Hi ~ Do we have any suggestion?

@rom1v
Copy link
Collaborator

rom1v commented Apr 21, 2023

You have to disable stdout buffering in some way in your program (I don't know NodeJS).

Also see: https://unix.stackexchange.com/a/25378
And nodejs/node#6379

@Jellyswat
Copy link
Author

Well, Lets see is there any way to disable stdout buffering in NodeJS.

Thanks for your helping ~~

@Jellyswat
Copy link
Author

Jellyswat commented Feb 20, 2024

@rom1v
For a long time search in StackOverflow and 'Node' repo issue,

I found that stdout has a buffer area while stderr does not.
Means, Stderr will print msg immediately.(That's why scrcpy 1.24 works.) But Stdout will wait for buffer fflush.

In my case, I use unbuffer scrcpy --serial xxx --port 12345 for a temporary plan. But its very difficult to use in Windows and MacOSX system.
So i strongly suggest to add fflush(stdout) when we print something in Stdout.

Reference material:

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