AMCP Commands Review

Here we review the AMCP commands used by CasparCG

From the CasparCG AMCP command page, "The Advanced Media Control Protocol (AMCP) is the main communication protocol used to control and query CasparCG Server." I would recommend saving that link, it will make getting back to the AMCP commands much easier in the future.

We are primarily interested in the Template Commands. Let's break each of them down and explain how each of them can be used with our JavaScript file. If you are already familiar with the AMCP commands, you can skip to the next section.

CG ADD

CG ADD will load the HTML file from an URL or a file in the templates folder defined in your casparcg.config file. Each HTML file loaded will be displayed on a device and occupy one layer. The channel and layer are defined as the first two properties in the CG ADD command.

CG [channel: int]-[layer: int] ADD
CG 1-1 ADD
CG 1-999 ADD // 999 is the max layer

The next parameter is the flash layer. This has no effect on our HTML template so we will always set it to 0.

CG [channel: int]-[layer: int] ADD [Flash Layer: int]
CG 1-1 ADD 0

The next parameter is an URL or name of a HTML file in the templates folder. If you are using the HTTP-Server package setup in the Development Setup section of this guide, then your command will look like the following.

CG [channel: int]-[layer: int] ADD [Flash Layer: int] [URL: string]
CG 1-1 ADD 0 http://localhost:8080/lower-third.1.html

To load a file from the CasparCG templates folder, remove the extension from the filename like so.

CG 1-1 ADD 0 lower-third.1
CG 1-1 ADD 0 folder/lower-third.1 // If you nested the file in a folder

CasparCG version 2.1.1 NRK Build will only load files from the templates folder.

Next, we can add a Play On Load parameter that is either 0 or 1. For now, we will set it to 0.

CG [channel: int]-[layer: int] ADD [Flash Layer: int] [URL: string] [Play On Load: bool] [Data: string]
CG 1-1 ADD 0 http://localhost:8080/lower-third.1.html 0

Finally, we can add some optional data. We will define that in the Handling AMCP Commands within the JavaScript section of this guide.

CG UPDATE

CG UPDATE calls the JavaScript file's update global function. It is also the only function that is passed a string of data. The CasparCG Server website says it is either string of JSON or XML data but, it can be any string. We will primarily be using JSON. We do need to escape the double quotes because CasparCG Server will not recognize single quotes as a string.

CG [channel: int]-[layer: int] UPDATE "{}"
CG 1-1 UPDATE "{\"some\":\"data\"}"

CG PLAY

CG PLAY will call the JavaScript file's play global function. It is designed to animate in the graphic.

CG [channel: int]-[layer: int] PLAY
CG 1-1 PLAY

CG NEXT

CG NEXT will call the JavaScript file's next global function. It is designed to advance the template to the next step. We will also be defining a non-standard function called previous.

CG [channel: int]-[layer: int] NEXT
CG 1-1 NEXT

CG STOP

CG STOP will call the JavaScript file's stop global function. It is designed to animate out the graphic.

CG [channel: int]-[layer: int] STOP
CG 1-1 STOP

CG REMOVE

CG REMOVE will call the JavaScript file's remove global function. It is designed to prepare a graphic to be cleared. This can include things like saving local data, or making API calls.

CG [channel: int]-[layer: int] REMOVE
CG 1-1 REMOVE

CG INVOKE

CG INVOKE calls a custom function defined on the JavaScript file's global scope. In this guide, we will define the reset and previous functions to be invoked by the CasparCG server.

CG [channel: int]-[layer: int] INVOKE [Flash Layer: int] [Function Name: string]
CG 1-1 INVOKE 0 reset
CG 1-1 INVOKE 0 previous

CG CLEAR

CG CLEAR will not interact with our JavaScript file at all. It will immediately clear the layer or channel provided. This will also remove our template if it is on that channel or layer.

CG [channel: int] CLEAR // Clears an entire channel
CG [channel: int]-[layer: int] CLEAR // Clears a specific channel and layer

Resources

Last updated