How can I save media stream using RecorderEndpoint to remote server?

65 views
Skip to first unread message

이홍준

unread,
Feb 7, 2023, 7:14:48 AM2/7/23
to kurento
Hi Im trying to save media stream using RecorderEndpoint to remote server.
In Kurento java client doc, RecorderEndpoint supports post request.

 "POST request will be used against a remote server. The server must support using the chunked encoding mode (HTTP header Transfer-Encoding: chunked)."

I fixed tiny parts in kurento-hello-world-recording tutorial.
-----------------------------------------------------------------------------
private static final String RECORDER_FILE_PATH3 = "http://host.docker.internal:9090/recording/test123.webm";

RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, RECORDER_FILE_PATH3)
.withMediaProfile(profile).build();

... same with tutorial

-> kms is installed in docker based on wsl2
-----------------------------------------------------------------------------

And this is my spring web server for receiving POST request

@RestController
@RequestMapping("/recording")

@PostMapping(value = "/", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<String> mediaPost(@RequestBody InputStream recording) {
try {
    System.out.println(" ----- post request -----");
    return ResponseEntity.ok("Chunked encoding POST request received");
} catch (Exception e) {
    return ResponseEntity.badRequest().build();
    }
}


@PostMapping(value = "/{file}", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<String> mediaPost2(@PathVariable("file") String file, @RequestBody InputStream recording) {
try {
    System.out.println(" ----- post request -----");
    System.out.println(file);
    return ResponseEntity.ok("Chunked encoding MP4 POST request received");
} catch (Exception e) {
    return ResponseEntity.badRequest().build();
    }
}

both post controller doesn't work.
What's wrong with it?
Im really newbie about it :(
can you tell me some details about this problem?

thank you

Stefan Hellkvist

unread,
Feb 7, 2023, 8:23:11 AM2/7/23
to kurento
It is now many years since I last used the RecorderEndpoint, but back then one issue was that it could not resolve a name, thus you had to use the IP-address rather than the host name when you configured the URL. I am not sure if that is your problem though but I suggest you try to Wireshark the requests so that you see what the RecorderEndpoint is trying to send (if anything). I also suggest that you try to do a POST with some other tool - like curl - by using the same URL - just to test your endpoint so that you know which side is faulty.  

Neil Young

unread,
Feb 7, 2023, 9:37:25 AM2/7/23
to kur...@googlegroups.com
I would not recommend to use RecorderEndpoint at all. Once you overcome this problem you will run into the next with H.264 recording. There are better and more reliable ways using RtpEndpoint and FFMPEG. Also feeding an external server with chunked-http POSTs is not a problem at all.

이홍준

unread,
Feb 16, 2023, 11:42:02 PM2/16/23
to kurento
Is there a simple example using RtpEndpoint and FFmpeg? thank you

2023년 2월 7일 화요일 오후 11시 37분 25초 UTC+9에 Neil Young님이 작성:

Neil Young

unread,
Feb 17, 2023, 2:05:35 AM2/17/23
to kurento
The general idea has been published here first, I guess https://github.com/godka/kurento-rtmp

There is a high potential of making this better in many ways (e.g. dynamic port allocation from a pool in order to have a better control over the range, dynamic SDP creation depending on the properties of the incoming stream, variable FFMPEG parametrisation) and finally you need to add the HTTP push code, but this is where I was starting from and after you managed to wrap your head around you will have a Swiss army knife of doing WebRTC to RTMP, to RTSP, to HTTP Push etc :)

Neil Young

unread,
Feb 17, 2023, 2:06:45 AM2/17/23
to kurento
Ah, and for RTSP, RTMP and HLS I can really recommend to utilize https://github.com/aler9/rtsp-simple-server 
Reply all
Reply to author
Forward
0 new messages