I have a job where I have to take continuous screenshots and capture sound from the desktop, and then publish them as a live video stream. I am using Wowza Media Server 3.0.3 to publish streams. I also use Xuggler to generate image frames and put them with sound buffers in packages. I have the following problem:
I run my program, and image frames and sound packets are published. The Wowza console tells me that packages are being published. When I open the media player (in this case, VLC), the video part of the stream works like a charm (I see that the graphic frames taken from my desktop continuously), but the audio part is very bad. I mean, when I start playing livestream, VLC buffers the approximately 3-second audio portion recorded from my desktop and plays it at a faster speed. After a longer break, it is buffered again and plays the next part. In my code, I constantly send iBuffers audio encoded in MP3 and publish them in packets, so I can’t understand why the sound does not play continuously, like image frames.
Can anyone get an answer or any experience in my problem?
I made a copy from my code, where I just transmit the desktop sound, not the image. This is the snippet where I receive the sound and send it for encoding and publishing:
while (true) { byte buffer[] = new byte[line.available()]; int count = line.read(buffer, 0, buffer.length); IBuffer iBuf = IBuffer.make(null, buffer, 0, count);
This is the part where I get iBuffer and encode it to mp3. After publication as a package:
public void encodeFrameToStream(IBuffer ibuffer, byte[] buffer, long firstTimeStamp) { long now = System.currentTimeMillis(); long timeStamp = (now - firstTimeStamp); IAudioSamples outChunk = IAudioSamples.make(ibuffer, 1, IAudioSamples.Format.FMT_S16); if (outChunk == null) { return; } long numSample = buffer.length / outChunk.getSampleSize(); outChunk.setComplete(true, numSample, 44100, 1, Format.FMT_S16, timeStamp);