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

Getting random error "pts has no value" #4536

Closed
theninthsky opened this issue Dec 15, 2023 · 10 comments
Closed

Getting random error "pts has no value" #4536

theninthsky opened this issue Dec 15, 2023 · 10 comments

Comments

@theninthsky
Copy link

Environment

  • OS: Windows
  • scrcpy version: 2.3.1
  • installation method: Windows release
  • device model: Levono Legion Y700 (2023)
  • Android version: 13

Describe the bug
Sometimes, right when I start recording, my terminal immediately gets spammed with these errors:

[server] INFO: Device: [Lenovo] Lenovo TB320FC (Android 13)
[server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.hevc'
DEBUG: Server connected
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
INFO: Recording started to mp4 file: file.mp4
DEBUG: Demuxer 'video': starting thread
DEBUG: Demuxer 'audio': starting thread
[server] DEBUG: Using audio encoder: 'c2.android.aac.encoder'
WARN: [FFmpeg] track 1: codec frame size is not set
[server] WARN: Could not get any audio timestamp
WARN: [FFmpeg] Packet duration: 5206291712 / dts: 5206292736 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206292735 / dts: 5206293760 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206293758 / dts: 5206294784 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206294781 / dts: 5206295808 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206295804 / dts: 5206296832 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206296827 / dts: 5206297856 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206297850 / dts: 5206298880 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206298873 / dts: 5206299904 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206299896 / dts: 5206300928 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206300919 / dts: 5206301952 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206301942 / dts: 5206302976 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206302965 / dts: 5206304000 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206303988 / dts: 5206305024 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206305011 / dts: 5206306048 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206306034 / dts: 5206307072 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206307057 / dts: 5206308096 is out of range
WARN: [FFmpeg] pts has no value
WARN: [FFmpeg] Packet duration: 5206308080 / dts: 5206309120 is out of range
WARN: [FFmpeg] pts has no value

I have no other choice than to abort the recording, and the recording file is damaged (it has size but it's unplayable).

@rom1v
Copy link
Collaborator

rom1v commented Dec 15, 2023

Does audio forwarding work if you don't record?

Please try with this additional log:

diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
index e3de50e63..a4e87bd11 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
@@ -161,6 +161,7 @@ public final class AudioCapture {
 
         long durationUs = r * 1000000 / (CHANNELS * BYTES_PER_SAMPLE * SAMPLE_RATE);
         nextPts = pts + durationUs;
+        Ln.d("pts=" + pts + "; duration=" + durationUs);
 
         if (previousPts != 0 && pts < previousPts + ONE_SAMPLE_US) {
             // Audio PTS may come from two sources:

Here is a binary, replace the file in your folder of scrcpy 2.3.1:

  • scrcpy-server SHA-256: 5e9ade0b488cb3b99e797640e899ab6e7c2f4258ee2612045212c16dabbcc06

Then run:

scrcpy -Vdebug

@theninthsky
Copy link
Author

@rom1v
I replaced my scrcpy-server file with yours and ran your debug command.
Yes, audio forwarding works just fine, I can hear the music coming out of my computer's screen.

Here is the command that I'm using when recording (if it helps):

scrcpy --audio-codec=aac --audio-bit-rate=384K --video-codec=h265 --video-encoder=OMX.qcom.video.encoder.hevc --video-bit-rate=40M --max-fps=60 --no-playback --verbosity=verbose --record=file.mp4

@rom1v
Copy link
Collaborator

rom1v commented Dec 16, 2023

my scrcpy-server file with yours and ran your debug command.

I'm interested in the full console output 😁

@theninthsky
Copy link
Author

theninthsky commented Dec 16, 2023

@rom1v
Of course, my bad.

C:\Users\Almog\Downloads\scrcpy-win64-v2.3.1>scrcpy -Vdebug
scrcpy 2.3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)              HA1W2C1F            device  TB320FC
DEBUG: Device serial: HA1W2C1F
DEBUG: Using server (portable): C:\Users\Almog\Downloads\scrcpy-win64-v2.3.1\scrcpy-server
C:\Users\Almog\Downloads\scrcpy-win64-v2.3.1\scrcpy-server...ile pushed, 0 skipped. 121.5 MB/s (103862 bytes in 0.001s)
[server] INFO: Device: [Lenovo] Lenovo TB320FC (Android 13)
DEBUG:[server] DEBUG: Using audio encoder: 'c2.android.opus.encoder'
 Server connected
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
[server] DEBUG: Using video encoder: 'c2.qti.avc.encoder'
INFO: Renderer: direct3d
DEBUG: Trilinear filtering disabled (not an OpenGL renderer
DEBUG: Using icon (portable): C:\Users\Almog\Downloads\scrcpy-win64-v2.3.1\icon.png
DEBUG: Demuxer 'video': starting thread
DEBUG: Demuxer 'audio': starting thread
INFO: Texture: 2560x1440
[server] WARN: Could not get any audio timestamp
[server] DEBUG: pts=0; duration=-2369
[server] DEBUG: pts=1584090621; duration=-2369
[server] DEBUG: pts=1584112406; duration=-2369
[server] DEBUG: pts=1584110037; duration=-2369
[server] DEBUG: pts=1584154975; duration=-2369
[server] DEBUG: pts=1584152606; duration=-2369
[server] DEBUG: pts=1584197672; duration=-2369
[server] DEBUG: pts=1584218964; duration=-2369
[server] DEBUG: pts=1584240293; duration=-2369
[server] DEBUG: pts=1584261649; duration=-2369
[server] DEBUG: pts=1584282942; duration=-2369
[server] DEBUG: pts=1584304431; duration=-2369
[server] DEBUG: pts=1584325582; duration=-2369
[server] DEBUG: pts=1584346940; duration=-2369
[server] DEBUG: pts=1584368271; duration=-2369
[server] DEBUG: pts=1584365902; duration=-2369
[server] DEBUG: pts=1584389618; duration=-2369
[server] DEBUG: pts=1584410933; duration=-2369
[server] DEBUG: pts=1584432269; duration=-2369
.
.
.
DEBUG: User requested to quit
DEBUG: quit...
DEBUG: Server disconnected
DEBUG: Server terminated
DEBUG: Demuxer 'audio': end of frames
DEBUG: Receiver stopped
DEBUG: Demuxer 'video': end of frames

rom1v added a commit that referenced this issue Dec 16, 2023
The result is assign to a long (64-bit signed integer), but the
intermediate multiplication was stored in a int (32-bit signed integer).

This value is only used as a fallback when no timestamp could be
retrieved, that's why it did not cause too much harm.

Fixes #4536 <#4536>
rom1v added a commit that referenced this issue Dec 16, 2023
If the initial timestamp could not be retrieved, use the current time as
returned by System.nanoTime(). In practice, it is the same time base as
AudioRecord timestamps.

Fixes #4536 <#4536>
rom1v added a commit that referenced this issue Dec 16, 2023
The result is assigned to a long (64-bit signed integer), but the
intermediate multiplication was stored in an int (32-bit signed
integer).

This value is only used as a fallback when no timestamp could be
retrieved, that's why it did not cause too much harm so far.

Fixes #4536 <#4536>
rom1v added a commit that referenced this issue Dec 16, 2023
If the initial timestamp could not be retrieved, use the current time as
returned by System.nanoTime(). In practice, it is the same time base as
AudioRecord timestamps.

Fixes #4536 <#4536>
@rom1v
Copy link
Collaborator

rom1v commented Dec 16, 2023

Interesting.

Here is a new branch fixing two problems: issue4536

Please test this binary:

@theninthsky
Copy link
Author

@rom1v
It seems that I'm missing some sort of DLL.

image

@rom1v
Copy link
Collaborator

rom1v commented Dec 16, 2023

Sorry, my bad, I made a mistake. I updated the link in the previous comment. Please retry.

@theninthsky
Copy link
Author

theninthsky commented Dec 16, 2023

@rom1v
Yeah, it seems recording always works now (I tried multiple times).

I only got [server] WARN: Could not get initial audio timestamp one time but the recorded file was perfectly fine.

@theninthsky
Copy link
Author

@rom1v
Thanks a lot!

@rom1v
Copy link
Collaborator

rom1v commented Dec 17, 2023

Merged into dev. 🚀

@rom1v rom1v closed this as completed Dec 17, 2023
armm29393 added a commit to armm29393/scrcpy-root that referenced this issue May 24, 2024
scrcpy v2.4

Changes since v2.3.1:
 - Add UHID keyboard and mouse support (Genymobile#4473)
 - Simulate tilt multitouch by pressing Shift (Genymobile#4529)
 - Add rotation support for non-default display (Genymobile#4698)
 - Improve audio player (Genymobile#4572)
 - Adapt to display API changes in Android 15 (Genymobile#4646, Genymobile#4656, Genymobile#4657)
 - Adapt audio workarounds to Android 14 (Genymobile#4492)
 - Fix clipboard for IQOO devices on Android 14 (Genymobile#4492, Genymobile#4589, Genymobile#4703)
 - Fix integer overflow for audio packet duration (Genymobile#4536)
 - Rework cleanup (Genymobile#4649)
 - Upgrade FFmpeg to 6.1.1 in Windows releases (Genymobile#4713)
 - Upgrade libusb to 1.0.27 in Windows releases (Genymobile#4713)
 - Various technical fixes
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