Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ format:
ifndef CLANG_FORMAT_PROG
$(error $(newline)$(ccred)clang-format is not available on $$PATH$(ccend))
endif
$(eval DIRS = src/opentime src/opentimelineio src/opentimelineio/algo)
$(eval DIRS = src/opentime)
$(eval DIRS += src/opentimelineio)
$(eval DIRS += src/opentimelineio/algo)
$(eval DIRS += tests)
$(eval DIRS += examples)
$(eval DIRS += src/py-opentimelineio/opentime-bindings)
$(eval DIRS += src/py-opentimelineio/opentimelineio-bindings)
$(eval FILES_TO_FORMAT = $(wildcard $(addsuffix /*.h, $(DIRS)) $(addsuffix /*.cpp, $(DIRS))))
echo "formatting..." $(FILES_TO_FORMAT)
$(shell clang-format -i -style=file $(FILES_TO_FORMAT))

manifest:
Expand Down
49 changes: 28 additions & 21 deletions examples/conform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION_NS;

// Look for media with this name in this folder.
std::string find_matching_media(std::string const& name, std::string const& folder)
std::string
find_matching_media(std::string const& name, std::string const& folder)
{
// This function is an example which searches the file system for matching media.
// A real world studio implementation would likely look in an asset management system
Expand All @@ -41,9 +42,9 @@ std::string find_matching_media(std::string const& name, std::string const& fold
// shot = asset_database->find_shot(
// otio::any_cast<std::map<std::string, std::string> >(clip->metadata()["mystudio"])["shotID"]);
// new_media = shot->latest_render("mov");

const auto matches = examples::glob(folder, name + ".*");

if (matches.size() == 0)
{
//std::cout << "DEBUG: No match for clip '" << name << "'" << std::endl;
Expand All @@ -55,8 +56,9 @@ std::string find_matching_media(std::string const& name, std::string const& fold
}
else
{
std::cout << "WARNING: " << matches.size() << " matches found for clip '" <<
name << "', using '" << matches[0] << "'";
std::cout << "WARNING: " << matches.size()
<< " matches found for clip '" << name << "', using '"
<< matches[0] << "'";
return matches[0];
}
}
Expand All @@ -70,21 +72,22 @@ std::string find_matching_media(std::string const& name, std::string const& fold
// internal reference count. For more details on the usage of Retainers see
// the C++ documentation:
// https://opentimelineio.readthedocs.io/en/latest/cxx/cxx.html
int conform_timeline(
int
conform_timeline(
otio::SerializableObject::Retainer<otio::Timeline> const& timeline,
std::string const& folder)
std::string const& folder)
{
int count = 0;

otio::ErrorStatus error_status;
const auto clips = timeline->find_clips(&error_status);
const auto clips = timeline->find_clips(&error_status);
if (otio::is_error(error_status))
{
examples::print_error(error_status);
exit(1);
}
for (const otio::SerializableObject::Retainer<otio::Clip>& clip : clips)

for (const otio::SerializableObject::Retainer<otio::Clip>& clip: clips)
{
// look for a media file that matches the clip's name
const std::string new_path = find_matching_media(clip->name(), folder);
Expand All @@ -96,28 +99,31 @@ int conform_timeline(
// relink to the found path
clip->set_media_reference(new otio::ExternalReference(
"file://" + new_path,
std::nullopt // the available range is unknown without opening the file
));
std::
nullopt // the available range is unknown without opening the file
));
count += 1;
}

return count;
}

int main(int argc, char** argv)
int
main(int argc, char** argv)
{
if (argc != 4)
{
std::cout << "Usage: conform (input) (folder) (output)" << std::endl;
return 1;
}
const std::string input = examples::normalize_path(argv[1]);
const std::string input = examples::normalize_path(argv[1]);
const std::string folder = examples::normalize_path(argv[2]);
const std::string output = examples::normalize_path(argv[3]);
otio::ErrorStatus error_status;

otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(
dynamic_cast<otio::Timeline*>(otio::Timeline::from_json_file(input, &error_status)));
dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(input, &error_status)));
if (!timeline || otio::is_error(error_status))
{
examples::print_error(error_status);
Expand All @@ -136,7 +142,8 @@ int main(int argc, char** argv)
examples::print_error(error_status);
exit(1);
}
std::cout << "Saved " << output << " with " << clips.size() << " clips." << std::endl;

std::cout << "Saved " << output << " with " << clips.size() << " clips."
<< std::endl;

return 0;
}
46 changes: 28 additions & 18 deletions examples/flatten_video_tracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,37 @@

namespace otio = opentimelineio::OPENTIMELINEIO_VERSION_NS;

int main(int argc, char** argv)
int
main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Usage: flatten_video_tracks (inputpath) (outputpath)" << std::endl;
std::cout << "Usage: flatten_video_tracks (inputpath) (outputpath)"
<< std::endl;
return 1;
}

// Read the file
otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(dynamic_cast<otio::Timeline*>(otio::Timeline::from_json_file(argv[1], &error_status)));
otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(
dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(argv[1], &error_status)));
if (!timeline)
{
examples::print_error(error_status);
return 1;
}
auto video_tracks = timeline.value->video_tracks();
auto audio_tracks = timeline.value->audio_tracks();
std::cout << "Read " << video_tracks.size() << " video tracks and " <<
audio_tracks.size() << " audio tracks." << std::endl;

std::cout << "Read " << video_tracks.size() << " video tracks and "
<< audio_tracks.size() << " audio tracks." << std::endl;

// Take just the video tracks - and flatten them into one.
// This will trim away any overlapping segments, collapsing everything
// into a single track.
std::cout << "Flattening " << video_tracks.size() << " video tracks into one..." << std::endl;
std::cout << "Flattening " << video_tracks.size()
<< " video tracks into one..." << std::endl;
auto onetrack = otio::flatten_stack(video_tracks, &error_status);
if (!onetrack || is_error(error_status))
{
Expand All @@ -45,22 +50,25 @@ int main(int argc, char** argv)
}

// Now make a new empty Timeline and put that one Track into it
std::string name;
std::string name;
std::stringstream ss(name);
ss << timeline.value->name() << " Flattened";
auto newtimeline = otio::SerializableObject::Retainer<otio::Timeline>(new otio::Timeline(ss.str()));
auto stack = otio::SerializableObject::Retainer<otio::Stack>(new otio::Stack());
auto newtimeline = otio::SerializableObject::Retainer<otio::Timeline>(
new otio::Timeline(ss.str()));
auto stack =
otio::SerializableObject::Retainer<otio::Stack>(new otio::Stack());
newtimeline.value->set_tracks(stack);
if (!stack.value->append_child(onetrack, &error_status))
{
examples::print_error(error_status);
return 1;
return 1;
}

// keep the audio track(s) as-is
for (const auto& audio_track : audio_tracks)
for (const auto& audio_track: audio_tracks)
{
auto clone = dynamic_cast<otio::Track*>(audio_track->clone(&error_status));
auto clone =
dynamic_cast<otio::Track*>(audio_track->clone(&error_status));
if (!clone)
{
examples::print_error(error_status);
Expand All @@ -72,10 +80,12 @@ int main(int argc, char** argv)
return 1;
}
}

// ...and save it to disk.
std::cout << "Saving " << newtimeline.value->video_tracks().size() << " video tracks and " <<
newtimeline.value->audio_tracks().size() << " audio tracks." << std::endl;
std::cout << "Saving " << newtimeline.value->video_tracks().size()
<< " video tracks and "
<< newtimeline.value->audio_tracks().size() << " audio tracks."
<< std::endl;
if (!newtimeline.value->to_json_file(argv[2], &error_status))
{
examples::print_error(error_status);
Expand Down
Loading
Loading