Red5 video stream recording is breaking up

孤人 提交于 2019-12-01 00:42:43

*But what should I put into the packetReceived() function? *

I add this in a separated answer to highlight correctly:

To write the packets to disk, you need: 1) the packet, 2) convert the packet to an ITag 3) Obtain an instance of a ITagWriter

1) the packet data http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/StreamVideoListener.java?view=markup around Line 50

public void packetReceived(IBroadcastStream broadcastStream,
  IStreamPacket streampacket) {

}

streampacket => the packet you want to write to disk.

2) write the packet by converting it to a ITag

http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/StreamVideoWriter.java?view=markup around Line 90ff

        IoBuffer data = streampacket.getData().asReadOnlyBuffer();

        if (data.limit() == 0) {
            return;
        }

        if (startTimeStamp == -1) {
            // That will be not bigger then long value
            startTimeStamp = streampacket.getTimestamp();
        }

        timeStamp -= startTimeStamp;

        ITag tag = new Tag();
        tag.setDataType(streampacket.getDataType());

        // log.debug("data.limit() :: "+data.limit());
        tag.setBodySize(data.limit());
        tag.setTimestamp(timeStamp);
        tag.setBody(data);

        writer.writeTag(tag);

3) Obtaining an instance of a Writer

http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/BaseStreamWriter.java?view=markup around Line 90ff

protected ITagWriter writer = null;

private void init() throws IOException {
    file = new File(OmFileHelper.getStreamsSubDir(this.scope.getName()), this.streamName + ".flv");

    IStreamableFileFactory factory = (IStreamableFileFactory) ScopeUtils
            .getScopeService(this.scope, IStreamableFileFactory.class,
                    StreamableFileFactory.class);

    if (!this.file.isFile()) {
        // Maybe the (previously existing) file has been deleted
        this.file.createNewFile();

    } else if (!file.canWrite()) {
        throw new IOException("The file is read-only");
    }

    IStreamableFileService service = factory.getService(this.file);
    IStreamableFile flv = service.getStreamableFile(this.file);
    this.writer = flv.getWriter();

}

So this is a rough walk through. In that sense you can then go ahead.

The http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/BaseStreamWriter.java?view=markup

class also contains a Queue to collect the packets.

IStreamPacket.getType == 9 is video and I think 8 is audio (but you need to verify that).

Sebastian

What recording method do you use now? There are actually 2 methods in Red5 to record: 1) NetStream.record => this is plain simple 2) You do NetStream "live" but you have a server side StreamListener that you attach to the stream and then write the stream to disc.

I have implemented both solutions successfully at: http://incubator.apache.org/openmeetings/ There is no choppy video or random stop/pause.

There is no need to integrate FFMPEG or Xuggler to do a simple recording with Red5! FFMPEG might be useful if you want to modify the resulting video and add a watermark. For audio editing you might use tools like SoX. However ... just plain record and playback as-is does not require those tools at all!

Sebastian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!