sndcpy icon indicating copy to clipboard operation
sndcpy copied to clipboard

Use ffplay instead of VLC

Open mekwall opened this issue 5 years ago • 7 comments
trafficstars

Instead of having VLC as a peer dependency you could distribute this package with a slimmed down version of ffplay and use the following command to play the audio:

$ ffplay -autoexit -nodisp -probesize 32 -f s16le -ar 48k -ac 2 -sync ext tcp://localhost:28200

Latency is still pretty bad, but better than VLC at least.

mekwall avatar Aug 16 '20 02:08 mekwall

hey @mekwall , maybe try this change? https://github.com/rom1v/sndcpy/commit/39bd8c74485cf6dd4f34d58b94ea4f1e8fbccacf I don't like this solution becuase it adds a lot of distortion to the audio sometimes

FerLuisxd avatar Oct 03 '20 01:10 FerLuisxd

Instead of having VLC as a peer dependency you could distribute this package with a slimmed down version of ffplay and use the following command to play the audio:

$ ffplay -autoexit -nodisp -probesize 32 -f s16le -ar 48k -ac 2 -sync ext tcp://localhost:28200

Latency is still pretty bad, but better than VLC at least.

@mekwall could you show how the batch file works with this updated change?

evansmosomi avatar Apr 09 '21 03:04 evansmosomi

Instead of having VLC as a peer dependency you could distribute this package with a slimmed down version of ffplay and use the following command to play the audio:

$ ffplay -autoexit -nodisp -probesize 32 -f s16le -ar 48k -ac 2 -sync ext tcp://localhost:28200

Latency is still pretty bad, but better than VLC at least.

@mekwall could you show how the batch file works with this updated change?

My solution (I'm still a batch file noob, don't roast me) Add this at the top:

if not defined FFPLAY set FFPLAY=ffplay.exe

and comment out the vlc line, then add this to replace it:

%FFPLAY% -autoexit -nodisp -probesize 32 -f s16le -ar 48k -ac 2 -sync ext tcp://localhost:%SNDCPY_PORT%

I'm still tweaking it, but the latency got alot better now.

johnchen40904 avatar Apr 13 '21 11:04 johnchen40904

Does this fix the buffer delay that keeps increasing as time goes?

R-N avatar Jul 12 '21 04:07 R-N

the ffplay line works forme; can't figure out how to record though.

this doesn't work (in sndcpy script) ffmpeg -y -probesize 32 -f s16le -ar 48k -ac 2 -i tcp://localhost:28200 out.ogg

clort81 avatar Sep 19 '21 05:09 clort81

Instead of having VLC as a peer dependency you could distribute this package with a slimmed down version of ffplay and use the following command to play the audio:

$ ffplay -autoexit -nodisp -probesize 32 -f s16le -ar 48k -ac 2 -sync ext tcp://localhost:28200

Latency is still pretty bad, but better than VLC at least.

@mekwall could you show how the batch file works with this updated change?

I switched from VLC to FFplay and it works great (Latency around 50-300ms) It's much better than VLC ffplay -f s16le -probesize 32 -ar 48000 -ac 2 -fflags nobuffer tcp://localhost:28200 -autoexit -nodisp -fflags nobuffer | removes buffering

Also in SCRCPY I set the delay to 200ms And now it's almost perfectly in sync

You also need to install the ffmpeg library for this to work. Here is the batch file code that you can use

`@echo off if not defined ADB set ADB=adb if not defined SNDCPY_APK set SNDCPY_APK=sndcpy.apk if not defined SNDCPY_PORT set SNDCPY_PORT=28200

if not "%1"=="" ( set serial=-s %1 echo Waiting for device %1... ) else ( echo Waiting for device )

%ADB% %serial% wait-for-device || goto :error %ADB% %serial% install -t -r -g %SNDCPY_APK% || ( echo Uninstalling existing version first %ADB% %serial% uninstall com.rom1v.sndcpy || goto :error %ADB% %serial% install -t -g %SNDCPY_APK% || goto :error ) %ADB% %serial% shell appops set com.rom1v.sndcpy PROJECT_MEDIA allow %ADB% %serial% forward tcp:%SNDCPY_PORT% localabstract:sndcpy || goto :error %ADB% %serial% shell am start com.rom1v.sndcpy/.MainActivity || goto :error

timeout 4

echo Playing audio. ffplay -f s16le -probesize 32 -ar 48000 -ac 2 -fflags nobuffer tcp://localhost:28200 -autoexit -nodisp goto :EOF

:error echo Failed with error #%errorlevel%. pause exit /b %errorlevel%`

ziengri avatar Jan 09 '23 21:01 ziengri

最近也在测试这段代码,正准备回复,发现已经有楼上的答案了。 实际上,如果加上-fflags nobuffer,不用-probesize 32也很流畅,几乎是正常感知的速度了,玩乒乓球时,我看到投屏的画面对方击发球了,心里预期听到声音时,声音就发出来了。 ffplay -hide_banner -fflags nobuffer -f s16le -ar 48k -ac 2 -sync ext -autoexit -nodisp -i tcp://localhost:%SNDCPY_PORT% 另:如多次开关音频投放,在创建端口转发前先关闭已建立的转发端口似乎成功率会大些。

%ADB% %serial% forward --remove-all

%ADB% %serial% forward tcp:%SNDCPY_PORT% localabstract:sndcpy || goto :error

wglnngt avatar Jan 10 '23 15:01 wglnngt