The following code snippet allows you to record streams on demand. You can initiate it before the stream is published or after it’s already started.
public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp){ String queryStr = req.getQueryString(); queryStr = URLUtils.decodeValue(queryStr); MapqueryMap = HTTPUtils.splitQueryStr(queryStr); String responseStr = "Bad request"; if (queryMap.containsKey("application_name") && queryMap.containsKey("stream_name") ) { String applicationName = queryMap.get("appname"); String streamName = queryMap.get("stream"); String appInstanceName = (queryMap.containsKey("appinstance"))?queryMap.get("stream"):"_definst_"; IApplication application = vhost.getApplication(applicationName); IApplicationInstance appInstance = application.getAppInstance(appInstanceName); StreamRecorderParameters rp = new StreamRecorderParameters(appInstance); rp.recordData = true; rp.startOnKeyFrame = true; rp.fileFormat = IStreamRecorderConstants.FORMAT_MP4; vhost.getLiveStreamRecordManager().startRecording(appInstance, streamName, rp); responseStr = "Initiated recorder for "+streamName; } try { OutputStream out = resp.getOutputStream(); byte[] outBytes = responseStr.getBytes(); out.write(outBytes); } catch (IOException e) { e.printStackTrace(); } }