html 5 audio streaming faking files. Progressive Download, PCM WAV - html

As far as i know there is no audio streaming available in html5. Even with the audio tag.
That is, you always have to provide a file instead of passing an audio stream of some sort.
So, we know that most commonly used formats are ogg and mp3(not free). Also wav can be used but due to its size not commonly used.
My question is can I fake a file as if it was a stream, say create the wav file (with the riff header) and specify the PCM format details(freq,channel,blah blah) and pass that as the first few bytes and then send the PCM stream over the wire(actualy audio chunks).
The first issue I see if that RIFF header in the wav files require the chunk sizes which is the length of the file. WELL WE DONT HAVE A LENGTH SINCE IT IS AN AUDIO STREAM.
Any ideas.

Yes, absolutely.
The client doesn't need to know or care that the media it is playing is created live, or being loaded from disk.
You may have challenges depending on the codec used. WAV present the problems you have mentioned with the header, but it should be possible. With MP3, you can generally just send data at any point, and the decoder will sync to the frames on its own.

Related

Streaming adaptive audio on the web (low latency)

I am attempting to implement a streaming audio solution for the web. My requirements are these:
Relatively low latency (no more than 2 seconds).
Streaming in a compressed format (Ogg Vorbis/MP3) to save on bandwidth.
The stream is generated on the fly and is unique for each client.
To clarify the last point, my case does not fit the usual pattern of having a stream being generated somewhere and then broadcast to the clients using something like Shoutcast. The stream is dynamic and will adapt based on client input which I handle separately using regular http requests to the same server.
Initially I looked at streaming Vorbis/MP3 as http chunks for use with the html5 audio tag, but after some more research I found a lot of people who say that the audio tag has pretty high latency which disqualifies it for this project.
I also looked into Emscripten which would allow me to play audio using SDL2, but the prospect of decoding Vorbis and MP3 in the browser is not too appealing.
I am looking to implement the server in C++ (probably using the asynchronous facilities of boost.asio), and to have as small a codebase as possible for playback in the browser (the more the browser does implicitly the better). Can anyone recommend a solution?
P.S. I have no problem implementing streaming protocol support from scratch in C++ if there are no ready to use libraries that fit the bill.
You should look into Media Source Extension.
Introduction: http://en.wikipedia.org/wiki/Media_Source_Extensions
Specification: https://w3c.github.io/media-source/

Looking to understand RTSP and H.264 Encapsulation

I am trying to learn enough about H.264, RTP, RTSP and encapsulation file formats to develop a video recording application.
Specifically, what should I read to understand the problem?
I want to be able to answer the following questions:
Can I save H.264 packets or NALs (Per RFC 6184) to a file?
Can I save the individual payloads as files?
Can I join the RTP payloads simply by concatenating them?
What transformation is needed to save
several seconds of H.264 video in an MP4 container.
What must be done
to later join these MP4 files, or arbitrarily split them, or serve
them as a new RTSP presentation?
I want to be able to answer these questions on a fairly low level so I can implement software that does some of the processes (capture RTP streams, rebroadcast joined MP4s).
Background
The goal is to record video from a network camera onto disk. The camera has an RTSP server that provides an H.264 encoded stream which it sends via RTP to a player. I have successfully played the stream using VLC, but would like to customize the process.
The "raw" video stream is a sequence of NAL units, per H.264 specification. Neither on RTSP, nor on MP4 file you have this stream "as is".
On RTSP connection you typically receive NAL units fragmented, and you need to depacketize them (no you cannot simply concatenate):
RTP H.264 Packet Depacketizer
How to process raw UDP packets so that they can be decoded by a decoder filter in a directshow source filter
MP4 file is a container formatted file, and has its own structure (boxes). So you cannot simply stream NALs into such file and you have to do what is called multiplexing.
How do I create an mp4 file from a collection of H.264 frames and audio frames?
just install rtmpdump along with rtmpsrv and rtmpsuck...
this will do all the work
in one terminal open rtmpsrv and in other open rtmpdump -r "RTMP URL"
this will save the stream in mystream.flv

Is it necessary to convert database of mp3's to ogg and wave to use html audio?

I have thousands of mp3 files in a database and a website that lets people listen to them. I'm using a flash player but want to move to html5 audio player. Does this mean that I need to make ogg and wave versions of all my audio files? What is a good approach to making these files more accessible?
In short, yes you need to support multiple formats. (Assuming you care about decent browser support.)
If you are lacking disk space, don't get a lot of traffic, and don't mind some delay before the data gets to the user, you can convert these on the fly. Just write some code so that on request, it checks the conversion cache to see if you have already converted the file. If not, convert it on the fly (with something like FFMPEG) and write the data to disk at the same time you are writing it to the client.
As Imre pointed out, browser support is changing all the time. Look up what codecs are supported from time to time.

Is it possible to convert an avi file to mp4 in real time?

I have an AVI file that I would like to be played inside Flowplayer. I understand it uses HTML5 which requires movie files to be converted to MP4/OGV, so I was wondering if there was a framework that exists which will convert an AVI file to an MP4 file in real-time (and without necessarily being stored on the server)
...the more I think about this, the more I'm beginning to think this isn't possible. Please prove me wrong.
The video can be transcoded in (sort of) realtime by hardware or even software, but I'ts never a practical aproach since you are spending lot of processing power for each client for each video. This is madness. It's adviceable to cache pages... so videos are needed to be cached.
A simple way is to upload/place the video in a folder in the server, then trigger a transcoding (using FFMPEG) to a file which is the file to be served.

Live Audio Streaming to a browser methods, must be very simple

I'm recording a mono audio stream using a PIC at 8-bit 8Khz and streaming it raw to another microprocessor that houses a web server. I'm currently buffering the data and turning it into a wav file that gets played in the browser. What I'd like to be able to do is continuously stream the audio as it's being recorded without putting a lot of encoding overhead on the second processor. I've been searching but most searches turn up just streaming from a stored file, but since the file size isn't known ahead of time I'm not sure how to do this without the overhead of mp3 encoding.
You may find that simply creating a WAV file (or other raw format) that keeps growing will, in most players/browser plugins, cause the file to act as a live stream. This is, I believe, basically how like Ogg streaming and similar works. Because the player begins playing before it is done downloading anyway, it keeps playing and downloading until the end of the file, but the file has no end so it just keeps going.
Vlc media player can stream flv and many other formats.