forked from AcademySoftwareFoundation/OpenTimelineIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.cpp
More file actions
125 lines (113 loc) · 3.84 KB
/
Copy pathbundle.cpp
File metadata and controls
125 lines (113 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
// Example OTIO program that can create and extract bundles.
//
// Usage:
// * bundle (input.otio) (output.otioz)
// Create an .otioz bundle from an .otio file.
//
// * bundle (input.otio) (output.otiod)
// Create an .otiod bundle from an .otio file.
//
// * bundle (input.otioz) (output)
// Extract an .otioz bundle.
#include "util.h"
#include "opentimelineio/bundle.h"
#include "opentimelineio/fileUtils.h"
#include "opentimelineio/timeline.h"
#include <filesystem>
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)
{
// Command line arguments.
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_NS::to_unix_separators(argv[1]);
const std::string output = OTIO_NS::to_unix_separators(argv[2]);
if (ends_with(input, ".otio") && ends_with(output, ".otioz"))
{
// Create an .otioz bundle from an .otio file.
// Open timeline.
OTIO_NS::ErrorStatus error_status;
OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline> timeline(
dynamic_cast<OTIO_NS::Timeline*>(
OTIO_NS::Timeline::from_json_file(input, &error_status)));
if (!timeline || OTIO_NS::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}
// Create .otioz bundle.
OTIO_NS::bundle::WriteOptions options;
options.parent_path =
std::filesystem::u8path(input).parent_path().u8string();
if (!OTIO_NS::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.
OTIO_NS::bundle::OtiozReadOptions options;
options.extract_path = output;
OTIO_NS::ErrorStatus error_status;
auto result = OTIO_NS::bundle::from_otioz(input, options, &error_status);
if (OTIO_NS::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}
}
else if (ends_with(input, ".otio") && ends_with(output, ".otiod"))
{
// Create an .otiod bundle from an .otio file.
// Open timeline.
OTIO_NS::ErrorStatus error_status;
OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline> timeline(
dynamic_cast<OTIO_NS::Timeline*>(
OTIO_NS::Timeline::from_json_file(input, &error_status)));
if (!timeline || OTIO_NS::is_error(error_status))
{
examples::print_error(error_status);
return 1;
}
// Create .otiod bundle.
OTIO_NS::bundle::WriteOptions options;
options.parent_path =
std::filesystem::u8path(input).parent_path().u8string();
if (!OTIO_NS::bundle::to_otiod(
timeline.value,
output,
options,
&error_status))
{
examples::print_error(error_status);
return 1;
}
}
return 0;
}