kurento:如何在webm和mp4记录点上记录网络摄像头?

时间:2014-11-16 21:55:45

标签: webrtc webcam-capture kurento

我修改了kurento的one2many教程(https://github.com/Kurento/kurento-tutorial-java/blob/master/kurento-one2many-call/src/main/java/org/kurento/tutorial/one2manycall/CallHandler.java)示例,将网络摄像头流记录到mp4或webm文件中,如下所示。

在这里我注释掉RecorderEndpoint编写mp4。

我的问题是,如何从一个WebRtcEndpoint写出两个文件(webm和mp4)? 我想过使用DispatcherOneToMany(http://www.kurento.org/docs/4.2.0/kmf-media-api/com/kurento/kmf/media/DispatcherOneToMany.html)但是setSource需要一个HubPort,我无法使用我的WebRtcEndpoint masterWebRtc。 那么如何将masterWebRtc调度到两个RecorderEndpoint?

感谢您的帮助。

private synchronized void master(WebSocketSession session,
        JsonObject jsonMessage) throws IOException {
    if (masterUserSession == null) {
        masterUserSession = new UserSession(session);

        pipeline = kurento.createMediaPipeline();
        masterUserSession.setWebRtcEndpoint(new WebRtcEndpoint.Builder(
                pipeline).build());

        WebRtcEndpoint masterWebRtc = masterUserSession.getWebRtcEndpoint();
        String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer")
                .getAsString();
        String sdpAnswer = masterWebRtc.processOffer(sdpOffer);

        JsonObject response = new JsonObject();
        response.addProperty("id", "masterResponse");
        response.addProperty("response", "accepted");
        response.addProperty("sdpAnswer", sdpAnswer);
        masterUserSession.sendMessage(response);

        //RecorderEndpoint recorderEndpoint =  new RecorderEndpoint.Builder(pipeline,"file:///tmp/recording.mp4").withMediaProfile(MediaProfileSpecType.MP4).build();
       RecorderEndpoint recorderEndpoint =  new RecorderEndpoint.Builder(pipeline,"file:///tmp/recording.webm").withMediaProfile(MediaProfileSpecType.WEBM).build();
        masterWebRtc.connect(recorderEndpoint);
        recorderEndpoint.record();

    } else {
        JsonObject response = new JsonObject();
        response.addProperty("id", "masterResponse");
        response.addProperty("response", "rejected");
        response.addProperty("message",
                "Another user is currently acting as sender. Try again later ...");
        session.sendMessage(new TextMessage(response.toString()));
    }
}

1 个答案:

答案 0 :(得分:1)

在Kurento中,所有媒体元素都是“一对多”,这意味着您可以根据需要将源媒体元素连接到任意数量的媒体元素。关注您的代码:

RecorderEndpoint recorderEndpointA =  new RecorderEndpoint.Builder(pipeline,"file:///tmp/recording.mp4").withMediaProfile(MediaProfileSpecType.MP4).build();
RecorderEndpoint recorderEndpointB =  new RecorderEndpoint.Builder(pipeline,"file:///tmp/recording.webm").withMediaProfile(MediaProfileSpecType.WEBM).build();

masterWebRtc.connect(recorderEndpointA); //masterWebRtc is source, recorderEndpointA is sink
masterWebRtc.connect(recorderEndpointB); //masterWebRtc is source, recorderEndpointB is sink

//you could connect masterWebRtc to other additional elements here if you want.

recorderEndpointA.record();
recorderEndpointB.record();