I have some 2-channel 16-bit 44.1KHz PCM data in a string in a PHP daemon. I would like to output that data through the line out jack at the server (Not through a browser). I've struggled finding much on Google since this isn't something people would normally be doing.
The code will run on CentOS7/RockyLinux and doesn't need to be portable with any other OSs. It looks like I somehow need to get the PCM data either directly to ALSA or through PulseAudio. I've found a few examples of changing the output volume using those but nothing to actually get audio data to them.
Is there a "file" I can stream the PCM data to or a command line utility that would accept PCM data through STDIN? It looks like PulseAudio can play over the network so is there a spec for how to stream audio through a socket to it?
I don't need incredibly low latency, less than 1 second would be fine. This is a long running process that is continually generating PCM data so I need a solution that can run indefinitely. For example, writing the PCM data to a wav file and simply shelling an external process isn't an option. It needs to be a continuous stream.
Related
So I am new to Perl and web development but I was hoping to get some guidance on the following issue.
Server 1 is transcoding video for me and has an api endpoint for me to access. It will give me the file stream that I want to push to the web.
So for the sake of the problem lets say that it is accessed at:
server1:123\video_stream
Server2 is my web server and I want to have a page that lets us access this video stream file
server2:80\web_stream
I have seen in php you can do readfile("server1:123\video_stream) but the entire video_stream will be read into memory before being output to the page... or so I was told.
I have also seen in Perl that ffmpeg output can but routed through the open(DATA, $ffmpegProcess) then printing the buffer read from this stream to the web_stream page...
This all assumes that the header information about the attributes of the video are correct.
Would it be as simple as making a curl request to Server 1 and returning that stream output like I can already with the ffmpeg output?
I am not looking for complete solution, just some direction on the best and most correct way to do this. Maybe php and Perl are not the right tools to handle this at all?
ffserver seems like the better tool to use. It's part of the ffmpeg family.
PHP readfile() is a good way to do this. If you read the PHP manual page the discussion tells you how to deal with different possibilites of reading the file in chunks and dealing with memory issues.
I need to be able to
Tell if the file is a proper wav or flac file
Get the bitrate from it
Get the sample rate / kHz
Get the bit rate
using php and external tools like ffmpeg for example (if possible to use it) that i can execute and get their output back via php.
Any suggestions for the best and most reliable solution? I'm not asking for an implementation but the best tool or library to get these information via php.
Try to Google for open source project, which can do it (Some C++/Delphi etc), then search for Bytes they read to determinate the parameters you want. Then just use php fread() and compare the bytes.
After some research I found sox, i think this will do it http://sox.sourceforge.net/ as I asked for.
I have an HTML 5 website where I want to stream videos from a torrent server. I don't know which Linux torrent client to use. Can I use PHP as a torrent client?
Example:
<video src="downloder.php?file=movie.mp4"
downloader.php would then return an mp4 file from the .torrent file.
You can use #feross' fantastic library, webtorrent. This works in both Node.js and the browser.
HTML5/javascript can't do the bittorrent protocol. Java applets can, but few browsers support java applets out of the box these days. https://webtorrent.io/ is an alternate protocol that works in the browser. It can't communicate via the bittorrent protocol though, so only works with webtorrent trackers (and piers that speak webtorrent.)
I don't think it is even possible to stream from torrent. Files from torrent are separated into small chunks that are obtained unordered, when/if you will get them from other clients, when/if other clients decide to send them to you.
The torrent file doesn't contain any data to stream. Your PHP server would have to start receiving the torrent data from other peers (that is how torrents work).
MP4 is not a format that needs every byte to play - that is why QuickTime can start playing before completely downloading (hence streaming), but the bytes to play need to be at the start (or at the end, but in any case) - torrents do not 'load' in 'byte order'. As the above user says, torrents load data in chunks. You'd need at least the header.
It's just not realistic.
So I have users who have told me they are interested in being able to upload videos to my site straight from DVD's (for which they own the rights, of course).
I've never encountered this before, but I would imagine this would take an enormous amount of resources and would clog up the servers, which I would like to avoid.
A basic google search returns numerous DVD to FLV converters but all seem to appear to be applications which would need to be used to convert the files before uploading.
So, if this isn't a horrible idea, how would I go about implementing it using PHP or any Linux command line tool?
Or if this is insane, Why is this a bad idea? and What are other possible alternatives?
As an example, I could see an alternative being:
showing information about how to convert the files to a valid upload format before uploading
Search for ffmpeg - i don't know does it reads DVD files, but most of video formats can, see:
http://en.wikipedia.org/wiki/Libavcodec
It's a command line program, which can convert between many video formats.
You can't avoid huge load on server, because converting video simply require lot of computations. Maybe there is a way to restrict resources that program takes and slow it down - but it will have cost in execution time. On multi-core server, only one core will be loaded when converting video, so maybe this is not a problem ?
Remeber that uploading large files (like DVD video is) can also be a problem, and you should watch to nice uploader with progress bar (for example flash uploader)
I would like know if it is possible to create embedding of audio message to audio files?
For example, on playing every 10 sec of an audio, it would be interrupted with an audio message "You are currently listening to an audio by XYZ band" and then the audio continues. And even if someone were to download the mp3 file, the audio message is still embedded with that downloaded file?
May I know if there are any libraries or classes that can work with php to achieve the above result? And what would be the workflow?
Thank you very much.
You definitely can't do that in pure PHP - in theory you could write a MP3 decoding and encoding engine for PHP but it's an insane idea - and you will need some server side help for the task.
ffmpeg should enable you to mix multiple MP3s together to one file, provided your host supports it.
I would use sox for everything. It can decode and chop up the audio into segments, into which you can interject your message, and then render the sequence into a new mp3 file. It should also be able to overlay the messages onto the audio, so you don't break up the music, which might sound more pleasant.
Of course, this means using PHP just for management. The signal processing would be done by sox. If you really want to do as much as possible in PHP, use an external tool to decode the mp3 into a wave file, load the PCM into an integer array in PHP, and manipulate it there. PHP is probably not very fast when it comes to number crunching like this, but it should be possible. Save the PCM to disk for final encoding.