Wowza Community

Recording Wowza with URL Queries from Postman or Java

Hello,

I am currently doing a simple service application that is making live broadcas of wowza apps, for me it is so clear that how to make streaming lively with wowza and i’ve reached that goal.

Currently, my expectations is to use also start recording in cases using url queries of wowza media engine, but somehow my implementations are always getting “401 unauthorized”. Trying to making it via browser always works with correct credentials, but Postman or java always get response as 401.

http://username:password@ipadress:8086/livestreamrecord/index.html

Above url, is easliy reachable from Chrome, but when i try to use Postman, i can’t get any result. I don’t know how i can start and stop recording by usage of below queries if i can’t manage to reach wowza media engine :

http://username:password@ipadress:8086/livestreamrecord?app=yanda&streamname=hayra&action=startRecording&outputFile=yanda_12347.mp4

http://username:password@ipadress:8086/livestreamrecord?app=yanda&streamname=hayra&action=stopRecording&outputFile=yanda_12347.mp4

I am using retrofit2 on my android application and here is the code that i am using it :

//WowzaIntefaceUtils

public class WowzaInterfaceUtils {
    public static final String BASE_URL = "http://username:password@ipadress:8086/";
    public static WowzaInterfaceController getWowzaInterfaceController(){
        return WowzaInterfaceClient.getClient(BASE_URL).create(WowzaInterfaceController.class);
    }
}

//WowzaInterfaceClient

 */

public class WowzaInterfaceClient {private static Retrofit retrofit = null;

    public static Retrofit getClient(String baseUrl) {
        if (retrofit==null) {
            OkHttpClient.Builder client = new OkHttpClient.Builder();
            client.followRedirects(false);
            OkHttpClient httpClient = client.build();
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .client(httpClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

}

//WowzaInterfaceController
@GET("/livestreamrecord")
@Streaming
Call<ResponseBody> livestreamrecord(@Query("app") String app, @Query("streamname") String streamName,
                                    @Query("action") String action, @Query("outputFile") String outputFile);

//On Retrofit call

public void startCameraRecording(String app, String streamName,String outputFile){
    wowzaInterfaceController = WowzaInterfaceUtils.getWowzaInterfaceController();
    Log.i("YTA_CameraRecording","Camera recording will be started");

    wowzaInterfaceController.livestreamrecord(app,streamName,"startRecording",outputFile).enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Log.i("YTA_CameraRecording", "Start camera responded : " + response.code());
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.e("YTA_CameraRecording", "Start camera failed");
        }
    });
}

The 401 error you are getting is caused by not providing a username or password. Additional information on enabling and disabling authentication can be found in the article below.

https://www.wowza.com/docs/how-to-change-the-authentication-method-for-the-wowza-streaming-engine-rest-api

Authentication would look like this.

curl --digest -u "username:password" http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/incomingstreams/myStream

Below is an example of creating a recorder by using our REST API that will:

1) Record the myStream live stream that is under the default live application to the default content folder.

2) Give the recording the Base name of the live feed and specify that segment numbers should be used.

3) Specifying the file template can be done only through the API. This value is never saved in Application.xml.
https://www.wowza.com/docs/how-to-record-live-streams-wowza-streaming-engine#setfiletemplate

4) Configure the segment duration to be 15 minutes (900,000 milliseconds)

Note that API authentication is disabled in this example.

curl -X POST --header 'Accept:application/json; charset=utf-8' --header 
'Content-type:application/json; charset=utf-8' 
http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream
 -d '
{
"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream",
"recorderName":"myStream",
"instanceName":"_definst_",
"recorderState":"Waiting for stream",
"defaultRecorder":true,
"segmentationType":"SegmentByDuration",
"baseFile":"myStream.mp4",
"fileFormat":"MP4",
"fileVersionDelegateName":"com.wowza.wms.livestreamrecord.manager.StreamRecorderFileVersionDelegate",
"fileTemplate":"${BaseFileName}_${RecordingStartTime}_${SegmentNumber}",
"segmentDuration":900000,
"segmentSize":10485760,
"segmentSchedule":"0 * * * * *",
"recordData":true,
"startOnKeyFrame":true,
"option":"Version existing file",
"moveFirstVideoFrameToZero":true,
"currentSize":0,
"currentDuration":0,
"recordingStartTime":""
}'

Wowza Streaming Engine will, by default, save all recordings in the default content location.
https://www.wowza.com/docs/how-to-change-the-storage-location-of-vod-content

You can specify an alternate location for the content to be saved to by adding the “outputPath” option as shown in the article below:
https://www.wowza.com/docs/how-to-record-live-streams-wowza-streaming-engine#livestreamrecordproperties

Please note that Wowza Streaming Engine needs write access to the location you specify. Please adjust user and/or service permissions accordingly.

There is no way to specify recording time limits either inside or outside of the API. If you need an exact 15 minute recording and no segments created outside of that one 15 minute segment then you will need to stop the recorder manually, create a script for automation, or delete any additional or unwanted segments once the recording has stopped.

The recording can be stopped via our REST API as follows:

curl -X PUT --header 'Accept:application/json; charset=utf-8' --header 
'Content-type:application/json; charset=utf-8' 
http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream/actions/stopRecording

I suggest that if you are unfamiliar with Wowza Streaming Engine’s REST API that you use our Swagger documentation. More information on how to enable both the REST API and the documentation can be found in the following article:
https://www.wowza.com/docs/how-to-access-documentation-for-wowza-streaming-engine-rest-api

The download link is buried in the article above. You can download the documentation here:

https://www.wowza.com/downloads/forums/restapidocumentation/RESTAPIDocumentationWebpage.zip

Yes this is working through your browser as you already have authenticated and already have a cookie. Try it in incognito mode or clear your cookies and you won’t see it.

Basically you’ll have to acquire an authentication cookie and then try again, sending this cookie in the request.

I am running the curl command via bash. There is no cookie involved. I can also run it via Cygwin and there is still no cookie involved. Curl works on servers that have no web browsers installed.