projectM-visualizer / projectm

projectM - Cross-platform Music Visualization Library. Open-source and Milkdrop-compatible.
https://discord.gg/mMrxAqaa3W
GNU Lesser General Public License v2.1
3.38k stars 375 forks source link

How can I render an mp3 to a video file? #205

Closed NightMachinery closed 1 year ago

NightMachinery commented 5 years ago

I like to render an mp3 to a video file. I took a look at https://github.com/projectM-visualizer/projectm/issues/10, but I didn’t find a way to do that? Was support of projectM ever added to https://github.com/djfun/audio-visualizer-python? Though that project seems dead anyways.

hsantanna commented 5 years ago

You mean, you want to export the visualization animation generated while playing a song (encoded as mp3) to a video file (encoded like a h264 mp4 or mkv).

Maybe try something like this: http://blog.scene.ro/posts/capturing-opengl-video-on-linux/

Iiridayn commented 4 years ago

Yeah, OBS can be set up to record the window + audio easily enough - but the setup runs at the rate of 1 second per second of output, and requires post-processing to trim the start/end.

Been digging into the code/API. Looks like it uses the batch approach. It might be simple to write an application which takes an audio stream in PCM s16le format over stdin, and writes a "video" stream of binary ppm images (p6 - trivial to implement w/o dependencies) over stdout from an OpenGL surface. This then could be used with a ffmpeg pipeline as ffmpeg -i <audio file> -f s16le -acodec pcm_s16le | <new program name> | ffmpeg -i <audio file> -f ppm_pipe -i - -map 0:a:0 -map 1:v:0 out.mkv or something (not great at ffmpeg cli, the second command is a guess, but something w/ppm_pipe should work).

Great example of the Unix philosophy overall - do one thing well - just missing pipe support :).

kblaschke commented 1 year ago

There's an old QuickTime-based command line tool that might have worked years ago, but it's no longer maintained and most probably defunct. Writing a new tool is currently not a top priority of the core dev team.

In addition to that, a few changes in the core library will be required to allow rendering presets at any speed, but a fixed target framerate and still have the visuals be synced to the audio. To be precise, the timekeeping in libprojectM is currently done using the OS clock and cannot be controlled from the outside. An API function to set a specific time value before each frame is needed, so preset switches and animation speeds match the video framerate in the final product.

Also, the new tool should ideally use ffmpeg/libav for audio decoding and video encoding instead of the closed-source and hardly portable QuickTime software.

If anyone wants to pick up on this, please chat with us on Discord, we'll be glad to help out!

kblaschke commented 1 year ago

Closing this issue, as we currently have no resources to implement it. We'll create a page in the Wiki with all sorts of suggested, but unimplemented applications of libprojectM.

msuiche commented 7 months ago

@Iiridayn This seems promising, anyway you managed to make this command work with projectMSDL ?

Iiridayn commented 7 months ago

@Iiridayn This seems promising, anyway you managed to make this command work with projectMSDL ?

Sorry to say it hasn't been a priority for me. As I mentioned, it shouldn't be terribly difficult - a CS Sophmore might be able to take it on as a semester project for example. (The code'd be bad compared to a senior, but hey, if it works...). If you build it, please let me know :).