11// SPDX-License-Identifier: Apache-2.0
22// Copyright Contributors to the OpenTimelineIO project
33
4- // Example OTIO script that can create and extract bundles.
4+ // Example OTIO program that can create and extract bundles.
5+ //
6+ // Usage:
7+ // * bundle (input.otio) (output.otioz)
8+ // Create an .otioz bundle from an .otio file.
9+ //
10+ // * bundle (input.otio) (output.otiod)
11+ // Create an .otiod bundle from an .otio file.
12+ //
13+ // * bundle (input.otioz) (output)
14+ // Extract an .otioz bundle.
515
616#include " util.h"
717
1121
1222#include < filesystem>
1323
14- namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
15- namespace bundle = opentimelineio::OPENTIMELINEIO_VERSION::bundle;
16-
1724bool
1825ends_with (std::string const & s, std::string const & find)
1926{
@@ -27,6 +34,7 @@ ends_with(std::string const& s, std::string const& find)
2734int
2835main (int argc, char ** argv)
2936{
37+ // Command line arguments.
3038 if (argc != 3 )
3139 {
3240 std::cout << " Usage:\n " ;
@@ -38,27 +46,29 @@ main(int argc, char** argv)
3846 << " Extract an .otioz bundle.\n " ;
3947 return 1 ;
4048 }
41- const std::string input = otio ::to_unix_separators (argv[1 ]);
42- const std::string output = otio ::to_unix_separators (argv[2 ]);
49+ const std::string input = OTIO_NS ::to_unix_separators (argv[1 ]);
50+ const std::string output = OTIO_NS ::to_unix_separators (argv[2 ]);
4351
4452 if (ends_with (input, " .otio" ) && ends_with (output, " .otioz" ))
4553 {
54+ // Create an .otioz bundle from an .otio file.
55+
4656 // Open timeline.
47- otio ::ErrorStatus error_status;
48- otio ::SerializableObject::Retainer<otio ::Timeline> timeline (
49- dynamic_cast <otio ::Timeline*>(
50- otio ::Timeline::from_json_file (input, &error_status)));
51- if (!timeline || otio ::is_error (error_status))
57+ OTIO_NS ::ErrorStatus error_status;
58+ OTIO_NS ::SerializableObject::Retainer<OTIO_NS ::Timeline> timeline (
59+ dynamic_cast <OTIO_NS ::Timeline*>(
60+ OTIO_NS ::Timeline::from_json_file (input, &error_status)));
61+ if (!timeline || OTIO_NS ::is_error (error_status))
5262 {
5363 examples::print_error (error_status);
5464 return 1 ;
5565 }
5666
5767 // Create .otioz bundle.
58- bundle::WriteOptions options;
68+ OTIO_NS:: bundle::WriteOptions options;
5969 options.parent_path =
6070 std::filesystem::u8path (input).parent_path ().u8string ();
61- if (!bundle::to_otioz (
71+ if (!OTIO_NS:: bundle::to_otioz (
6272 timeline.value ,
6373 output,
6474 options,
@@ -71,34 +81,36 @@ main(int argc, char** argv)
7181 else if (ends_with (input, " .otioz" ))
7282 {
7383 // Extract .otioz bundle.
74- bundle::OtiozReadOptions options;
84+ OTIO_NS:: bundle::OtiozReadOptions options;
7585 options.extract_path = output;
76- otio ::ErrorStatus error_status;
77- auto result = bundle::from_otioz (input, options, &error_status);
78- if (otio ::is_error (error_status))
86+ OTIO_NS ::ErrorStatus error_status;
87+ auto result = OTIO_NS:: bundle::from_otioz (input, options, &error_status);
88+ if (OTIO_NS ::is_error (error_status))
7989 {
8090 examples::print_error (error_status);
8191 return 1 ;
8292 }
8393 }
8494 else if (ends_with (input, " .otio" ) && ends_with (output, " .otiod" ))
8595 {
96+ // Create an .otiod bundle from an .otio file.
97+
8698 // Open timeline.
87- otio ::ErrorStatus error_status;
88- otio ::SerializableObject::Retainer<otio ::Timeline> timeline (
89- dynamic_cast <otio ::Timeline*>(
90- otio ::Timeline::from_json_file (input, &error_status)));
91- if (!timeline || otio ::is_error (error_status))
99+ OTIO_NS ::ErrorStatus error_status;
100+ OTIO_NS ::SerializableObject::Retainer<OTIO_NS ::Timeline> timeline (
101+ dynamic_cast <OTIO_NS ::Timeline*>(
102+ OTIO_NS ::Timeline::from_json_file (input, &error_status)));
103+ if (!timeline || OTIO_NS ::is_error (error_status))
92104 {
93105 examples::print_error (error_status);
94106 return 1 ;
95107 }
96108
97109 // Create .otiod bundle.
98- bundle::WriteOptions options;
110+ OTIO_NS:: bundle::WriteOptions options;
99111 options.parent_path =
100112 std::filesystem::u8path (input).parent_path ().u8string ();
101- if (!bundle::to_otiod (
113+ if (!OTIO_NS:: bundle::to_otiod (
102114 timeline.value ,
103115 output,
104116 options,
0 commit comments