restreamer icon indicating copy to clipboard operation
restreamer copied to clipboard

Start a stream programatically using API without using the GUI

Open NeveIsa opened this issue 3 years ago • 10 comments

Currently the documentation is not clear on how to start a process using the API. For example, I want to use /dev/video1 and want to get the stream on the htmlplayer.

How do I accomplish this using POST on the url /api/v3/process? Later I want to get the livestream player's url which I guess is easy to do using GET on the endpoint /api/v3/process and retrieving the process id.

Can we get some example JSON that helps us understand how to use the API?

NeveIsa avatar Jun 15 '22 09:06 NeveIsa

Hey @NeveIsa Here's a quick example:

  1. Create a process via the Restreamer-Interface

  2. Log in and get the access_token:

curl -X 'POST' \
  'http://127.0.0.1:8080/api/login' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "your-username",
  "password": "your-password"
}'
  1. Show the processes:
curl -X 'GET' \
  'http://127.0.0.1:8080/api/v3/process' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer ACCESS_TOKEN'
  1. Copy the process config "config":{...} and customize it

  2. Create your own process:

curl -X 'POST' \
  'http://127.0.0.1:8080/api/v3/process' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -d '{
  "type": "ffmpeg",
  ....
}'

More API details: https://github.com/datarhei/core#process https://demo.datarhei.com/api/swagger/index.html#/default/restream-3-get-all

jstabenow avatar Jun 15 '22 10:06 jstabenow

So in step 5 we just pass the contents of the modified process config section?

This means that the payload {"type": "ffmpeg",...} is the config part of the process details from step 4?

NeveIsa avatar Jun 15 '22 10:06 NeveIsa

You can find the existing configuration in the object "config": https://demo.datarhei.com/api/swagger/index.html#/default/restream-3-get-all

[
  {
    "config": {
      "autostart": true,
      "id": "string",
      "input": [],
      "limits": {
        "cpu_usage": 0,
        "memory_mbytes": 0,
        "waitfor_seconds": 0
      },
      "options": [],
      "output": [],
      "reconnect": true,
      "reconnect_delay_seconds": 0,
      "reference": "string",
      "stale_timeout_seconds": 0,
      "type": "ffmpeg"
    },
    .....
  }
]

And an example of the process configuration looks like this: https://demo.datarhei.com/api/swagger/index.html#/default/restream-3-add

{
  "autostart": true,
  "id": "string",
  "input": [
    {
      "address": "string",
      "cleanup": [],
      "id": "string",
      "options": [
        "string"
      ]
    }
  ],
  "limits": {
    "cpu_usage": 0,
    "memory_mbytes": 0,
    "waitfor_seconds": 0
  },
  "options": [
    "string"
  ],
  "output": [
    {
      "address": "string",
      "cleanup": [],
      "id": "string",
      "options": [
        "string"
      ]
    }
  ],
  "reconnect": true,
  "reconnect_delay_seconds": 0,
  "reference": "string",
  "stale_timeout_seconds": 0,
  "type": "ffmpeg"
}

You use this as payload:

curl -X 'POST' \
  'http://127.0.0.1:8080/api/v3/process' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -d '{
  "autostart": true,
  "id": "string",
  "input": [
    {
      "address": "string",
      "cleanup": [],
      "id": "string",
      "options": [
        "string"
      ]
    }
  ],
  "limits": {
    "cpu_usage": 0,
    "memory_mbytes": 0,
    "waitfor_seconds": 0
  },
  "options": [
    "string"
  ],
  "output": [
    {
      "address": "string",
      "cleanup": [],
      "id": "string",
      "options": [
        "string"
      ]
    }
  ],
  "reconnect": true,
  "reconnect_delay_seconds": 0,
  "reference": "string",
  "stale_timeout_seconds": 0,
  "type": "ffmpeg"
}'

jstabenow avatar Jun 15 '22 11:06 jstabenow

@NeveIsa Did it work? Any questions?

jstabenow avatar Jun 16 '22 09:06 jstabenow

I will try soon and post here. Sorry, my machine is under repair

NeveIsa avatar Jun 19 '22 19:06 NeveIsa

I tried to check the API through swagger but I keep getting a 401 error

I entered the access_token and refresh_token obtained through /api/login correctly, but I get a 401 Missing or invalid JWT token when requesting /api/v3/process

fatherslab-taylor avatar Jun 20 '22 05:06 fatherslab-taylor

@faters-taylor In the token field you have to add Bearer in front of the token, i.e. Bearer [token].

This is currently a limitation of the Swagger 2.0 specs.

ioppermann avatar Jun 20 '22 05:06 ioppermann

@ioppermann Thanks, I'm using it by calling it directly instead of testing it in swagger-ui

fatherslab-taylor avatar Jun 20 '22 06:06 fatherslab-taylor

@faters-taylor Did you generate a client from the swagger file? Then you will most likely need to modify the generated code such that Bearer [access token] is sent to the API instead of only the access token.

ioppermann avatar Jun 20 '22 09:06 ioppermann

For me this description worked well, thanks!

Dielee avatar Jul 01 '22 14:07 Dielee

Hello

We are closing your ticket https://github.com/datarhei/restreamer/issues/366.

This may be due to the following reasons:

  • Problem/inquiry has been solved
  • Ticket remained unanswered by you for a more extended period
  • Problem was explained and handled in another ticket

You can reopen this ticket at any time!

Please only open related tickets once! Always answer/ask in the original ticket with the same issue!

With kind regards, Your datarhei team

svenerbeck avatar Nov 23 '22 21:11 svenerbeck