restreamer
restreamer copied to clipboard
Start a stream programatically using API without using the GUI
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?
Hey @NeveIsa Here's a quick example:
-
Create a process via the Restreamer-Interface
-
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"
}'
- Show the processes:
curl -X 'GET' \
'http://127.0.0.1:8080/api/v3/process' \
-H 'accept: application/json' \
-H 'Authorization: Bearer ACCESS_TOKEN'
-
Copy the process config
"config":{...}and customize it -
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
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?
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"
}'
@NeveIsa Did it work? Any questions?
I will try soon and post here. Sorry, my machine is under repair
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
@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 Thanks, I'm using it by calling it directly instead of testing it in swagger-ui
@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.
For me this description worked well, thanks!
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