c2patool - C2PA command line tool
c2patool is a command line tool for working with C2PA manifests. Currently, the tool supports:
- Reading a JSON report of C2PA manifests in supported file formats
- Reading a low-level report of C2PA manifest data in supported file formats
- Previewing manifest data from a manifest definition
- Adding a C2PA manifest to supported file formats
Supported file formats
| MIME type | extensions | read only |
|---|---|---|
image/jpeg |
jpg, jpeg |
|
image/png |
png |
|
image/avif |
avif |
X |
image/heic |
heic |
X |
image/heif |
heif |
X |
video/mp4 |
mp4 |
|
application/mp4 |
mp4 |
|
audio/mp4 |
m4a |
|
application/c2pa |
c2pa |
X |
video/quicktime |
mov |
Installation
If you have Rust installed, you can install or update c2patool using:
cargo install c2patool
Usage
Displaying manifest data
Invoking the tool with a path to an asset will print a report describing the manifests contained in the file in JSON format to stdout.
c2patool image.jpg
Detailed manifest report
The -d or --detailed option will print a detailed report describing the internal C2PA format of manifests contained in the file in JSON format to stdout.
c2patool image.jpg -d
Adding a manifest to a file
To add C2PA data to a file, use the -m or --manifest option and provide a manifest definition JSON file as the argument. The tool generates a new manifest using the values given in the file.
The file path must reference the asset to be signed.
The output file is specified on the command line via the -o or --output flag. If the output is the same as the source, it will be overwritten. Use this with caution. If no output is given you can preview the generated manifest but nothing is written.
The generated manifest store will also be reported in JSON format to stdout.
c2patool image.jpg -m sample/test.json -o signed_image.jpg
A parent file can be specified with the -p or --parent option or in the manifest definition. The parent file represents the state of the asset before any edits were made.
c2patool image.jpg -m sample/test.json -p parent.jpg -o signed_image.jpg
Forced overwrite
The tool will return an error if the output file already exists. The -f or --force flag may be used to override this behavior. Use this with caution.
c2patool image.jpg -m sample/test.json -f -o signed_image.jpg
Manifest preview feature
If the output file is not specified, the tool will generate a preview of the generated manifest. This can be used to make sure you have formatted the manifest definition correctly.
c2patool image.jpg -m sample/test.json
Generating an external manifest
The -s or --sidecar option puts the manifest in an external sidecar file in the same location as the output file. The manifest will have the same output filename but with a ".c2pa" extension. The output file will be copied but untouched.
c2patool image.jpg -s -m sample/test.json -o signed_image.jpg
Generating a remote manifest
The -r or --remote option places an http reference to manifest in the output file. The manifest is returned as an external sidecar file in the same location as the output file. The manifest will have the same output filename but with a ".c2pa" extension. The manifest should then be placed at the location specified by the -r option. When using remote manifests the remote URL should be publicly accessible to be most useful to users. When verifying an asset, remote manifests are automatically fetched.
c2patool image.jpg -r http://my_server/myasset.c2pa -m sample/test.json -o signed_image.jpg
In the example above c2patool will try to fetch the manifest for new_manifest.jpg from http://my_server/myasset.c2pa during validation.
Note: It is possible to combine the -s and -r options. When used together a manifest will be embedded in the output files and the remote reference will also be added.
Example of a manifest definition file
Here's an example of a manifest definition that inserts a CreativeWork author assertion. If you copy this into a JSON file, you can use it as a test manifest definition.
Manifest definition on command line
The manifest definition can also be passed on the command line as a string using the -c or --config option.
In this example we are adding a custom assertion called "org.contentauth.test".
c2patool image.json -c '{"assertions": [{"label": "org.contentauth.test", "data": {"my_key": "whatever I want"}}]}'
Manifest definition format
The manifest definition file is a JSON formatted file with a .json extension.
Any relative file paths will be treated as relative to the location of the definition file unless a base_path field is specified.
The schema for this type is as follows: