-
Notifications
You must be signed in to change notification settings - Fork 24
Add otiotool support #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add otiotool support #137
Changes from 7 commits
fd6236b
3dede6f
5362786
190f826
0855ffe
ba164c2
eefd88b
60601ea
d48edc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Tools | ||
| #include "tools.h" | ||
|
|
||
| #include "app.h" | ||
|
|
||
| #include <map> | ||
| #include <filesystem> | ||
| #include <cstdio> | ||
|
|
||
| std::string run_subprocess(const std::string cmd, int& return_val) | ||
| { | ||
| #ifdef _WIN32 | ||
| auto pipe = _popen(cmd.c_str(), "r"); | ||
| #else | ||
| auto pipe = popen(cmd.c_str(), "r"); | ||
| #endif | ||
|
|
||
| if (pipe == nullptr) { | ||
| std::cout << "Failed to open pipe" << std::endl; | ||
| return std::string(); | ||
| } | ||
|
|
||
| char buffer[128]; | ||
ThomasWilshaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::string result; | ||
| while (fgets(buffer, sizeof buffer, pipe) != NULL){ | ||
| result += buffer; | ||
| } | ||
|
|
||
| #ifdef _WIN32 | ||
| return_val = _pclose(pipe); | ||
| #else | ||
| return_val = pclose(pipe); | ||
| #endif | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| bool otiotool_found() | ||
| { | ||
| int result; | ||
|
|
||
| run_subprocess("otiotool -h", result); | ||
|
|
||
| return !result; | ||
| } | ||
|
|
||
| bool run_otiotool_command(std::string options, bool debug = false) | ||
| { | ||
| // Write the current root to a temp json file | ||
| std::filesystem::path file = std::filesystem::temp_directory_path(); | ||
| file.replace_filename(std::tmpnam(nullptr)); | ||
| file.replace_extension("otio"); | ||
| if (debug) { | ||
| std::cout << file << std::endl; | ||
| } | ||
| GetActiveRoot()->to_json_file(file.generic_string()); | ||
|
|
||
| // Build command | ||
| std::string command = "otiotool --input " + file.generic_string() + " " + options + " --output -"; | ||
|
||
| if (debug) { | ||
| std::cout << command << std::endl; | ||
| } | ||
|
|
||
| // Run subproces | ||
| int return_val = 0; | ||
| std::string result = run_subprocess(command, return_val); | ||
|
|
||
| // Load new otio file | ||
| if (!result.empty() && return_val == 0) { | ||
| LoadString(result); | ||
| } else { | ||
| ErrorMessage("Error trying to redact file, see console"); | ||
| return false; | ||
| } | ||
|
|
||
| // Clean up temp file | ||
| std::remove(file.generic_string().c_str()); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool Redact() { | ||
| return run_otiotool_command("--redact"); | ||
| } | ||
|
|
||
| bool VideoOnly() { | ||
| return run_otiotool_command("--video-only"); | ||
| } | ||
|
|
||
| bool AudioOnly() { | ||
| return run_otiotool_command("--audio-only"); | ||
| } | ||
|
|
||
| bool FlattenAllTracks() { | ||
| return run_otiotool_command("--flatten all"); | ||
| } | ||
|
|
||
| bool FlattenVideoTracks() { | ||
| return run_otiotool_command("--flatten video"); | ||
|
||
| } | ||
|
|
||
| bool FlattenAudioTracks() { | ||
| return run_otiotool_command("--flatten audio"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Tools | ||
|
|
||
|
|
||
| bool otiotool_found(); | ||
|
|
||
| // Remove all metadata, names, or other identifying information from this | ||
| // timeline. Only the structure, schema and timing will remain. | ||
| bool Redact(); | ||
|
|
||
| // Output only video tracks | ||
| bool VideoOnly(); | ||
|
|
||
| // Output only audio tracks | ||
| bool AudioOnly(); | ||
|
|
||
| // Flatten all tracks | ||
| bool FlattenAllTracks(); | ||
|
|
||
| // Flatten vieo tracks | ||
| bool FlattenVideoTracks(); | ||
|
|
||
| // Flatten audio tracks | ||
| bool FlattenAudioTracks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to set
return_valin this early exit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks that is a good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
1a suitable return value here or would-1be better to indicate it isn't returning the value from the subprocess but a prior error?