jprjr / lua-music-visualizer

MIT License
4 stars 0 forks source link

I don't understand how to use this program #2

Closed GOKOP closed 3 years ago

GOKOP commented 3 years ago

Literally everything I try ends with the help message being printed

jprjr commented 3 years ago

Do you have an example?

Try something like: lua-music-visualizer /path/to/some/mp3 /path/to/some/lua/script ffplay pipe:0

GOKOP commented 3 years ago

Oooooh, the program to pipe the output into is supposed to be an argument. Ok, so now I've been able to make it running. But I'm running it with the example script "example: draw visualizer bars" from readme and I'm not getting any visualizations; just a black window

jprjr commented 3 years ago

Yeah, I need to revisit how those work - the bars set up during initialization, it's not very dynamic. You have to specify --bars=(whatever) as a CLI option, and it will calculate that many visualizer bars. If you don't specify that option, they're not calculated

GOKOP commented 3 years ago

And how do I do that? Those don't work:

./lua-music-visualizer --bars=10 ~/Music/something.mp3 myscript.lua ffplay pipe:0
./lua-music-visualizer ~/Music/something.mp3 myscript.lua ffplay pipe:0 --bars=10
./lua-music-visualizer ~/Music/something.mp3 "myscript.lua --bars=10" ffplay pipe:0 
./lua-music-visualizer ~/Music/something.mp3 myscript.lua --bars=10 ffplay pipe:0
./lua-music-visualizer ~/Music/something.mp3 --bars=10 myscript.lua ffplay pipe:0

And another question I have is how do I use it with MPD? I tried this but it obviously doesn't work because arguments aren't on right positions so they're misinterpreted

MPD_HOST=localhost ./lua-music-visualizer myscript.lua ffplay pipe:0
jprjr commented 3 years ago

It looks like I had two errors in that visualizer bars example. It was written back when the "amps" field was a value between 0-90, now it's between 0.0 and 1.0, so I need to multiply by whatever scaling you want. Also, ceil should be math.ceil (I have a habit in Lua scripts of saving local references to library functions, I usually have some preample like local ceil = math.ceil). I updated the example in the README, here it is for convenience:

-- set a maximum height for the bars, in pixels
local bars_height = 100
return {
    onframe = function()
        -- draws visualizer bars
        -- each bar is 10px wide
        -- bar height is between 0 and 100 (bars height)
        for i=1,stream.audio.spectrum_len,1 do
            stream.video:draw_rectangle((i-1)*20, 680 ,10 + (i-1)*20, 680 - (math.ceil(stream.audio.amps[i] * bars_height)) , 255, 255, 255)
        end

    end
}

Re: MPD, there's two ways - either define a FIFO output in MPD, or a pipe output, I recommend the FIFO.

So in your mpd.conf file have something like:

audio_output {
    type "fifo"
    name "fifo output"
    path "/tmp/mpd.fifo"
    format "48000:16:2"
}

Then after starting MPD, run the visualizer with:

MPD_HOST=localhost ./lua-music-visualizer --samplerate 48000 --channels 2 /tmp/mpd.fifo myscript.lua ffplay pipe:0
GOKOP commented 3 years ago

Okay, thank you! One last thing I wanted to know if it's possible to make this program silent; when it's playing MPD output it also plays sound, but it's already being played by MPD so I get double music (with latency)

jprjr commented 3 years ago

Well, it's not lua-music-visualizer that's playing the audio, it's ffplay (or whatever program you decide to use like mpv, etc).

To disable audio in ffplay there's the -an flag, so

MPD_HOST=localhost ./lua-music-visualizer --samplerate 48000 --channels 2 /tmp/mpd.fifo myscript.lua ffplay -an pipe:0
GOKOP commented 3 years ago

Ok then. thanks!