Assets, representations, resources, and locators¶
An asset is a logical production object. It is not a pathname.
A representation is one concrete realization of an asset, such as a camera original, editorial proxy, mezzanine transcode, or render sequence. A representation is not necessarily one file. It has an explicit content structure describing how storage resources form usable media.
A resource identifies a storage-level component. A single-file movie uses one resource, while spanned recordings and packages use several. A regular image sequence uses one compact patterned resource instead of creating one database object per frame. File facts and storage-level fingerprints belong to resources.
A representation fingerprint combines the content structure with its resource-fingerprint evidence. It excludes PostProject object IDs and locators, preserves order for spanned media, treats package member order as irrelevant, and hashes an image sequence’s compact descriptor without visiting every frame during representation aggregation. Neither fingerprint includes an image sequence’s file names, so a renamed copy has the same identity. The sequence resource contributes deterministically sampled member-content evidence. Its confidence cannot exceed the resource evidence it aggregates: a sampled resource fingerprint does not become a full-content identity claim.
A locator describes where or how a resource can currently be accessed. One resource may have several locators, such as paths through different mounts. Moving content changes its locator rather than its resource, representation, or asset identity. For an image sequence the locator names a directory together with the naming of the files there: their prefix, suffix, and frame-number padding. Renaming a sequence therefore changes only its locator, and a copy of the sequence under other names is another locator of the same resource.
flowchart TD
asset["Asset"] --> representation["Representation"]
representation -- "one of" --> single["single resource<br/>a movie file"]
representation -- "one of" --> sequence["image sequence<br/>one patterned resource"]
representation -- "one of" --> ordered["ordered resources<br/>parts of a spanned recording"]
representation -- "one of" --> package["package<br/>required and optional members"]
sequence --> original["locator<br/>directory + naming sh010.####.exr"]
sequence --> renamed["locator<br/>directory + naming sh010_grade.####.exr"]
Content structures distinguish:
one resource;
a compact image sequence with a frame domain, exact rate, and known gaps, whose file naming belongs to each locator;
ordered resources, such as a spanned recording; and
a package whose required and optional members have extensible roles.
Availability is evaluated for the complete representation. All required content being resolvable is online; some required content being available is partial; none being available is offline; multiple plausible resolutions are ambiguous; and a required resource whose resolution failed makes the representation error. Missing optional package members can be reported without making otherwise usable media partial.
This separation is why PostProject can retain an asset’s identity and metadata when storage paths change, and why one missing image-sequence frame is not mistaken for a fully online representation.
Across public surfaces¶
Resolution reports candidates without mutating the production or silently choosing among ambiguous locations:
static pp_error_code_t resolve_asset(const pp_production_t *production,
const pp_asset_id_t *asset_id,
const char *rushes_directory,
pp_resolution_set_t **out_resolutions,
pp_error_t **error) {
pp_resolution_options_t *options = NULL;
pp_resolution_set_t *resolutions = NULL;
/* The mapping locates the logical root on this machine for this call only. */
const pp_root_mapping_t mapping = {"rushes", rushes_directory};
pp_resolution_config_t config = PP_RESOLUTION_CONFIG_INIT;
config.root_mappings = &mapping;
config.root_mapping_count = 1;
pp_error_code_t status = pp_resolution_options_create(&config, &options, error);
if (status == PP_OK) {
status = pp_production_resolve_assets(production, asset_id, 1, options,
&resolutions, error);
}
pp_resolution_options_release(options);
const uint64_t count =
status == PP_OK ? pp_resolution_set_representation_count(resolutions) : 0;
for (uint64_t r = 0; status == PP_OK && r < count; ++r) {
pp_asset_id_t resolved_asset_id;
pp_representation_id_t representation_id;
pp_representation_availability_t availability;
uint64_t resource_count = 0;
uint64_t issue_count = 0;
status = pp_resolution_set_get_representation(
resolutions, r, &resolved_asset_id, &representation_id, &availability,
&resource_count, &issue_count, error);
if (status == PP_OK) {
printf("availability: %u\n", availability);
}
for (uint64_t s = 0; status == PP_OK && s < resource_count; ++s) {
pp_resource_id_t resource_id = {0};
pp_resource_resolution_state_t state;
uint64_t candidate_count = 0;
uint64_t evidence_count = 0;
status = pp_resolution_set_get_resource_state(resolutions, r, s, &state, error);
if (status != PP_OK) break;
status = pp_resolution_set_get_resource(resolutions, r, s, state, &resource_id,
&state, &candidate_count,
&evidence_count, error);
for (uint64_t c = 0; status == PP_OK && c < candidate_count; ++c) {
const char *uri = NULL;
uint16_t confidence = 0;
const char *root = NULL;
uint8_t has_naming = 0;
pp_sequence_naming_t naming;
status = pp_resolution_set_get_candidate(
resolutions, r, s, c, &uri, &confidence, &root, &has_naming,
&naming, &evidence_count, error);
if (status == PP_OK) {
printf("candidate: %s (%u/10000) under %s\n", uri, confidence,
root != NULL ? root : "no root");
}
}
}
}
if (status == PP_OK) {
*out_resolutions = resolutions;
} else {
pp_resolution_set_release(resolutions);
}
return status;
}
std::vector<postproject::RepresentationResolution>
resolve_asset(const postproject::Production &production,
const postproject::AssetId &asset_id,
const std::string &rushes_directory) {
// The mapping locates the logical root on this machine for this call only.
postproject::ResolutionConfig config;
config.root_mappings = {{"rushes", rushes_directory}};
config.verification = postproject::VerificationMode::content;
auto options = postproject::ResolutionOptions::create(config).value();
const auto resolutions = production.resolveAsset(asset_id, options).value();
for (const auto &representation : resolutions) {
std::cout << "availability: "
<< static_cast<std::uint32_t>(representation.availability)
<< '\n';
for (const auto &resource : representation.resources) {
for (const auto &candidate : resource.candidates()) {
std::cout << "candidate: " << candidate.uri << " ("
<< candidate.confidence_basis_points << "/10000)\n";
}
}
}
return resolutions;
}
def resolve_asset(
production: Production, asset_id: AssetId, rushes_directory: Path
) -> tuple[RepresentationResolution, ...]:
resolutions = production.resolve(
asset_id, {"rushes": rushes_directory}, verification=VerificationMode.CONTENT
)
for representation in resolutions:
print(f"availability: {representation.availability.name}")
for resource in representation.resources:
for candidate in resource.candidates:
print(
f"candidate: {candidate.uri} "
f"({candidate.confidence_basis_points}/10000)"
)
return resolutions
fn resolve_asset(
production: &SqliteProduction,
asset_id: AssetId,
rushes_directory: &Path,
) -> Result<(
postproject_core::DecisionBase,
Vec<RepresentationResolution>,
)> {
let view = production.read_session()?;
let base = view.decision_base();
let roots = view.read().media_roots()?;
let mut work = Vec::new();
for representation in view.read().representations(asset_id)? {
let resources = view
.read()
.resources(representation.id())?
.into_iter()
.map(|resource| {
let locators = view.read().locators(resource.id())?;
Ok((resource, locators))
})
.collect::<Result<Vec<_>>>()?;
work.push((representation, resources));
}
drop(view); // Release the database view before filesystem work.
let scope = SearchScope::new(
roots,
vec![MediaRootMapping::new("rushes", rushes_directory)?],
);
let items = work
.iter()
.flat_map(|(representation, resources)| {
resources.iter().map(|(resource, locators)| {
ResolutionItem::new(resource, representation.content_structure(), locators)
})
})
.collect::<Vec<_>>();
let resolver = MediaResolver::new(ResolverOptions {
verification: VerificationMode::Content,
..ResolverOptions::default()
})?;
let mut resources = resolver.resolve(&items, &scope)?.into_iter();
let resolutions = work
.iter()
.map(|(representation, members)| {
RepresentationResolution::aggregate(
representation.id(),
representation.content_structure(),
resources.by_ref().take(members.len()).collect(),
)
})
.collect::<Result<Vec<_>>>()?;
Ok((base, resolutions))
}
postproject --json media resolve production.pproj "$ASSET_ID" \
--root-map rushes="$PWD/moved" > resolution.json
jq -r '.resolutions[] | .availability' resolution.json
jq -r '.resolutions[].resources[].candidates[].uri' resolution.json
Reading a representation returns its content structure, members, resources, fingerprints, and locators as separate facts:
static void print_hex(const char *label, const char *algorithm,
uint16_t version, const uint8_t *value, uint64_t length) {
printf(" %s %s v%u: ", label, algorithm, version);
for (uint64_t i = 0; i < length && i < 8; ++i) {
printf("%02x", value[i]);
}
printf("%s\n", length > 8 ? "..." : "");
}
static pp_error_code_t print_resource(const pp_representation_set_t *set,
uint64_t r, uint64_t s,
pp_error_t **error) {
pp_resource_id_t resource_id;
uint8_t has_file_facts = 0;
uint64_t size = 0;
uint8_t has_modified_at = 0;
int64_t modified_at = 0;
uint64_t locator_count = 0;
uint64_t fingerprint_count = 0;
pp_error_code_t status = pp_representation_set_get_resource(
set, r, s, &resource_id, &has_file_facts, &size, &has_modified_at,
&modified_at, &locator_count, &fingerprint_count, error);
/* Saved resource text and dynamic targets use explicit checked boundaries. */
char *saved = NULL;
pp_resource_id_t parsed = {{0}};
pp_resource_id_t projected = {{0}};
pp_object_ref_t target = {0};
if (status == PP_OK) status = pp_resource_id_format(resource_id, &saved, error);
if (status == PP_OK) status = pp_resource_id_parse(saved, &parsed, error);
if (status == PP_OK) status = pp_object_ref_from_resource(parsed, &target, error);
if (status == PP_OK) status = pp_object_ref_get_resource(&target, &projected, error);
if (status == PP_OK && memcmp(projected.bytes, resource_id.bytes, 16) != 0)
status = PP_ERROR_INTERNAL;
pp_string_release(saved);
if (status == PP_OK && has_file_facts != 0) {
printf(" resource %llu: %llu bytes\n", (unsigned long long)s,
(unsigned long long)size);
}
for (uint64_t f = 0; status == PP_OK && f < fingerprint_count; ++f) {
const char *algorithm = NULL;
uint16_t version = 0;
const uint8_t *value = NULL;
uint64_t length = 0;
status = pp_representation_set_get_resource_fingerprint(
set, r, s, f, &algorithm, &version, &value, &length, error);
if (status == PP_OK) {
print_hex("resource fingerprint", algorithm, version, value, length);
}
}
for (uint64_t l = 0; status == PP_OK && l < locator_count; ++l) {
pp_locator_id_t locator_id;
const char *uri = NULL;
pp_locator_availability_t availability;
uint8_t has_last_seen = 0;
int64_t last_seen = 0;
uint8_t has_naming = 0;
pp_sequence_naming_t naming;
status = pp_representation_set_get_locator(
set, r, s, l, &locator_id, &uri, &availability, &has_last_seen,
&last_seen, &has_naming, &naming, error);
if (status == PP_OK && has_naming) {
/* A sequence locator names its directory and the files there. */
printf(" locator: %s %s%0*d%s (availability %u)\n", uri,
naming.prefix, (int)naming.padding, 1001, naming.suffix,
availability);
} else if (status == PP_OK) {
printf(" locator: %s (availability %u)\n", uri, availability);
}
}
return status;
}
static pp_error_code_t print_representation(const pp_representation_set_t *set,
uint64_t r,
int64_t *out_missing_frame,
pp_error_t **error) {
pp_representation_id_t id;
pp_asset_id_t asset_id;
pp_representation_kind_t kind;
pp_content_structure_kind_t structure;
uint64_t members = 0;
uint64_t resources = 0;
uint64_t fingerprints = 0;
pp_error_code_t status =
pp_representation_set_get(set, r, &id, &asset_id, &kind, &structure,
&members, &resources, &fingerprints, error);
if (status == PP_OK) {
printf("representation kind %u, structure %u\n", kind, structure);
}
/* Members are in structural order; single files and sequences have no role.
*/
for (uint64_t m = 0; status == PP_OK && m < members; ++m) {
pp_resource_id_t resource_id;
const char *role = NULL;
uint8_t required = 0;
status = pp_representation_set_get_member(set, r, m, &resource_id, &role,
&required, error);
if (status == PP_OK) {
printf(" member %llu: %s%s\n", (unsigned long long)m,
role != NULL ? role : "(no role)", required ? "" : " (optional)");
}
}
for (uint64_t s = 0; status == PP_OK && s < resources; ++s) {
status = print_resource(set, r, s, error);
}
/* Representation fingerprints are distinct from resource fingerprints. */
for (uint64_t f = 0; status == PP_OK && f < fingerprints; ++f) {
const char *algorithm = NULL;
uint16_t version = 0;
const uint8_t *value = NULL;
uint64_t length = 0;
status = pp_representation_set_get_fingerprint(
set, r, f, &algorithm, &version, &value, &length, error);
if (status == PP_OK) {
print_hex("representation fingerprint", algorithm, version, value,
length);
}
}
if (status == PP_OK && structure == PP_CONTENT_IMAGE_SEQUENCE) {
int64_t start = 0, end = 0;
uint32_t step = 0, rate_numerator = 0, rate_denominator = 0;
uint64_t missing_count = 0;
status = pp_representation_set_get_sequence(
set, r, &start, &end, &step, &rate_numerator, &rate_denominator,
&missing_count, error);
for (uint64_t i = 0; status == PP_OK && i < missing_count; ++i) {
status = pp_representation_set_get_sequence_missing_frame(
set, r, i, out_missing_frame, error);
if (status == PP_OK) {
printf(" known missing frame: %lld\n", (long long)*out_missing_frame);
}
}
}
return status;
}
static pp_error_code_t print_asset_structure(const pp_production_t *production,
const pp_asset_id_t *asset_id,
uint64_t *out_count,
int64_t *out_missing_frame,
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_representation_set_t *page = NULL;
status = pp_production_representations_page(
production, *asset_id, UINT32_C(2), cursor, &page, error);
const uint64_t count =
status == PP_OK ? pp_representation_set_count(page) : 0;
for (uint64_t r = 0; status == PP_OK && r < count; ++r) {
status = print_representation(page, r, out_missing_frame, error);
}
*out_count += count;
/* The cursor borrows the page; copy it before releasing the page. */
const char *next =
status == PP_OK ? pp_representation_set_next_cursor(page) : NULL;
const int copied =
next != NULL
? snprintf(cursor_storage, sizeof cursor_storage, "%s", next)
: 0;
pp_representation_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;
}
std::vector<postproject::Representation>
print_structure(const postproject::Production &production,
const postproject::AssetId &asset_id) {
std::vector<postproject::Representation> all;
std::optional<std::string> cursor;
do {
const auto page = production.representations(asset_id, 2, cursor).value();
for (const auto &representation : page.items) {
std::cout << "representation kind "
<< static_cast<std::uint32_t>(representation.kind)
<< ", structure "
<< static_cast<std::uint32_t>(representation.structureKind())
<< ", " << representation.fingerprints.size()
<< " fingerprint(s)\n";
for (const auto &member : representation.members()) {
std::cout << " member " << member.role.value_or("-")
<< (member.required ? " (required)" : " (optional)") << '\n';
}
for (const auto &resource : representation.resources) {
for (const auto &fingerprint : resource.fingerprints) {
std::cout << " resource fingerprint " << fingerprint.algorithm
<< " v" << fingerprint.version << '\n';
}
for (const auto &locator : resource.locators) {
std::cout << " locator " << locator.uri;
// A sequence locator names its directory and the files there.
if (const auto &naming = locator.sequence_naming) {
std::cout << ' ' << naming->prefix << "#"
<< naming->suffix;
}
std::cout << '\n';
}
}
if (const auto *content = std::get_if<postproject::ImageSequenceContent>(
&representation.content.value())) {
const auto &sequence = content->descriptor;
std::cout << " frames " << sequence.start << '-' << sequence.end
<< " step " << sequence.step << ", missing:";
for (const auto frame : sequence.missing_frames) {
std::cout << ' ' << frame;
}
std::cout << '\n';
}
all.push_back(representation);
}
cursor = page.next_cursor;
} while (cursor.has_value());
return all;
}
def describe_representations(
production: Production, asset_id: AssetId
) -> list[Representation]:
described: list[Representation] = []
cursor = None
while True:
page = production.representations_page(asset_id, limit=2, cursor=cursor)
for representation in page.items:
print(f"{representation.kind.name} {representation.structure_kind.name}")
for member in representation.members:
print(f" member {member.role or '-'} required={member.required}")
for resource in representation.resources:
for fingerprint in resource.fingerprints:
print(f" resource {fingerprint.algorithm} v{fingerprint.version}")
for locator in resource.locators:
# A sequence locator names its directory and the files there.
naming = locator.sequence_naming
files = f" {naming.filename(1001)}" if naming is not None else ""
print(
f" locator {locator.uri}{files} ({locator.availability.name})"
)
# Representation fingerprints are separate from resource ones.
for fingerprint in representation.fingerprints:
print(f" representation {fingerprint.algorithm}")
content = representation.content
if isinstance(content, ImageSequenceContent):
sequence = content.descriptor
print(
f" frames {sequence.start}-{sequence.end}, "
f"rate {sequence.rate}, missing {list(sequence.missing_frames)}"
)
described.append(representation)
cursor = page.next_cursor
if cursor is None:
return described
fn print_structure(production: &SqliteProduction, asset_id: AssetId) -> Result<usize> {
let mut count = 0;
let mut cursor = None;
loop {
let page = production.representations_page(asset_id, &QueryPageRequest::new(2, cursor)?)?;
for representation in page.items() {
count += 1;
let structure = representation.content_structure();
println!(
"{} {:?} {:?}",
representation.id(),
representation.kind(),
structure.kind()
);
for fingerprint in representation.fingerprints() {
println!(
" fingerprint {} v{}",
fingerprint.algorithm(),
fingerprint.version()
);
}
for member in structure.members().unwrap_or_default() {
println!(
" member {} as {} (required: {})",
member.resource_id(),
member.role().as_str(),
member.is_required()
);
}
if let Some(sequence) = structure.image_sequence_descriptor() {
let frames = sequence.frames();
println!(
" frames {}-{} at {}, known missing {:?}",
frames.start(),
frames.end(),
sequence.rate(),
sequence.known_missing_frames()
);
}
for resource in production.resources(representation.id())? {
println!(" resource {}", resource.id());
for fingerprint in resource.fingerprints() {
println!(" fingerprint {}", fingerprint.algorithm());
}
for locator in production.locators(resource.id())? {
// A sequence locator names its directory and the files there.
match locator.sequence_naming() {
Some(naming) => {
println!(" locator {} {}", locator.uri(), naming.filename(1001));
}
None => println!(" locator {}", locator.uri()),
}
}
}
}
cursor = page.next_cursor().cloned();
if cursor.is_none() {
return Ok(count);
}
}
}
# Page through the asset's representations, following each next_cursor.
CURSOR=
while :; do
ARGS=(--json representation list media.pproj "$ASSET_ID" --limit 2)
[[ -n "$CURSOR" ]] && ARGS+=(--cursor "$CURSOR")
PAGE=$(postproject "${ARGS[@]}")
jq -r '.items[] | "\(.id) \(.kind) \(.structure) \(.fingerprints[0].value_hex)"' \
<<<"$PAGE"
CURSOR=$(jq -r '.next_cursor // empty' <<<"$PAGE")
[[ -z "$CURSOR" ]] && break
done
# Resources in structural order, with their fingerprints and locators.
for RESOURCE in $(postproject --json representation resources media.pproj \
"$PACKAGE_ID" | jq -r '.items[].id'); do
postproject --json locator list media.pproj "$RESOURCE" |
jq -r '.items[] | "\(.resource_id) \(.uri) \(.availability)"'
done
postproject --json media show media.pproj "$ASSET_ID" |
jq --arg id "$SEQUENCE_ID" '.representations[] | select(.id == $id) |
.resources[] | {fingerprints, locators: [.locators[].uri]}'