sndcpy icon indicating copy to clipboard operation
sndcpy copied to clipboard

mpv support?

Open sharunkumar opened this issue 4 years ago • 14 comments

Wondering if its possible to have a version that supports playing with mpv player

sharunkumar avatar Jun 16 '20 07:06 sharunkumar

Probably, or even aplay from ffmpeg.

But it's just a PoC, so I probably won't add options to select another player. You could just edit the last line of sndcpy to call mpv with the right parameters.

rom1v avatar Jun 16 '20 08:06 rom1v

hm got it. I put together this script after looking up the manual

@echo off
adb shell am start com.rom1v.sndcpy/.MainActivity
pause
mpv tcp://localhost:28200 --demuxer=rawaudio --no-cache --demuxer-cache-wait=no

but still there is some latency in the audio. is this unavoidable?

sharunkumar avatar Jun 16 '20 08:06 sharunkumar

Over USB or Wifi?

Do you get the same latency with VLC?

rom1v avatar Jun 16 '20 08:06 rom1v

Over USB.

Latency is there in VLC but not as much as experienced on MPV

sharunkumar avatar Jun 16 '20 08:06 sharunkumar

With VLC, do you see such lines in the console: https://github.com/rom1v/sndcpy/blob/master/README.md#audio-delay ?

If not, over USB, you could try to change --network-cache=50 (milliseconds) to a smaller value.

rom1v avatar Jun 16 '20 08:06 rom1v

If not, over USB, you could try to change --network-cache=50 (milliseconds) to a smaller value.

setting it to 0 has helped with reducing the latency. though I'm not sure how to set a similar setting in mpv. will have to look around.

on a related note, how do I close vlc when it is playing in the background?

sharunkumar avatar Jun 16 '20 09:06 sharunkumar

Okay, one more thing. When I play youtube, the audio forwards. But not when playing from an audio only source like spotify. is this intentional? 🤔

sharunkumar avatar Jun 16 '20 09:06 sharunkumar

setting it to 0 has helped with reducing the latency. though I'm not sure how to set a similar setting in mpv. will have to look around.

OK, I think I will change it to 0 by default then.

on a related note, how do I close vlc when it is playing in the background?

Because it's Windows and it's "console" vs "non-console" mode is stupid.

Once you clicked on START NOW, press Enter in the console to start playing on the computer. Press Ctrl+c in the terminal to stop (except on Windows, just disconnect the device or stop capture from the device notifications).

https://github.com/rom1v/sndcpy/blob/master/README.md

But not when playing from an audio only source like spotify. is this intentional?

https://github.com/rom1v/sndcpy/blob/master/README.md#apps-restrictions

rom1v avatar Jun 16 '20 09:06 rom1v

Damn sorry should have read the docs fully 😅

sharunkumar avatar Jun 16 '20 09:06 sharunkumar

Im trying to edit the file to use mpv instead of vlc but it's not working. Could i get step-by-step instructions to help out?

PieFlavours avatar Jun 09 '21 14:06 PieFlavours

Im trying to edit the file to use mpv instead of vlc but it's not working. Could i get step-by-step instructions to help out?

download and extract mpv and put inside mpv folder Copy paste this code to .bat file and run:

@echo off
if not defined ADB set ADB=adb
if not defined mpv set mpv="mpv\mpv"
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% forward tcp:%SNDCPY_PORT% localabstract:sndcpy || goto :error
%ADB% %serial% shell am start com.rom1v.sndcpy/.MainActivity || goto :error
echo Press Enter once audio capture is authorized on the device to start playing...
pause >nul
echo Playing audio...
%mpv% tcp://localhost:%SNDCPY_PORT% --demuxer=rawaudio --no-cache --demuxer-cache-wait=no
goto :EOF

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

DarkXonline avatar Jul 15 '21 10:07 DarkXonline

mpv uses the wrong sample rate. It should be 48 KHz as shown in VLC, but mpv always uses 44.1 KHz.

Tatsh avatar Oct 27 '21 15:10 Tatsh

To replace VLC with mpv or ffplay, I tried using the following line replacements (for the line bellow "echo Playing audio..."). They seem to work well. In fact, I get very little delay with ffplay and both processes terminate on Windows after closing the script.

For mpv:

mpv --demuxer=rawaudio --demuxer-rawaudio-rate=48000 --no-cache --untimed --no-demuxer-thread --demuxer-cache-wait=no --no-terminal tcp://localhost:%SNDCPY_PORT%

For ffplay:

ffplay -hide_banner -loglevel fatal -nodisp -f s16le -probesize 32 -ac 2 -ar 48000 -acodec pcm_s16le tcp://localhost:%SNDCPY_PORT%

mpv uses the wrong sample rate. It should be 48 KHz as shown in VLC, but mpv always uses 44.1 KHz.

I added the flag --demuxer-rawaudio-rate=48000, so that's fixed.

rafuwu avatar Feb 04 '22 11:02 rafuwu

To replace VLC with mpv or ffplay, I tried using the following line replacements (for the line bellow "echo Playing audio..."). They seem to work well. In fact, I get very little delay with ffplay and both processes terminate on Windows after closing the script.

For mpv:

mpv --demuxer=rawaudio --demuxer-rawaudio-rate=48000 --no-cache --untimed --no-demuxer-thread --demuxer-cache-wait=no --no-terminal tcp://localhost:%SNDCPY_PORT%

For ffplay:

ffplay -hide_banner -loglevel fatal -nodisp -f s16le -probesize 32 -ac 2 -ar 48000 -acodec pcm_s16le tcp://localhost:%SNDCPY_PORT%

mpv uses the wrong sample rate. It should be 48 KHz as shown in VLC, but mpv always uses 44.1 KHz.

I added the flag --demuxer-rawaudio-rate=48000, so that's fixed.

I was trying to do that as well, as I was sure that mpv wouldn't have delay (evidenced by other times I used mpv vs VLC). Your parameters worked great, thank you!

One thing for me (on Windows 10, mpv-x86_64-20220703-git-369168b), is that --no-terminal didn't stop an OSC screen appearing for MPV, so I deleted that and used --player-operation-mode=cplayer instead:

mpv --demuxer=rawaudio --demuxer-rawaudio-rate=48000 --no-cache --untimed --no-demuxer-thread --demuxer-cache-wait=no --player-operation-mode=cplayer tcp://localhost:%SNDCPY_PORT%

trykert avatar Jul 07 '22 17:07 trykert