Beginner

Quick introduction to using the core API and FFmpeg processes.

Guide content

Finally, two FFmpeg processes are running, using the RTMP server and the in-memory filesystem.
  1. Starting the Core container

  2. Configure and restart the Core

  3. Creating, verifying, updating, and deleting an FFmpeg process

  4. Using placeholders for the in-memory file system and RTMP server

  5. Analyze FFmpeg process errors

1. Start the Core

docker run --detach --name core --publish 8080:8080 datarhei/core:latest

2. Enable the RTMP server on the Core

  1. Configuring the Core via the API

  2. Restarting the Core via the API and loading the changed configuration

  3. Calling the RTMP API

2.1 Changing the Configuration

curl http://127.0.0.1:8080/api/v3/config \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X PUT \
   -d '{
         "version": 3,
         "rtmp": {
            "enable": true
         }
      }'

API Documentation > Configuration

Config

2.2 Apply the change

curl http://127.0.0.1:8080/api/v3/config/reload \
    -X GET

2.3 Checking the RTMP server

curl http://127.0.0.1:8080/api/v3/rtmp \
    -X GET

3. Main-process

Fig. 1: Create the main-process
  1. Initiating the main-process using the Process API

  2. Check the main-process via the Process API

  3. Update the main-process via the Process API

  4. Check the change of the main-process via the Process API

  5. Monitor the RTMP stream via the RTMP API

3.1 Create the FFmpeg process

curl http://127.0.0.1:8080/api/v3/process \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X POST \
   -d '{
         "id": "main",
         "options": [],
         "input": [
            {
               "address": "testsrc=size=1280x720:rate=25",
               "id": "0",
               "options": ["-f", "lavfi", "-re"]
            }
         ],
         "output": [
            {
               "address": "-",
               "id": "0",
               "options": ["-c:v", "libx264", "-f", "null"]
            }
         ],
         "autostart": true,
         "reconnect": true,
         "reconnect_delay_seconds": 10,
         "stale_timeout_seconds": 10
      }'

The configuration creates a process with a virtual video input with no output.

API Documentation > FFmpeg processing

Process

3.2 Check that the FFmpeg process is running

curl http://127.0.0.1:8080/api/v3/process/main/state \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

3.3 Update the FFmpeg process

curl http://127.0.0.1:8080/api/v3/process/main \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X PUT \
   -d '{
         "id": "main",
         "options": [],
         "input": [
            {
               "address": "testsrc=size=1280x720:rate=25",
               "id": "0",
               "options": ["-f", "lavfi", "-re"]
            }
         ],
         "output": [
            {
               "address": "{rtmp,name=main}",
               "id": "0",
               "options": ["-c:v", "libx264", "-f", "flv"]
            }
         ],
         "autostart": true,
         "reconnect": true,
         "reconnect_delay_seconds": 10,
         "stale_timeout_seconds": 10
      }'

This configuration creates an RTMP stream as output and sends it to the internal RTMP server. It uses the {rtmp} placeholder for ease of integration.

3.4 Check that the FFmpeg process is running again

curl http://127.0.0.1:8080/api/v3/process/main/state \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

3.5 Check that the RTMP stream is available

curl http://127.0.0.1:8080/api/v3/rtmp \
    -X GET

API Documentation > RTMP

RTMP

4. Sub-process

Fig. 2: Create the sub-process
  1. Initiate the sub-process through the Process API

  2. Check the sub-process through the Process API

  3. Monitor the HLS stream via the file system API

4.1 Create the FFmpeg process

curl http://127.0.0.1:8080/api/v3/process \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X POST \
   -d '{
         "id": "sub",
         "options": [],
         "input": [
            {
               "address": "{rtmp,name=main}",
               "id": "0",
               "options": []
            }
         ],
         "output": [
            {
               "address": "{memfs}/{processid}.m3u8",
               "id": "0",
               "options": ["-f", "hls"]
            }
         ],
         "autostart": true,
         "reconnect": true,
         "reconnect_delay_seconds": 10,
         "stale_timeout_seconds": 10
      }'

This configuration uses the RTMP stream from the main-process and creates an HLS stream as an output on the internal in-memory file system. It uses the {memfs} placeholder for ease of integration.

4.2 Check that the FFmpeg process is running

curl http://127.0.0.1:8080/api/v3/process/sub/state \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

4.3 Check that the HLS stream is available

curl http://127.0.0.1:8080/api/v3/fs/mem \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

API Documentation > Filesystem > In-Memory

In-memory

5. Analyze process failers

  1. Stop the main-process through the Process API

  2. Check the sub-process via process API

  3. Analyze the sub-process log report via the Process API

  4. Start the main-process through the Process API

  5. Check the sub-process through the Process API

5.1 Create an error on the video input of the sub-process

curl http://127.0.0.1:8080/api/v3/process/main/command \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X PUT \
   -d '{"command": "stop"}'

This command stops the running main-process and interrupts the RTMP stream.

5.2 Check the status of the sub-process

curl http://127.0.0.1:8080/api/v3/process/sub/state \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

5.3 Analyze the sub-process report

curl http://127.0.0.1:8080/api/v3/process/sub/report \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GE

5.4 Fix the process failer

curl http://127.0.0.1:8080/api/v3/process/main/command \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X PUT \
   -d '{"command":"start"}'

This command enables the main-process again.

5.5 Verify the fix

curl http://127.0.0.1:8080/api/v3/process/sub/state \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X GET

6. Cleanup

  1. Stops and deletes the sub-process via the Process API

  2. Stops and deletes the main-process via the Process API

6.1 Delete the sub-process

curl http://127.0.0.1:8080/api/v3/process/sub \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X DELETE

6.2 Delete the main-process

curl http://127.0.0.1:8080/api/v3/process/main \
   -H 'accept: application/json' \
   -H 'Content-Type: application/json' \
   -X DELETE

6.3 Stop the Core

docker kill core
docker rm core

Last updated

Was this helpful?