Metadata vocabularies¶
Metadata properties are identified by an exact vocabulary string and an exact vocabulary-local property string. Do not rewrite either string during import. Use a standard namespace when a standard already defines the concept; use a stable application-owned namespace only for genuinely application-specific data.
Add and read metadata¶
A metadata assertion attaches a typed value to a production, asset, representation, resource, activity, or job under an exact vocabulary and property. Every surface can:
append a value, so a property can hold several ordered values;
remove every value of a property from a target;
read every assertion on a target; and
find every assertion that uses an exact vocabulary and property, as one bounded page at a time and optionally restricted to an exact scalar value.
The Rust storage API can additionally replace every ordered value of a property atomically. The example adds a language-tagged title to an asset and reads it back from both directions:
static const char *const IPTC_VIDEO_METADATA_HUB =
"https://iptc.org/std/videometadatahub/recommendation/"
"iptc-vmhub-1.7-schema.json";
static pp_error_code_t add_title(pp_production_t *production,
const pp_asset_id_t *asset_id,
pp_error_t **error) {
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_metadata_input_t *title = NULL;
pp_transaction_t *transaction = NULL;
pp_metadata_set_t *on_asset = NULL;
pp_metadata_set_t *everywhere = NULL;
pp_error_code_t status =
pp_metadata_input_create_string("Interview", "en-US", &title, error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_add_metadata_value(
transaction, &target, IPTC_VIDEO_METADATA_HUB, "title", title, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
if (status == PP_OK) {
status = pp_production_metadata(production, &target, &on_asset, error);
}
if (status == PP_OK) {
status = pp_production_find_metadata(production, IPTC_VIDEO_METADATA_HUB,
"title", &everywhere, error);
}
for (uint64_t index = 0;
status == PP_OK && index < pp_metadata_set_count(on_asset); ++index) {
pp_object_ref_t owner;
const char *vocabulary = NULL;
const char *property = NULL;
const pp_metadata_value_t *value = NULL;
const char *text = NULL;
const char *language = NULL;
status = pp_metadata_set_get(on_asset, index, &owner, &vocabulary,
&property, &value, error);
if (status == PP_OK &&
pp_metadata_value_kind(value) == PP_METADATA_LANG_STRING) {
status = pp_metadata_value_get_string(value, &text, &language, error);
if (status == PP_OK) {
printf("%s: %s [%s]\n", property, text, language);
}
}
}
pp_metadata_set_release(everywhere);
pp_metadata_set_release(on_asset);
pp_transaction_release(transaction);
pp_metadata_input_release(title);
return status;
}
void add_title(postproject::Production &production,
const postproject::AssetId &asset_id) {
const postproject::ObjectRef target = postproject::ObjectRef::asset(asset_id);
auto transaction = production.edit().value();
transaction.addMetadataValue(
target,
"https://iptc.org/std/videometadatahub/recommendation/"
"iptc-vmhub-1.7-schema.json",
"title", postproject::MetadataValue::languageString("Interview", "en-US")).value();
transaction.commit().value();
// Read one target's assertions with the C function pp_production_metadata().
}
def add_title(production: Production, asset_id: AssetId) -> None:
title = MetadataProperty(
"https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json",
"title",
)
with production.edit() as transaction:
transaction.add_metadata(
AssetRef(asset_id), title, MetadataLanguageString("Interview", "en-US")
)
transaction.commit()
for assertion in production.metadata[AssetRef(asset_id)]:
print(f"{assertion.property.property}: {assertion.value}")
assert len(production.metadata_by_property[title]) == 1
fn add_title(production: &mut SqliteProduction, asset_id: AssetId) -> Result<()> {
let title = MetadataProperty::new(
VocabularyId::new(
"https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json",
)?,
PropertyId::new("title")?,
);
let target = ObjectRef::Asset(asset_id);
{
let mut transaction = production.begin_transaction()?;
transaction.add_metadata_value(
target,
&title,
&MetadataValue::language_string("Interview", "en-US")?,
)?;
transaction.commit()?;
}
let on_asset = production.metadata(target)?;
let everywhere = production.query_by_metadata_property(&title)?;
assert_eq!(on_asset.len(), 1);
assert_eq!(everywhere.len(), 1);
Ok(())
}
IPTC_VMHUB=https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json
postproject metadata add-text production.pproj asset "$ASSET_ID" \
"$IPTC_VMHUB" title "Interview" --language en-US
postproject metadata list production.pproj asset "$ASSET_ID"
postproject metadata find production.pproj "$IPTC_VMHUB" title
All writes belong to an explicit production transaction. A failed operation or rollback leaves no partial assertions.
Typed values¶
Values are typed rather than stringly encoded: plain and language-tagged text, signed and unsigned 64-bit integers, exact decimals and rationals, booleans, timestamps, URIs, opaque bytes, typed object references, and recursively nested ordered lists and named-field structures. Every surface preserves every value kind on read.
The example writes one value of every kind under an application-owned vocabulary, reads them back by dispatching on the value type, and pages through a property query:
static const char *const EDITORIAL = "https://example.com/ns/editorial/1";
enum { VALUE_COUNT = 13 };
static pp_error_code_t add_typed_values(pp_production_t *production,
const pp_asset_id_t *asset_id,
const pp_representation_id_t *representation_id,
pp_error_t **error) {
static const uint8_t thumbnail[] = {0x89, 0x50, 0x4e, 0x47};
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_object_ref_t source;
reference_status = pp_object_ref_from_representation(*representation_id, &source, error);
if (reference_status != PP_OK) return reference_status;
const char *const properties[VALUE_COUNT] = {
"slate", "title", "offset", "frame-count", "gain",
"approved", "reviewed-at", "homepage", "thumbnail", "frame-rate",
"keywords", "camera", "source"};
pp_metadata_input_t *values[VALUE_COUNT] = {NULL};
pp_metadata_input_t *keyword[2] = {NULL, NULL};
pp_metadata_input_t *field[2] = {NULL, NULL};
pp_transaction_t *transaction = NULL;
pp_error_code_t status =
pp_metadata_input_create_string("A001 T3", NULL, &values[0], error);
if (status == PP_OK) {
/* A language tag makes this a language string. */
status = pp_metadata_input_create_string("Interview", "en-US", &values[1],
error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_i64(-12, &values[2], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_u64(2400, &values[3], error);
}
if (status == PP_OK) {
/* Decimals are exact: coefficient 325 with scale 2 is 3.25. */
status = pp_metadata_input_create_decimal("325", 2, &values[4], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_bool(1, &values[5], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_timestamp(INT64_C(1767225600000000),
&values[6], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_uri("https://example.com/interviews/3",
&values[7], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_bytes(thumbnail, sizeof thumbnail,
&values[8], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_rational(24000, 1001, &values[9], error);
}
if (status == PP_OK) {
status =
pp_metadata_input_create_string("interview", NULL, &keyword[0], error);
}
if (status == PP_OK) {
status =
pp_metadata_input_create_string("exterior", NULL, &keyword[1], error);
}
if (status == PP_OK) {
/* Collections copy their children, which stay owned by the caller. */
const pp_metadata_input_t *items[] = {keyword[0], keyword[1]};
status = pp_metadata_input_create_list(items, 2, &values[10], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_string("ARRI", NULL, &field[0], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_u64(800, &field[1], error);
}
if (status == PP_OK) {
const char *names[] = {"make", "iso"};
const pp_metadata_input_t *fields[] = {field[0], field[1]};
status =
pp_metadata_input_create_struct(names, fields, 2, &values[11], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_reference(&source, &values[12], error);
}
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
for (int i = 0; status == PP_OK && i < VALUE_COUNT; ++i) {
status = pp_transaction_add_metadata_value(transaction, &target, EDITORIAL,
properties[i], values[i], error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
for (int i = 0; i < 2; ++i) {
pp_metadata_input_release(field[i]);
pp_metadata_input_release(keyword[i]);
}
for (int i = 0; i < VALUE_COUNT; ++i) {
pp_metadata_input_release(values[i]);
}
return status;
}
static pp_error_code_t print_value(const pp_metadata_value_t *value,
uint32_t *seen_kinds, pp_error_t **error) {
const pp_metadata_value_kind_t kind = pp_metadata_value_kind(value);
pp_error_code_t status = PP_OK;
*seen_kinds |= kind < 32 ? UINT32_C(1) << kind : 0;
switch (kind) {
case PP_METADATA_STRING:
case PP_METADATA_LANG_STRING: {
const char *text, *language;
status = pp_metadata_value_get_string(value, &text, &language, error);
if (status == PP_OK) {
printf("\"%s\"%s%s", text, language != NULL ? "@" : "",
language != NULL ? language : "");
}
break;
}
case PP_METADATA_I64: {
int64_t number = 0;
status = pp_metadata_value_get_i64(value, &number, error);
if (status == PP_OK) {
printf("%lld", (long long)number);
}
break;
}
case PP_METADATA_U64: {
uint64_t number = 0;
status = pp_metadata_value_get_u64(value, &number, error);
if (status == PP_OK) {
printf("%llu", (unsigned long long)number);
}
break;
}
case PP_METADATA_DECIMAL: {
const char *coefficient;
uint32_t scale = 0;
status = pp_metadata_value_get_decimal(value, &coefficient, &scale, error);
if (status == PP_OK) {
printf("%se-%u", coefficient, scale);
}
break;
}
case PP_METADATA_BOOL: {
uint8_t flag = 0;
status = pp_metadata_value_get_bool(value, &flag, error);
if (status == PP_OK) {
printf("%s", flag ? "true" : "false");
}
break;
}
case PP_METADATA_TIMESTAMP: {
int64_t micros = 0;
status = pp_metadata_value_get_timestamp(value, µs, error);
if (status == PP_OK) {
printf("%lld us since 1970", (long long)micros);
}
break;
}
case PP_METADATA_URI: {
const char *uri;
status = pp_metadata_value_get_uri(value, &uri, error);
if (status == PP_OK) {
printf("<%s>", uri);
}
break;
}
case PP_METADATA_BYTES: {
const uint8_t *bytes;
uint64_t length = 0;
status = pp_metadata_value_get_bytes(value, &bytes, &length, error);
if (status == PP_OK) {
printf("%llu bytes", (unsigned long long)length);
}
break;
}
case PP_METADATA_RATIONAL: {
int64_t numerator = 0;
uint64_t denominator = 0;
status =
pp_metadata_value_get_rational(value, &numerator, &denominator, error);
if (status == PP_OK) {
printf("%lld/%llu", (long long)numerator,
(unsigned long long)denominator);
}
break;
}
case PP_METADATA_LIST: {
printf("[");
for (uint64_t i = 0;
status == PP_OK && i < pp_metadata_value_list_count(value); ++i) {
const pp_metadata_value_t *item;
status = pp_metadata_value_list_get(value, i, &item, error);
if (status == PP_OK) {
printf("%s", i > 0 ? ", " : "");
status = print_value(item, seen_kinds, error);
}
}
printf("]");
break;
}
case PP_METADATA_STRUCT: {
printf("{");
for (uint64_t i = 0;
status == PP_OK && i < pp_metadata_value_struct_count(value); ++i) {
const char *name;
const pp_metadata_value_t *field;
status = pp_metadata_value_struct_get(value, i, &name, &field, error);
if (status == PP_OK) {
printf("%s%s: ", i > 0 ? ", " : "", name);
status = print_value(field, seen_kinds, error);
}
}
printf("}");
break;
}
case PP_METADATA_REFERENCE: {
pp_object_ref_t reference;
status = pp_metadata_value_get_reference(value, &reference, error);
if (status == PP_OK) {
printf("object of kind %u", reference.kind);
}
break;
}
default:
/* Newer libraries may add kinds; skip what this host does not know. */
printf("(unknown kind %u)", kind);
break;
}
return status;
}
static pp_error_code_t print_typed_values(const pp_production_t *production,
const pp_asset_id_t *asset_id,
uint32_t *out_seen_kinds,
pp_error_t **error) {
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_metadata_set_t *metadata = NULL;
pp_error_code_t status =
pp_production_metadata(production, &target, &metadata, error);
for (uint64_t i = 0; status == PP_OK && i < pp_metadata_set_count(metadata);
++i) {
pp_object_ref_t owner;
const char *vocabulary, *property;
const pp_metadata_value_t *value;
status = pp_metadata_set_get(metadata, i, &owner, &vocabulary, &property,
&value, error);
if (status == PP_OK && strcmp(vocabulary, EDITORIAL) == 0) {
printf("%s: ", property);
status = print_value(value, out_seen_kinds, error);
printf("\n");
}
}
pp_metadata_set_release(metadata);
return status;
}
static pp_error_code_t count_values_by_page(const pp_production_t *production,
const char *property,
uint64_t *out_count,
pp_error_t **error) {
char cursor_storage[2049] = {0};
const char *cursor = NULL;
pp_error_code_t status = PP_OK;
*out_count = 0;
while (status == PP_OK) {
pp_metadata_set_t *page = NULL;
/* A NULL exact value matches every value of the property. */
status = pp_production_query_metadata(production, EDITORIAL, property, NULL,
UINT32_C(1), cursor, &page, error);
*out_count += status == PP_OK ? pp_metadata_set_count(page) : 0;
const char *next =
status == PP_OK ? pp_metadata_set_next_cursor(page) : NULL;
const int copied =
next != NULL
? snprintf(cursor_storage, sizeof cursor_storage, "%s", next)
: 0;
pp_metadata_set_release(page);
if (status != PP_OK || copied == 0) {
break;
}
if (copied < 0 || (size_t)copied >= sizeof cursor_storage) {
status = PP_ERROR_INTERNAL;
}
cursor = cursor_storage;
}
return status;
}
constexpr const char *editorial = "https://example.com/ns/editorial/1";
void add_editorial_metadata(postproject::Production &production,
const postproject::AssetId &asset_id,
const postproject::RepresentationId &representation_id) {
using postproject::MetadataValue;
const postproject::ObjectRef asset = postproject::ObjectRef::asset(asset_id);
std::vector<MetadataValue> keywords;
keywords.push_back(MetadataValue::plainString("interview"));
keywords.push_back(MetadataValue::plainString("exterior"));
std::vector<postproject::MetadataField> slate;
slate.push_back({"scene", MetadataValue::plainString("12A")});
slate.push_back({"take", MetadataValue::unsignedInteger(3)});
auto transaction = production.edit().value();
const auto add = [&](const char *property, const MetadataValue &value) {
transaction.addMetadataValue(asset, editorial, property, value).value();
};
add("title", MetadataValue::plainString("Harbour interview"));
add("caption", MetadataValue::languageString("Am Hafen", "de-DE"));
add("timecode-offset", MetadataValue::signedInteger(-48));
add("frame-count", MetadataValue::unsignedInteger(86400));
add("aspect-ratio", MetadataValue::decimal("239", 2)); // 2.39
add("circled", MetadataValue::boolean(true));
add("shot-at", MetadataValue::timestamp(1'700'000'000'000'000));
add("licence", MetadataValue::uri("https://example.com/licences/7"));
add("checksum", MetadataValue::bytes({0xde, 0xad, 0xbe, 0xef}));
add("frame-rate", MetadataValue::rational(24000, 1001));
add("keywords", MetadataValue::list(keywords));
add("slate", MetadataValue::structure(slate));
add("preferred-representation",
MetadataValue::reference(
postproject::ObjectRef::representation(representation_id)));
transaction.commit().value();
}
std::map<std::string, std::size_t>
count_editorial_values(const postproject::Production &production,
const std::vector<std::string> &properties) {
std::map<std::string, std::size_t> counts;
for (const auto &property : properties) {
// Follow next_cursor until the query is exhausted.
std::optional<std::string> cursor;
do {
const auto page =
production.queryMetadata(editorial, property, 1, cursor).value();
counts[property] += page.items.size();
cursor = page.next_cursor;
} while (cursor.has_value());
}
// Values come back as MetadataValue objects: read them, pass one to an
// exact-value query, or copy it onto another target.
const auto frame_rate = production.queryMetadata(
editorial, "frame-rate",
postproject::MetadataValue::rational(24000, 1001), 10).value();
std::cout << "assets shot at 23.976 fps: " << frame_rate.items.size() << '\n';
const auto keywords =
production.queryMetadata(editorial, "keywords", 1).value();
if (const auto *list =
keywords.items.front().value.getIf<postproject::MetadataList>()) {
for (const auto &item : list->items) {
std::cout << "keyword: "
<< item.getIf<postproject::MetadataString>()->value << '\n';
}
}
const auto slate = production.queryMetadata(editorial, "slate", 1).value();
std::visit(
[](const auto &value) {
using Value = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<Value, postproject::MetadataStructure>) {
std::cout << "slate has " << value.fields.size() << " fields\n";
}
},
slate.items.front().value.variant());
return counts;
}
def add_editorial_metadata(
production: Production, asset_id: AssetId, original_id: RepresentationId
) -> None:
values: dict[str, MetadataInput] = {
"title": "Interview",
"headline": MetadataLanguageString("Gespräch am Morgen", "de"),
"reel-offset": -48,
"take-count": MetadataU64(3),
"gain-db": MetadataDecimal(coefficient=-125, scale=1), # -12.5
"approved": True,
"shot-at": MetadataTimestamp(1_700_000_000_000_000),
"script": MetadataUri("https://example.com/scripts/ep1"),
"thumbnail": b"\x89PNG",
"frame-rate": Fraction(24_000, 1_001),
"keywords": (("interview", "exterior")),
"lens": MetadataStruct(
(
MetadataStructField("model", "Example 35mm"),
MetadataStructField("focal-length-mm", MetadataU64(35)),
)
),
"selected-take": MetadataReference(RepresentationRef(original_id)),
}
with production.edit() as transaction:
for name, value in values.items():
transaction.add_metadata(AssetRef(asset_id), (EDITORIAL, name), value)
transaction.commit()
def describe(value: MetadataInput) -> str:
match value:
case str(text):
return text
case bool() | int() | bytes() | Fraction():
return repr(value)
case MetadataUri(text):
return text
case MetadataLanguageString(text, language):
return f"{text} @{language}"
case MetadataU64(number):
return str(number)
case MetadataDecimal(coefficient, scale):
return f"{coefficient}e-{scale}"
case MetadataTimestamp(unix_micros):
return f"{unix_micros} µs since the Unix epoch"
case tuple(items) | list(items):
return "[" + ", ".join(describe(item) for item in items) + "]"
case MetadataStruct(fields):
return (
"{" + ", ".join(f"{f.name}: {describe(f.value)}" for f in fields) + "}"
)
case MetadataReference(target):
return f"-> {target}"
raise TypeError("unsupported metadata value")
def print_metadata(production: Production, target: ObjectReference) -> None:
for assertion in production.metadata[target]:
print(f"{assertion.property.property} = {describe(assertion.value)}")
def find_approved(production: Production) -> list[ObjectReference]:
approved = MetadataProperty(EDITORIAL, "approved")
targets: list[ObjectReference] = []
cursor = None
while True:
# Pass the same property, value, and limit with each cursor.
page = production.query_metadata(approved, limit=1, cursor=cursor, value=(True))
targets.extend(assertion.target for assertion in page.items)
cursor = page.next_cursor
if cursor is None:
return targets
fn editorial(property: &str) -> Result<MetadataProperty> {
Ok(MetadataProperty::new(
VocabularyId::new("https://example.com/ns/editorial/1")?,
PropertyId::new(property)?,
))
}
fn add_typed_metadata(
production: &mut SqliteProduction,
asset_id: AssetId,
original_id: RepresentationId,
) -> Result<()> {
let values = [
("slate", MetadataValue::string("12A/3")?),
(
"title",
MetadataValue::language_string("Interview", "en-US")?,
),
("offset", MetadataValue::i64(-48)),
("take", MetadataValue::u64(3)),
(
"exposure",
MetadataValue::decimal(DecimalValue::new(125, 2)?),
),
("circled", MetadataValue::boolean(true)),
(
"shot-at",
MetadataValue::timestamp(Timestamp::from_unix_micros(1_700_000_000_000_000)),
),
(
"script",
MetadataValue::uri("https://example.com/scripts/12")?,
),
(
"thumbnail-hash",
MetadataValue::bytes(vec![0xde, 0xad, 0xbe, 0xef])?,
),
(
"rate",
MetadataValue::rational(RationalValue::new(24000, 1001)?),
),
(
"keywords",
MetadataValue::list(vec![
MetadataValue::string("interview")?,
MetadataValue::string("exterior")?,
])?,
),
(
"lens",
MetadataValue::structure(vec![
MetadataField::new(PropertyId::new("model")?, MetadataValue::string("35mm")?),
MetadataField::new(PropertyId::new("t-stop")?, MetadataValue::u64(2)),
])?,
),
(
"selected-take",
MetadataValue::reference(ObjectRef::Representation(original_id)),
),
];
let target = ObjectRef::Asset(asset_id);
let mut transaction = production.begin_transaction()?;
for (property, value) in &values {
transaction.add_metadata_value(target, &editorial(property)?, value)?;
}
transaction.commit()?;
drop(transaction);
for assertion in production.metadata(target)? {
let property = assertion.property().property().as_str();
println!("{property}: {}", describe(assertion.value()));
}
Ok(())
}
fn describe(value: &MetadataValue) -> String {
match value.kind() {
MetadataValueKind::String => format!("{:?}", value.as_string()),
MetadataValueKind::LangString => format!("{:?}", value.as_language_string()),
MetadataValueKind::I64 => format!("{:?}", value.as_i64()),
MetadataValueKind::U64 => format!("{:?}", value.as_u64()),
MetadataValueKind::Decimal => format!("{:?}", value.as_decimal()),
MetadataValueKind::Bool => format!("{:?}", value.as_bool()),
MetadataValueKind::Timestamp => format!("{:?}", value.as_timestamp()),
MetadataValueKind::Uri => format!("{:?}", value.as_uri()),
MetadataValueKind::Bytes => format!("{:?}", value.as_bytes()),
MetadataValueKind::Rational => format!("{:?}", value.as_rational()),
MetadataValueKind::List => {
let items = value.as_list().unwrap_or_default();
let items: Vec<String> = items.iter().map(describe).collect();
format!("[{}]", items.join(", "))
}
MetadataValueKind::Struct => {
let fields = value.as_structure().unwrap_or_default();
let fields: Vec<String> = fields
.iter()
.map(|field| format!("{}: {}", field.name().as_str(), describe(field.value())))
.collect();
format!("{{{}}}", fields.join(", "))
}
MetadataValueKind::Reference => format!("{:?}", value.as_reference()),
// New value types may be added; preserve what cannot be interpreted.
_ => "unsupported value type".to_owned(),
}
}
fn objects_with_slate(production: &SqliteProduction) -> Result<Vec<ObjectRef>> {
let query = MetadataQuery::new(editorial("slate")?, None)?;
let mut objects = Vec::new();
let mut cursor = None;
loop {
let page = production.metadata_query(&query, &QueryPageRequest::new(1, cursor)?)?;
objects.extend(page.items().iter().map(MetadataMatch::target));
cursor = page.next_cursor().cloned();
if cursor.is_none() {
return Ok(objects);
}
}
}
EDITORIAL=https://example.com/ns/editorial/1
mkdir -p values
# One JSON value file per property; "type" selects the metadata value type.
cat > values/slug.json <<'EOF'
{"type": "string", "value": "INT-001"}
EOF
cat > values/title.json <<'EOF'
{"type": "lang_string", "value": "Interview", "language": "en-US"}
EOF
cat > values/offset.json <<'EOF'
{"type": "i64", "value": -12}
EOF
cat > values/take.json <<'EOF'
{"type": "u64", "value": 3}
EOF
cat > values/gain.json <<'EOF'
{"type": "decimal", "coefficient": "-35", "scale": 1}
EOF
cat > values/approved.json <<'EOF'
{"type": "bool", "value": true}
EOF
cat > values/shot-at.json <<'EOF'
{"type": "timestamp", "unix_micros": 1767225600000000}
EOF
cat > values/homepage.json <<'EOF'
{"type": "uri", "value": "https://example.com/interview"}
EOF
cat > values/checksum.json <<'EOF'
{"type": "bytes", "hex": "00ff10"}
EOF
cat > values/rate.json <<'EOF'
{"type": "rational", "numerator": 24000, "denominator": 1001}
EOF
cat > values/keywords.json <<'EOF'
{"type": "list", "values": [
{"type": "string", "value": "interview"},
{"type": "string", "value": "exterior"}
]}
EOF
cat > values/camera.json <<'EOF'
{"type": "struct", "fields": [
{"name": "model", "value": {"type": "string", "value": "A-Cam"}},
{"name": "iso", "value": {"type": "u64", "value": 800}}
]}
EOF
cat > values/source.json <<EOF
{"type": "reference",
"target": {"target_kind": "representation", "target_id": "$ORIGINAL_ID"}}
EOF
for VALUE_FILE in values/*.json; do
postproject metadata add knowledge.pproj asset "$ASSET_ID" "$EDITORIAL" \
"$(basename "$VALUE_FILE" .json)" "$VALUE_FILE"
done
postproject --json metadata list knowledge.pproj asset "$ASSET_ID" |
jq -r '.[] | .property + ": " + (.value | if .type == "lang_string" then
"\(.value) (\(.language))"
elif .type == "decimal" then "\(.coefficient)e-\(.scale)"
elif .type == "timestamp" then "\(.unix_micros) us"
elif .type == "bytes" then "0x\(.hex)"
elif .type == "rational" then "\(.numerator)/\(.denominator)"
elif .type == "list" then [.values[].value] | join(", ")
elif .type == "struct" then [.fields[] | "\(.name)=\(.value.value)"] | join(", ")
elif .type == "reference" then "\(.target.kind) \(.target.id)"
else .value | tostring end)'
# Metadata queries are paged; follow next_cursor until it is null.
CURSOR=
while :; do
ARGS=(--json metadata find knowledge.pproj "$EDITORIAL" take --limit 1)
[[ -n "$CURSOR" ]] && ARGS+=(--cursor "$CURSOR")
PAGE=$(postproject "${ARGS[@]}")
jq -r '.items[] | "\(.target_kind) \(.target_id) take \(.value.value)"' <<<"$PAGE"
CURSOR=$(jq -r '.next_cursor // empty' <<<"$PAGE")
[[ -z "$CURSOR" ]] && break
done
In C, recursive input handles copy their children, so callers can release
intermediate list and structure values immediately after construction. In C++,
MetadataValue is one copyable type for writing and reading, like Python’s
value classes: read one with getIf<T>() or by visiting variant(), and
compare values with == (ADR 0036). The CLI
reads a typed value from a JSON file in the same tagged shape that --json
output emits. Decimal coefficients are strings so JSON consumers do not lose
precision, binary values use hexadecimal text, and lists and structure fields
are recursive and ordered.
Python common inputs use (vocabulary, property) keys and native str,
bool, signed int, bytes and Fraction values. Mixed children in
Lists and tuples represent one list value; MetadataStruct preserves ordered,
repeated fields. Reads return str, bool, signed int, bytes, Fraction
and immutable tuples. Keep explicit tags for unsigned integers, URI/text,
language strings, timestamps, decimals and typed references.
Unsigned integers, decimals, timestamps, URIs, language-tagged strings and
references keep explicit tags. Floats, None and plain dictionaries are
rejected. Reads retain typed values and exact property keys.
Remove a property¶
Removal deletes every value of one property from one target in a read-bound edit. Unbased transactions may append values; replacement and removal require a decision base. A destructive commit conflicts after any intervening change to that property, including an append. Reread before retrying.
static pp_error_code_t remove_keywords(pp_production_t *production,
const pp_asset_id_t *asset_id,
uint64_t *out_remaining,
pp_error_t **error) {
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_transaction_t *transaction = NULL;
pp_read_session_t *view = NULL;
pp_metadata_set_t *remaining = NULL;
pp_error_code_t status =
pp_production_read_session(production, &view, error);
if (status == PP_OK) {
status = pp_read_session_begin_edit(view, NULL, &transaction, error);
}
pp_read_session_release(view);
if (status == PP_OK) {
/* Removes every value of the property on this target. */
status = pp_transaction_remove_metadata_property(
transaction, &target, EDITORIAL, "keywords", error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
if (status == PP_OK) {
status = pp_production_find_metadata(production, EDITORIAL, "keywords",
&remaining, error);
}
if (status == PP_OK) {
*out_remaining = pp_metadata_set_count(remaining);
printf("keywords left: %llu\n", (unsigned long long)*out_remaining);
}
pp_metadata_set_release(remaining);
pp_transaction_release(transaction);
return status;
}
void clear_keywords(postproject::Production &production,
postproject::AssetId asset_id) {
const auto target = postproject::ObjectRef::asset(asset_id);
auto view = production.readSession().value();
const auto keywords = view.queryMetadata(editorial, "keywords", 1).value();
require(!keywords.items.empty() && keywords.items.front().target == target,
"inspect this asset's keywords");
auto edit = view.edit().value();
edit.removeMetadataProperty(target, editorial, "keywords").value();
const auto receipt = edit.commit().value();
require(receipt.revision.has_value(), "removal created its own revision");
require(production.queryMetadata(editorial, "keywords", 1).value().items.empty(),
"all keywords removed");
}
def clear_keywords(production: Production, asset_id: AssetId) -> None:
keywords = MetadataProperty(EDITORIAL, "keywords")
# Removes every value of the property on this target in one change.
with production.read_session() as view, view.edit() as transaction:
transaction.remove_metadata_property(AssetRef(asset_id), keywords)
transaction.commit()
assert production.metadata_by_property[keywords] == ()
fn remove_keywords(production: &mut SqliteProduction, asset_id: AssetId) -> Result<()> {
let keywords = MetadataProperty::new(
VocabularyId::new("https://example.com/ns/editorial/1")?,
PropertyId::new("keywords")?,
);
let target = ObjectRef::Asset(asset_id);
let base = {
let view = production.read_session()?;
assert_ne!(
view.read().metadata_values(target, &keywords)?,
[] as [postproject_core::MetadataValue; 0]
);
view.decision_base()
};
{
let mut transaction = production.begin_edit(base)?;
// Removes every value of the property at once.
transaction.remove_metadata_property(target, &keywords)?;
transaction.commit()?;
}
assert_eq!(production.metadata_values(target, &keywords)?, []);
Ok(())
}
# Removes every value of the property from the object, here both keyword lists.
BASE=$(postproject --json inspect knowledge.pproj | jq -r .decision_base)
postproject --decision-base "$BASE" metadata remove knowledge.pproj \
asset "$ASSET_ID" "$EDITORIAL" keywords
postproject --json metadata find knowledge.pproj "$EDITORIAL" keywords |
jq '.items | length'
Query by property and value¶
find and the paged property query return every assertion that uses an exact
vocabulary and property. An optional exact scalar value narrows the page; see
bounded queries for
the paging contract.
Technical inspection¶
The optional ffprobe adapter stores its results as ordinary typed assertions
under https://postproject.org/ns/technical-media/1 with property
inspection; see fingerprints, verification, and
inventory. No
FFmpeg type or dependency enters postproject-core, and raw embedded tag keys
and values are kept as ordered key/value structures so unfamiliar tags do not
need to become schema fields. Every surface reads the resulting assertion
through its normal metadata reads.
media resolve --verify reuses a single stored inspection as partial identity
evidence when scoring relocated file candidates. The candidate remains
ambiguous if another credible match exists. Subprocess output is limited to
8 MiB per stream, execution defaults to a 30-second deadline, JSON and numeric
values are parsed without floating point, and stderr diagnostics are truncated.
Missing ffprobe, non-zero exit, timeout, oversized output, and malformed JSON
are distinguishable outcomes.
Optional Rust registry¶
The core registry supplies a small set of advisory definitions for IPTC Video
Metadata Hub JSON, Dublin Core, XMP Basic, EBUCore, and PostProject-owned
metadata. A property hint can describe accepted value kinds, cardinality,
labels, descriptions, and known mapping aliases. validate_values applies
those rules only when an application explicitly calls it.
Registry lookup uses exact identifiers. An absent vocabulary or property is not an error, and persistence never invokes the registry automatically. This keeps unknown and application-specific metadata fully round-trippable.
Availability¶
The typed domain model, optional vocabulary registry, and SQLite persistence
back every surface. C, Python, Rust, and the CLI read and write every value
kind. C++ production.metadata(target) and view.metadata(target) return
copied assertions, preserving repeated properties and exact value kinds.
Use queryMetadata for bounded cross-target property searches and
removeMetadataProperty to remove a target’s property. Activity metadata
is writable after the activity is created in the same or an earlier
transaction.
See standards boundaries and the mapping matrix for the intended relationship to IPTC Video Metadata Hub, EBUCore, XMP, and other standards.