0

我修改了 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 文件的示例,如下所示。

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

我的问题是,如何仅从一个 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()));
    }
}
4

1 回答 1

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();
于 2014-11-17T23:01:04.327 回答