Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start a stream programatically using API without using the GUI #366

Closed
NeveIsa opened this issue Jun 15, 2022 · 12 comments
Closed

Start a stream programatically using API without using the GUI #366

NeveIsa opened this issue Jun 15, 2022 · 12 comments
Assignees
Labels

Comments

@NeveIsa
Copy link

NeveIsa commented Jun 15, 2022

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 NeveIsa changed the title Start a stream programatically using API without using te GUI Start a stream programatically using API without using the GUI Jun 15, 2022
@jstabenow
Copy link
Member

jstabenow commented Jun 15, 2022

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

@NeveIsa
Copy link
Author

NeveIsa commented Jun 15, 2022

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?

@jstabenow
Copy link
Member

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
Copy link
Member

@NeveIsa Did it work? Any questions?

@NeveIsa
Copy link
Author

NeveIsa commented Jun 19, 2022

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

@fatherslab-taylor
Copy link

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

@ioppermann
Copy link
Member

@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.

@fatherslab-taylor
Copy link

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

@ioppermann
Copy link
Member

@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.

@Dielee
Copy link

Dielee commented Jul 1, 2022

For me this description worked well, thanks!

@svenerbeck
Copy link
Member

Hello

We are closing your ticket #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

@Hoomanzoh79
Copy link

I actually created a process this way and it's added to the list of my processes, however It's just not showing in my restreamer GUI. I want the GUI to be in sync with my own program isn't that how it should be ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants