Compound-media integration¶
A host creates one representation for a sequence, span, or package. It should not import every member as an unrelated asset. The representation owns a content structure; its resources carry content evidence and one or more locators.
Media sources¶
A media source describes the content structure of a representation at its present location: a single file, an image sequence, ordered parts, or a package (ADR 0037). The same source serves both operations that create a representation:
import creates an asset whose original representation has the source’s structure; and
add representation adds a representation of a chosen kind, with the source’s structure, to an existing asset.
Both fingerprint the content and record a locator for each resource. A host already knows the structure of what it imports: an image strip lists its frames, and an editor knows a clip’s spans. A plain path is a single-file source on every surface.
Surface |
Single file |
Image sequence |
Ordered parts |
Package |
|---|---|---|---|---|
C |
|
|
|
|
C++ |
a native path |
|
|
|
Python |
a native path |
|
|
|
Rust |
|
|
|
|
In C, pp_transaction_import_media and pp_transaction_add_representation
borrow a pp_media_source_t only for the call, so one source may serve several
calls; release it with pp_media_source_release. The CLI describes an added
representation with a JSON source file and recognizes the structure of
imported media, as shown below.
Import an image sequence as an original¶
A compositor reading an EXR plate, or an editor importing an image strip, records the sequence as one asset whose only original representation is the sequence. The example imports a render directory with one frame known to be missing and reads back the asset’s single original:
static pp_error_code_t import_image_strip(pp_production_t *production,
const char *directory,
pp_asset_id_t *out_asset_id,
pp_content_structure_kind_t *out_kind,
pp_error_t **error) {
const int64_t missing_frames[] = {1003};
pp_media_source_t *strip = NULL;
pp_transaction_t *transaction = NULL;
pp_representation_set_t *representations = NULL;
/* The sequence becomes the new asset's only original representation. The
* directory and file naming become its locator; frames and rate its
* descriptor. */
const pp_sequence_naming_t naming = {"shot010.", ".exr", 4};
pp_error_code_t status = pp_media_source_create_image_sequence(
directory, &naming, 1001, 1004, 1, 24, 1, missing_frames, 1, &strip,
error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_import_media(transaction, strip, "shot010 strip",
out_asset_id, NULL, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
pp_media_source_release(strip);
if (status == PP_OK) {
status = pp_production_representations(production, *out_asset_id,
&representations, error);
}
if (status == PP_OK) {
pp_representation_id_t representation_id;
pp_asset_id_t owner;
pp_representation_kind_t kind;
uint64_t members, resources, fingerprints;
status = pp_representation_set_get(representations, 0, &representation_id,
&owner, &kind, out_kind, &members,
&resources, &fingerprints, error);
printf("%llu representation, structure %u\n",
(unsigned long long)pp_representation_set_count(representations),
status == PP_OK ? *out_kind : 0);
}
pp_representation_set_release(representations);
return status;
}
postproject::AssetId import_image_strip(postproject::Production &production,
const std::string &directory) {
// The sequence becomes the new asset's only original representation. The
// directory and file naming become its locator; frames and rate its
// descriptor.
const auto strip = postproject::MediaSource::imageSequence(
{directory, {"shot010.", ".exr", 4}, 1001, 1004, 1, 24, 1, {1003}});
auto transaction = production.edit().value();
const auto asset_id = transaction.importMedia(strip, "shot010 strip").value().asset_id;
transaction.commit().value();
const auto representations = production.representations(asset_id).value();
std::cout << representations.size() << " representation, sequence "
<< (representations.front().imageSequence() != nullptr) << '\n';
return asset_id;
}
def import_image_strip(production: Production, directory: Path) -> AssetId:
# The sequence becomes the new asset's only original representation. The
# directory and file naming become its locator; frames and rate its
# descriptor.
strip = ImageSequenceSource(
directory,
naming=SequenceNaming("shot010.", ".exr", 4),
start=1001,
end=1004,
step=1,
rate=Fraction(24),
missing_frames=(1003,),
)
with production.edit() as transaction:
asset_id = transaction.import_media(
strip, display_name="shot010 strip"
).asset_id
transaction.commit()
representations = production.representations[asset_id]
print(f"{len(representations)} representation, {representations[0].structure_kind}")
return asset_id
fn import_image_strip(production: &mut SqliteProduction, directory: &Path) -> Result<AssetId> {
// The sequence becomes the new asset's only original representation. The
// directory and file naming become its locator; frames and rate its
// descriptor.
let strip = ImageSequenceSource::new(
directory,
SequenceNaming::new("shot010.", ".exr", 4)?,
FrameRange::new(1001, 1004, 1)?,
RationalRate::new(24, 1)?,
vec![1003],
);
let import = prepare_original_media(strip, Some("shot010 strip".to_owned()), None)?;
let asset_id = import.asset().id();
{
let mut transaction = production.begin_transaction()?;
transaction.import_original(&import)?;
transaction.commit()?;
}
let representations = production.representations(asset_id)?;
let original = &representations[0];
println!(
"{} representation, {:?}",
representations.len(),
original.content_structure().kind()
);
Ok(asset_id)
}
# A directory holding one numbered image group imports as one asset whose
# only original representation is the sequence; frame 1003 is missing.
postproject --json media add media.pproj renders/shot010 --name "shot010 strip" \
--sequence-rate 24/1 > strip.json
postproject --json representation list media.pproj \
"$(jq -r .asset_id strip.json)" | jq -r '.items[] | "\(.kind) \(.structure)"'
Add an image sequence¶
An image-sequence representation is described compactly: directory, file naming (prefix, suffix, and frame-number padding), first and last frame, frame step, an exact rational frame rate, and any frames already known to be missing. The directory and naming become the sequence’s first locator; the frames, rate, and missing frames become its descriptor. File names belong to where a sequence is, not what it is (ADR 0038), so another copy may name the same frames differently. The example adds a derived render sequence to an existing asset and reads back the stored descriptor:
static pp_error_code_t add_render_sequence(pp_production_t *production,
const pp_asset_id_t *asset_id,
const char *directory,
pp_representation_id_t *out_sequence_id,
pp_error_t **error) {
const int64_t missing_frames[] = {1003};
pp_media_source_t *sequence = NULL;
pp_transaction_t *transaction = NULL;
pp_representation_set_t *representations = NULL;
/* Directory and file naming, frame range and step, exact rate, and the
* frames already known to be missing. */
const pp_sequence_naming_t naming = {"shot010.", ".exr", 4};
pp_error_code_t status = pp_media_source_create_image_sequence(
directory, &naming, 1001, 1004, 1, 24000, 1001, missing_frames, 1,
&sequence, error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_add_representation(
transaction, *asset_id, PP_REPRESENTATION_DERIVED, sequence,
out_sequence_id, error);
}
pp_media_source_release(sequence);
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_representations(production, *asset_id,
&representations, error);
}
for (uint64_t index = 0;
status == PP_OK && index < pp_representation_set_count(representations);
++index) {
pp_representation_id_t id;
pp_asset_id_t owner;
pp_representation_kind_t kind;
pp_content_structure_kind_t structure;
uint64_t members = 0;
uint64_t resources = 0;
uint64_t fingerprints = 0;
status = pp_representation_set_get(representations, index, &id, &owner,
&kind, &structure, &members, &resources,
&fingerprints, error);
if (status == PP_OK && structure == PP_CONTENT_IMAGE_SEQUENCE) {
int64_t start = 0;
int64_t end = 0;
uint32_t step = 0;
uint32_t rate_numerator = 0;
uint32_t rate_denominator = 0;
uint64_t missing_count = 0;
status = pp_representation_set_get_sequence(
representations, index, &start, &end, &step, &rate_numerator,
&rate_denominator, &missing_count, error);
if (status == PP_OK) {
printf("frames %lld-%lld at %u/%u, %llu known missing\n",
(long long)start, (long long)end, rate_numerator,
rate_denominator, (unsigned long long)missing_count);
}
}
}
pp_representation_set_release(representations);
pp_transaction_release(transaction);
return status;
}
postproject::RepresentationId add_render_sequence(postproject::Production &production,
const postproject::AssetId &asset_id,
const std::string &directory) {
postproject::ImageSequenceInput sequence{};
sequence.directory = directory;
sequence.naming = {"shot010.", ".exr", 4};
sequence.start = 1001;
sequence.end = 1004;
sequence.step = 1;
sequence.rate_numerator = 24000;
sequence.rate_denominator = 1001;
sequence.missing_frames = {1003};
auto transaction = production.edit().value();
const auto sequence_id = transaction.addRepresentation(
asset_id, postproject::RepresentationKind::derived,
postproject::MediaSource::imageSequence(sequence)).value();
transaction.commit().value();
for (const auto &representation : production.representations(asset_id).value()) {
if (representation.id == sequence_id && representation.imageSequence()) {
const auto &stored = *representation.imageSequence();
std::cout << "frames " << stored.start << '-' << stored.end << " at "
<< stored.rate_numerator << '/' << stored.rate_denominator
<< ", "
<< stored.missing_frames.size() << " known missing\n";
}
}
return sequence_id;
}
def add_render_sequence(
production: Production, asset_id: AssetId, directory: Path
) -> RepresentationId:
with production.edit() as transaction:
sequence_id = transaction.add_representation(
asset_id,
RepresentationKind.DERIVED,
ImageSequenceSource(
directory=directory,
naming=SequenceNaming("shot010.", ".exr", 4),
start=1001,
end=1004,
step=1,
rate=Fraction(24000, 1001),
missing_frames=(1003,),
),
)
transaction.commit()
stored = next(
item for item in production.representations[asset_id] if item.id == sequence_id
)
sequence = stored.image_sequence
assert sequence is not None
print(
f"frames {sequence.start}-{sequence.end} at "
f"{sequence.rate_numerator}/{sequence.rate_denominator}, "
f"{len(sequence.missing_frames)} known missing"
)
return sequence_id
fn add_render_sequence(
production: &mut SqliteProduction,
asset_id: AssetId,
directory: &Path,
) -> Result<RepresentationId> {
let source = ImageSequenceSource::new(
directory,
SequenceNaming::new("shot010.", ".exr", 4)?,
FrameRange::new(1001, 1004, 1)?,
RationalRate::new(24000, 1001)?,
vec![1003],
);
let import = prepare_representation(asset_id, RepresentationKind::Derived, source)?;
let sequence_id = import.representation().id();
{
let mut transaction = production.begin_transaction()?;
transaction.add_representation(&import)?;
transaction.commit()?;
}
let stored = production
.representations(asset_id)?
.into_iter()
.find(|representation| representation.id() == sequence_id)
.expect("committed representation");
println!("structure: {:?}", stored.content_structure().kind());
Ok(sequence_id)
}
cat > shot010.json <<'EOF'
{
"structure": "image_sequence",
"directory": "renders/shot010",
"prefix": "shot010.",
"suffix": ".exr",
"padding": 4,
"start": 1001,
"end": 1004,
"step": 1,
"rate_numerator": 24000,
"rate_denominator": 1001,
"missing_frames": [1003]
}
EOF
SEQUENCE_ID=$(postproject --json representation add production.pproj \
"$ASSET_ID" derived shot010.json | jq -r .representation_id)
postproject media show production.pproj "$ASSET_ID"
Add a proxy or other single-file representation¶
A proxy, an optimized mezzanine, or a derived render is another representation of the same asset, not a new asset. The example adds a single-file proxy to the imported asset; the file becomes a new resource with a confirmed locator and a content fingerprint:
static pp_error_code_t add_proxy(pp_production_t *production,
const pp_asset_id_t *asset_id,
const char *proxy_path,
pp_representation_id_t *out_proxy_id, pp_error_t **error) {
pp_transaction_t *transaction = NULL;
pp_error_code_t status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
if (status == PP_OK) {
/* The file is fingerprinted and recorded as one more representation of
* the same asset; it never becomes an unrelated asset. */
status = pp_transaction_add_file_representation(transaction, *asset_id, PP_REPRESENTATION_PROXY, proxy_path, out_proxy_id, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
return status;
}
postproject::RepresentationId add_proxy(postproject::Production &production,
const postproject::AssetId &asset_id,
const std::string &proxy_path) {
auto transaction = production.edit().value();
// A native path describes a file without an intermediate source owner.
const auto proxy_id = transaction.addRepresentation(
asset_id, postproject::RepresentationKind::proxy,
std::filesystem::path(proxy_path)).value();
transaction.commit().value();
require(postproject::RepresentationId::fromString(proxy_id.toString().value()).value()
== proxy_id, "saved representation identity");
require(postproject::ObjectRef::representation(proxy_id).representationId().value()
== proxy_id, "typed representation target");
return proxy_id;
}
def add_proxy(
production: Production, asset_id: AssetId, proxy: Path
) -> RepresentationId:
# A plain path is a single-file source too.
with production.edit() as transaction:
proxy_id = transaction.add_representation(
asset_id, RepresentationKind.PROXY, proxy
)
transaction.commit()
return proxy_id
fn add_proxy(
production: &mut SqliteProduction,
asset_id: AssetId,
proxy: &Path,
) -> Result<RepresentationId> {
// A path converts to a single-file source.
let import = prepare_representation(asset_id, RepresentationKind::Proxy, proxy)?;
let mut transaction = production.begin_transaction()?;
transaction.add_representation(&import)?;
transaction.commit()?;
Ok(import.representation().id())
}
cat > proxy.json <<'EOF'
{"structure": "single_file", "path": "proxies/A001_proxy.mov"}
EOF
PROXY_ID=$(postproject --json representation add media.pproj "$ASSET_ID" \
proxy proxy.json | jq -r .representation_id)
A path converts to a single-file source, so a proxy needs no other source type. The representation kind (original, proxy, optimized, or derived) says how the representation relates to the asset. Why it exists — which activity produced it from which input — is recorded separately as provenance.
Add ordered parts¶
A camera recording spanned across several files is one representation whose members are ordered. Each member carries an open-world role and is required unless marked optional; the order of the list is significant and preserved:
static pp_error_code_t
add_spanned_clip(pp_production_t *production, const pp_asset_id_t *asset_id,
const char *first_part, const char *second_part,
pp_representation_id_t *out_representation_id, pp_error_t **error) {
/* Order is significant, and every ordered part must be required. */
const pp_file_resource_input_t parts[] = {
{first_part, "org.postproject:span-part", UINT8_C(1)},
{second_part, "org.postproject:span-part", UINT8_C(1)},
};
pp_media_source_t *clip = NULL;
pp_transaction_t *transaction = NULL;
pp_error_code_t status =
pp_media_source_create_ordered_parts(parts, 2, &clip, error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_add_representation(
transaction, *asset_id, PP_REPRESENTATION_OPTIMIZED, clip,
out_representation_id, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
pp_media_source_release(clip);
return status;
}
postproject::RepresentationId add_spanned_clip(postproject::Production &production,
const postproject::AssetId &asset_id,
const std::string &directory) {
// Parts are stored in this order; every part of a span is required.
const auto parts = postproject::MediaSource::orderedParts({
{directory + "/CLIP0001.MTS", "org.postproject:essence", true},
{directory + "/CLIP0002.MTS", "org.postproject:span-part", true},
});
auto transaction = production.edit().value();
const auto clip_id = transaction.addRepresentation(
asset_id, postproject::RepresentationKind::original, parts).value();
transaction.commit().value();
return clip_id;
}
def add_spanned_clip(
production: Production, asset_id: AssetId, directory: Path
) -> RepresentationId:
# One recording spanned over several files: every part is required and
# the member order is preserved.
parts = OrderedPartsSource(
(
FileResourceInput(
str(directory / "CLIP0001.MTS"), "org.postproject:essence"
),
FileResourceInput(
str(directory / "CLIP0002.MTS"), "org.postproject:span-part"
),
)
)
with production.edit() as transaction:
clip_id = transaction.add_representation(
asset_id, RepresentationKind.ORIGINAL, parts
)
transaction.commit()
return clip_id
fn add_spanned_clip(
production: &mut SqliteProduction,
asset_id: AssetId,
spanned: &Path,
) -> Result<RepresentationId> {
// Order is significant: the parts play back as one continuous clip.
let parts = MediaSource::OrderedParts(vec![
FileResourceSource::new(
spanned.join("CLIP0001.MTS"),
ResourceRole::new(PRIMARY_ESSENCE_ROLE)?,
true,
),
FileResourceSource::new(
spanned.join("CLIP0002.MTS"),
ResourceRole::new(SPAN_PART_ROLE)?,
true,
),
]);
let import = prepare_representation(asset_id, RepresentationKind::Original, parts)?;
let mut transaction = production.begin_transaction()?;
transaction.add_representation(&import)?;
transaction.commit()?;
Ok(import.representation().id())
}
# The parts of one spanned recording form a single representation, in order.
cat > spanned.json <<'EOF'
{
"structure": "ordered_parts",
"members": [
{"path": "spanned/CLIP0001.MTS", "role": "org.postproject:span-part"},
{"path": "spanned/CLIP0002.MTS", "role": "org.postproject:span-part"}
]
}
EOF
SPANNED_ID=$(postproject --json representation add media.pproj "$ASSET_ID" \
original spanned.json | jq -r .representation_id)
Add a package¶
A package groups files that belong together without an order, such as an essence file and its metadata sidecar. Optional members may be missing without making the representation unavailable:
static pp_error_code_t add_package(pp_production_t *production,
const pp_asset_id_t *asset_id,
const char *essence, const char *sidecar,
pp_representation_id_t *out_representation_id,
pp_error_t **error) {
/* A package needs at least one required member; an optional sidecar that
* goes missing produces an issue but does not reduce availability. */
const pp_file_resource_input_t members[] = {
{essence, "org.postproject:essence", UINT8_C(1)},
{sidecar, "org.postproject:sidecar", UINT8_C(0)},
};
pp_media_source_t *package = NULL;
pp_transaction_t *transaction = NULL;
pp_error_code_t status =
pp_media_source_create_package(members, 2, &package, error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_add_representation(
transaction, *asset_id, PP_REPRESENTATION_DERIVED, package,
out_representation_id, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
pp_media_source_release(package);
return status;
}
postproject::RepresentationId add_package(postproject::Production &production,
const postproject::AssetId &asset_id,
const std::string &directory) {
// A package needs at least one required member; sidecars may be optional.
const auto members = postproject::MediaSource::package({
{directory + "/clip.mxf", "org.postproject:essence", true},
{directory + "/clip.xml", "org.postproject:sidecar", false},
});
auto transaction = production.edit().value();
const auto package_id = transaction.addRepresentation(
asset_id, postproject::RepresentationKind::original, members).value();
transaction.commit().value();
return package_id;
}
def add_package(
production: Production, asset_id: AssetId, directory: Path
) -> RepresentationId:
members = PackageSource(
(
FileResourceInput(str(directory / "clip.mxf"), "org.postproject:essence"),
# An optional member may go missing without making the package offline.
FileResourceInput(
str(directory / "clip.xml"), "org.postproject:sidecar", required=False
),
)
)
with production.edit() as transaction:
package_id = transaction.add_representation(
asset_id, RepresentationKind.OPTIMIZED, members
)
transaction.commit()
return package_id
fn add_package(
production: &mut SqliteProduction,
asset_id: AssetId,
package: &Path,
) -> Result<RepresentationId> {
let members = MediaSource::Package(vec![
FileResourceSource::new(
package.join("clip.mxf"),
ResourceRole::new(PRIMARY_ESSENCE_ROLE)?,
true,
),
// An optional member may be missing without making the package unusable.
FileResourceSource::new(
package.join("clip.xml"),
ResourceRole::new(SIDECAR_ROLE)?,
false,
),
]);
let import = prepare_representation(asset_id, RepresentationKind::Derived, members)?;
let mut transaction = production.begin_transaction()?;
transaction.add_representation(&import)?;
transaction.commit()?;
Ok(import.representation().id())
}
# Members default to required; an optional sidecar may be offline without
# making the package unavailable.
cat > package.json <<'EOF'
{
"structure": "package",
"members": [
{"path": "package/clip.mxf", "role": "org.postproject:essence"},
{"path": "package/clip.xml", "role": "org.postproject:sidecar",
"required": false}
]
}
EOF
PACKAGE_ID=$(postproject --json representation add media.pproj "$ASSET_ID" \
optimized package.json | jq -r .representation_id)
Read the stored structure¶
After commit, enumerate representations rather than retaining a private host index. Each representation exposes:
the content-structure kind;
ordered members, open-world roles, and requiredness;
the compact sequence descriptor and the frames known to be missing;
resources and their fingerprints;
resource locators, each with the naming of its sequence files for an image sequence; and
representation fingerprints separately from resource fingerprints.
The example reads one page of an asset’s representations and walks that structure:
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]}'
Availability¶
Read a sequence’s file names from the locator you use, not from the representation: a sequence renamed and relinked has one locator per naming.
Resolution returns one aggregate availability value plus resource results and issues. Missing sequence frames are sorted individual frame numbers. Optional package members may produce issues but do not reduce availability. Never choose one ambiguous candidate in integration code; present the candidates to the user and persist only an explicit confirmation.
Recognition¶
The Rust media adapter additionally recognizes compound media from filenames
and layouts: numbered image groups, numbered camera spans, same-stem sidecars,
and the checked AVCHD card layout. The CLI reaches the same adapter when
media add receives a directory, and with --recognize-companions for
sidecars:
Recognition is not exposed through the C ABI. Describe the structure
explicitly with pp_media_source_create_image_sequence,
pp_media_source_create_ordered_parts, or pp_media_source_create_package,
and import or add it as shown above.
Recognition is not exposed through the C++ wrapper. Describe the structure
explicitly with MediaSource::imageSequence, MediaSource::orderedParts, or
MediaSource::package, and import or add it as shown above.
Recognition is not exposed through the Python binding. Describe the structure
explicitly with ImageSequenceSource, OrderedPartsSource, or
PackageSource, and import or add it as shown above.
fn import_with_sidecar(production: &mut SqliteProduction, clip: &Path) -> Result<AssetId> {
let recognizer = MediaRecognizer::new(RationalRate::new(24, 1)?);
// A file with a same-named .xml, .xmp, or .json sidecar becomes a package.
let candidates = recognizer.recognize(clip)?;
let [media @ RecognizedMedia::Package(members)] = candidates.as_slice() else {
panic!("expected one package with a sidecar");
};
for member in members {
println!(
"{} as {} (required: {})",
member.path().display(),
member.role(),
member.is_required()
);
}
let import = prepare_recognized_original_media(media, Some("B001".to_owned()), None)?;
let mut transaction = production.begin_transaction()?;
transaction.import_original(&import)?;
transaction.commit()?;
Ok(import.asset().id())
}
printf 'camera C' > card/C001.mov
printf '<clip id="C001"/>' > card/C001.xml
# A same-stem .xml, .xmp, or .json sidecar joins the file as an optional
# package member instead of becoming a separate asset.
postproject --json media add media.pproj card/C001.mov --recognize-companions \
> recognized.json
postproject --json representation list media.pproj \
"$(jq -r .asset_id recognized.json)" | jq -r '.items[] | "\(.kind) \(.structure)"'
AVCHD recognition assigns open-world PostProject roles for essence, clip-information, playlist, and navigation members. These labels describe the adapter’s preservation model; they do not claim conformance validation or interpret vendor metadata.