Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "src/deps/Imath"]
path = src/deps/Imath
url = https://github.com/AcademySoftwareFoundation/Imath
[submodule "src/deps/minizip-ng"]
path = src/deps/minizip-ng
url = https://github.com/zlib-ng/minizip-ng.git
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ project(OpenTimelineIO VERSION ${OTIO_VERSION} LANGUAGES C CXX)
# Installation options
option(OTIO_CXX_INSTALL "Install the C++ bindings" ON)
option(OTIO_PYTHON_INSTALL "Install the Python bindings" OFF)
option(OTIO_DEPENDENCIES_INSTALL "Install OTIO's C++ header dependencies (Imath)" ON)
option(OTIO_INSTALL_PYTHON_MODULES "Install OTIO pure Python modules/files" ON)
option(OTIO_INSTALL_COMMANDLINE_TOOLS "Install the OTIO command line tools" ON)
option(OTIO_INSTALL_CONTRIB "Install the opentimelineio_contrib Python package" ON)
option(OTIO_FIND_IMATH "Find Imath using find_package" OFF)
option(OTIO_FIND_RAPIDJSON "Find RapidJSON using find_package" OFF)
option(OTIO_FIND_MINIZIP_NG "Find minizip-ng using find_package" OFF)
set(OTIO_PYTHON_INSTALL_DIR "" CACHE STRING "Python installation dir (such as the site-packages dir)")

# Build options
Expand Down Expand Up @@ -148,12 +148,6 @@ set(OTIO_RESOLVED_CXX_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
if(OTIO_CXX_INSTALL)
message(STATUS "Installing C++ bindings to: ${OTIO_RESOLVED_CXX_INSTALL_DIR}")
message(STATUS "Installing C++ dynamic libraries to: ${OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR}")

if(OTIO_DEPENDENCIES_INSTALL)
message(STATUS " Installing header dependencies for C++ (OTIO_DEPENDENCIES_INSTALL=ON)")
else()
message(STATUS " Not installing header dependencies for C++ (OTIO_DEPENDENCIES_INSTALL=OFF)")
endif()
else()
message(STATUS "Install C++ bindings: OFF")
endif()
Expand Down Expand Up @@ -263,6 +257,16 @@ else()
message(STATUS "Using src/deps/rapidjson by default")
endif()

#----- minizip-ng
if(OTIO_FIND_MINIZIP_NG)
find_package(minizip-ng CONFIG REQUIRED)
if (minizip-ng_FOUND)
message(STATUS "Found minizip-ng at ${minizip-ng_CONFIG}")
endif()
else()
message(STATUS "Using src/deps/minizip-ng by default")
endif()

# set up the internally hosted dependencies
add_subdirectory(src/deps)

Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/deps/optional-lite/include
${PYTHON_INCLUDE_DIRS})

list(APPEND examples bundle)
list(APPEND examples conform)
list(APPEND examples flatten_video_tracks)
list(APPEND examples summarize_timing)
Expand Down
113 changes: 113 additions & 0 deletions examples/bundle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project

// Example OTIO script that can create and extract bundles.

#include "util.h"

#include "opentimelineio/bundle.h"
#include "opentimelineio/fileUtils.h"
#include "opentimelineio/timeline.h"

#include <filesystem>

namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
namespace bundle = opentimelineio::OPENTIMELINEIO_VERSION::bundle;

bool
ends_with(std::string const& s, std::string const& find)
{
size_t const s_size = s.size();
size_t const find_size = find.size();
return find_size < s_size ?
s.substr(s_size - find_size, find_size) == find :
false;
}

int
main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Usage:\n";
std::cout << " bundle (input.otio) (output.otioz) - "
<< "Create an .otioz bundle from an .otio file.\n";
std::cout << " bundle (input.otio) (output.otiod) - "
<< "Create an .otiod bundle from an .otio file.\n";
std::cout << " bundle (input.otioz) (output) - "
<< "Extract an .otioz bundle.\n";
return 1;
}
const std::string input = otio::to_unix_separators(argv[1]);
const std::string output = otio::to_unix_separators(argv[2]);

if (ends_with(input, ".otio") && ends_with(output, ".otioz"))
{
// Open timeline.
otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(
dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(input, &error_status)));
if (!timeline || otio::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}

// Create .otioz bundle.
bundle::WriteOptions options;
options.parent_path =
std::filesystem::u8path(input).parent_path().u8string();
if (!bundle::to_otioz(
timeline.value,
output,
options,
&error_status))
{
examples::print_error(error_status);
return 1;
}
}
else if (ends_with(input, ".otioz"))
{
// Extract .otioz bundle.
bundle::OtiozReadOptions options;
options.extract_path = output;
otio::ErrorStatus error_status;
auto result = bundle::from_otioz(input, options, &error_status);
if (otio::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}
}
else if (ends_with(input, ".otio") && ends_with(output, ".otiod"))
{
// Open timeline.
otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(
dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(input, &error_status)));
if (!timeline || otio::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}

// Create .otiod bundle.
bundle::WriteOptions options;
options.parent_path =
std::filesystem::u8path(input).parent_path().u8string();
if (!bundle::to_otiod(
timeline.value,
output,
options,
&error_status))
{
examples::print_error(error_status);
return 1;
}
}

return 0;
}
7 changes: 4 additions & 3 deletions examples/conform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <opentimelineio/clip.h>
#include <opentimelineio/externalReference.h>
#include <opentimelineio/fileUtils.h>
#include <opentimelineio/timeline.h>

#include <iostream>
Expand Down Expand Up @@ -111,9 +112,9 @@ int main(int argc, char** argv)
std::cout << "Usage: conform (input) (folder) (output)" << std::endl;
return 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]);
const std::string input = otio::to_unix_separators(argv[1]);
const std::string folder = otio::to_unix_separators(argv[2]);
const std::string output = otio::to_unix_separators(argv[3]);

otio::ErrorStatus error_status;
otio::SerializableObject::Retainer<otio::Timeline> timeline(
Expand Down
11 changes: 6 additions & 5 deletions examples/io_perf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>

#include "opentimelineio/clip.h"
#include "opentimelineio/fileUtils.h"
#include "opentimelineio/typeRegistry.h"
#include "opentimelineio/serialization.h"
#include "opentimelineio/deserialization.h"
Expand Down Expand Up @@ -93,7 +94,7 @@ main(
const std::string tmp_dir_path = (
RUN_STRUCT.FIXED_TMP
? "/var/tmp/ioperftest"
: examples::create_temp_dir()
: otio::create_temp_dir()
);

otio::ErrorStatus err;
Expand Down Expand Up @@ -123,7 +124,7 @@ main(
cl->metadata()["example thing"] = "banana";
chrono_time_point begin = std::chrono::steady_clock::now();
cl->to_json_file(
examples::normalize_path(tmp_dir_path + "/clip.otio"),
otio::to_unix_separators(tmp_dir_path + "/clip.otio"),
&err,
&downgrade_manifest
);
Expand All @@ -140,7 +141,7 @@ main(
otio::SerializableObject::Retainer<otio::Timeline> timeline(
dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(
examples::normalize_path(argv[1]),
otio::to_unix_separators(argv[1]),
&err
)
)
Expand Down Expand Up @@ -205,7 +206,7 @@ main(
{
begin = std::chrono::steady_clock::now();
timeline.value->to_json_file(
examples::normalize_path(tmp_dir_path + "/io_perf_test.otio"),
otio::to_unix_separators(tmp_dir_path + "/io_perf_test.otio"),
&err,
&downgrade_manifest
);
Expand All @@ -218,7 +219,7 @@ main(
{
begin = std::chrono::steady_clock::now();
timeline.value->to_json_file(
examples::normalize_path(
otio::to_unix_separators(
tmp_dir_path
+ "/io_perf_test.nodowngrade.otio"
),
Expand Down
87 changes: 2 additions & 85 deletions examples/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "util.h"

#include "opentimelineio/fileUtils.h"
#include <opentimelineio/timeline.h>

#include <Python.h>
Expand All @@ -16,7 +17,6 @@
#define WIN32_LEAN_AND_MEAN
#endif // WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <combaseapi.h>
#if defined(min)
#undef min
#endif // min
Expand All @@ -35,16 +35,6 @@ namespace examples {

#if defined(_WINDOWS)

std::string normalize_path(std::string const& in)
{
std::string out;
for (auto i : in)
{
out.push_back('\\' == i ? '/' : i);
}
return out;
}

std::string absolute(std::string const& in)
{
wchar_t buf[MAX_PATH];
Expand All @@ -53,45 +43,7 @@ std::string absolute(std::string const& in)
{
buf[0] = 0;
}
return normalize_path(utf16.to_bytes(buf));
}

std::string create_temp_dir()
{
std::string out;

// Get the temporary directory.
char path[MAX_PATH];
DWORD r = GetTempPath(MAX_PATH, path);
if (r)
{
out = std::string(path);

// Replace path separators.
for (size_t i = 0; i < out.size(); ++i)
{
if ('\\' == out[i])
{
out[i] = '/';
}
}

// Create a unique name from a GUID.
GUID guid;
CoCreateGuid(&guid);
const uint8_t* guidP = reinterpret_cast<const uint8_t*>(&guid);
for (int i = 0; i < 16; ++i)
{
char buf[3] = "";
sprintf_s(buf, 3, "%02x", guidP[i]);
out += buf;
}

// Create a unique directory.
CreateDirectory(out.c_str(), NULL);
}

return out;
return otio::to_unix_separators(utf16.to_bytes(buf));
}

std::vector<std::string> glob(std::string const& path, std::string const& pattern)
Expand Down Expand Up @@ -124,48 +76,13 @@ std::vector<std::string> glob(std::string const& path, std::string const& patter

#else // _WINDOWS

std::string normalize_path(std::string const& in)
{
return in;
}

std::string absolute(std::string const& in)
{
char buf[PATH_MAX];
realpath(in.c_str(), buf);
return buf;
}

std::string create_temp_dir()
{
// Find the temporary directory.
std::string path;
char* env = nullptr;
if ((env = getenv("TEMP"))) path = env;
else if ((env = getenv("TMP"))) path = env;
else if ((env = getenv("TMPDIR"))) path = env;
else
{
for (const auto& i : { "/tmp", "/var/tmp", "/usr/tmp" })
{
struct stat buffer;
if (0 == stat(i, &buffer))
{
path = i;
break;
}
}
}

// Create a unique directory.
path = path + "/XXXXXX";
const size_t size = path.size();
std::vector<char> buf(size + 1);
memcpy(buf.data(), path.c_str(), size);
buf[size] = 0;
return mkdtemp(buf.data());
}

std::vector<std::string> glob(std::string const& path, std::string const& pattern)
{
std::vector<std::string> out;
Expand Down
6 changes: 0 additions & 6 deletions examples/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@

namespace examples {

// Normalize path (change '\' path delimiters to '/').
std::string normalize_path(std::string const&);

// Get the absolute path.
std::string absolute(std::string const&);

// Create a temporary directory.
std::string create_temp_dir();

// Get a list of files from a directory.
std::vector<std::string> glob(std::string const& path, std::string const& pattern);

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def generate_cmake_arguments(self):
'-DOTIO_CXX_INSTALL:BOOL=OFF',
'-DOTIO_SHARED_LIBS:BOOL=OFF',
'-DCMAKE_BUILD_TYPE=' + self.build_config,
'-DCMAKE_INSTALL_PREFIX=' + install_dir,
'-DOTIO_PYTHON_INSTALL_DIR=' + install_dir,
# turn off the C++ tests during a Python build
'-DBUILD_TESTING:BOOL=OFF',
Expand Down
Loading
Loading