Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

By default, the file name is formed by template

Code Block
languagebash
themeRDark
stream_record_policy=template

In its turn, the template is specified with stream_record_policy_template parameter. By default:

Code Block
languagebash
themeRDark
stream_record_policy_template=stream-{mediaSessionId}-{login}

...

ElementDescriptionMaximum size
{streamName}Stream name
{startTime}Recording start time20 characters
{endTime}Recording end time20 characters
{sessionId}Session ID in BASE64 encoding60 characters
{mediaSessionId}Media session ID36 characters
{login}Login32 characters
{audioCodec}Audiocodec4 characters
{videoCodec}Videocodec4 characters

For example,

Code Block
languagebash
themeRDark
stream_record_policy_template={streamName}

means that the file name will match the stream name. So, the stream published with ffmpeg

Code Block
languagebash
themeRDark
ffmpeg -re -i BigBuckBunny.mp4 -preset ultrafast -acodec aac -vcodec h264 -strict -2 -f flv rtmp://test1.flashphoner.com:1935/live/stream_ffmpeg

will be written to file stream_ffmpeg.mp4.

File extension is set depending on stream parameters and container used: mp4 for H264+AAC and webm for VP8+opus.

When the file name matches the stream name, it may contain characters that are not allowed in file names, slash '/' for example. In that case, the file name should be encoded using the parameter

...

specifies a fragment duration as 10 seconds . Recording fragments are numbered continuosly from 1, the last rcorded fragment is not numberedand setting

Code Block
languagebash
themeRDark
record_rotation=10M

defines a fragment maximum volume as 10 megabytes.

If recording file name template contains {startTime} element, fragments will not be numbered, and recording fragment start timestamp will be inserted into file name. If template contains {endTime} element, recording fragment end timestamp will be inserted into file name. For example, if the following settings are used

Code Block
themeRDark
record_rotation=20
stream_record_policy=template
stream_record_policy_template={streamName}-{startTime}-{endTime}

...

Code Block
themeRDark
test-1553577643961-1553577663988_1.mp4
test-1553577663989-1553577683997_2.mp4
test-1553577683997-1553577701626_3.mp4
...

Recording fragments are numbered continuosly from 1. For every new mediasession (even if stream is published with the same name) indexing starts again, i.e. old fragments will be overwritten if static part of file name template is not unic (stream name only for example).

Indexing can be disabled if necessary with the following parameter

Code Block
themeRDark
record_rotation_index_enabled=false

In this case recording fragments are not numbered and will be named exactly as template sets. If template does not provide unic names, old fragments may be overwritten.

Record files handling script

...

REST method

Example of REST query

Example of REST response

Response statuses

Description

/stream/startRecording


Code Block
languagejs
themeRDark
{
 "mediaSessionId": "5a072377-73c1-4caf-abd3"
  "config": {
    "fileNamefileTemplate": "recordStream.mp4{streamName}-{startTime}-{endTime}",
    "forcerotation": "true20M"
  }
}

404 - Not found

500 - Internal error


Start stream recording in specified mediasession


/stream/stopRecording
Code Block
languagejs
themeRDark
{
 "mediaSessionId": "5a072377-73c1-4caf-abd3"
}

404 - Not found

500 - Internal error

Stop stream recording in specified mediasession

...

fileName

Parameter name

Description

Example

mediaSessionId

Media session identificator

5a072377-73c1-4caf-abd3

configRecord settings that redefine server settings
fileTemplateRecording file name recordStream.mp4forceOverwrite the recording file on the next template{streamName}-{startTime}-{endTime}
rotationEnables/disables rotation and duration/volume of fragments
20M

Recording on demand works as follows:

  • When REST API /stream/startRecording

...

true

If REST query does not set recording file name explicitly, the stream in mediasession defined will be recorded to file named by template settings.

If file name is explicitly set, the stream will be recorded to file with this name. If file exists, then

1. If force:false (by default), and stream in this mediasession is already writing to this file, the file will not be owerwritten, current recording will continue. If the stream is not writing, and file  already exists, it will be overwritten.

...

  • query is called, current recording will be stopped.
  • New recording starts with settings passed in REST query.
  • If some setting is not defined in REST query, the server setting will be applied.

For example if recording should have exact file name with rotation disabled, the following query should be passed:

Code Block
languagejs
themeRDark
/stream/startRecording
{
  "mediaSessionId":"1234567890abcdefgh",
  "config": {
    "fileTemplate": "test",
    "rotation": "disabled"
  }
}

Known issues

1. Maximum length of file name in all actual Linux file systems is limited to 255 characters. When record file is created, its name will be trimmed to this limit including extension and part number if rotation is enabled.

...