Skip to content

Commit

Permalink
MXF metadata handling is now done in gyroflow_core
Browse files Browse the repository at this point in the history
  • Loading branch information
latenitefilms committed Jul 13, 2023
1 parent 48420b8 commit 12b31f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Source/Frameworks/gyroflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ argh = "*"
serde = "1.0"
serde_json = "1.0"
libc = "0.2"
gyroflow-core = { git = "https://github.com/gyroflow/gyroflow.git", default-features = false, rev = "64178f8", features = ["bundle-lens-profiles"] }
gyroflow-core = { git = "https://github.com/gyroflow/gyroflow.git", default-features = false, rev = "b8d6d96", features = ["bundle-lens-profiles"] }
log = "0.4.17"
oslog = "0.2.0"
lazy_static = "1.4.0"
Expand Down
10 changes: 5 additions & 5 deletions Source/Frameworks/gyroflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ pub extern "C" fn doesGyroflowProjectContainStabilisationData(
//---------------------------------------------------------
// Import the `gyroflow_project_data_string`:
//---------------------------------------------------------
let blocking = true;
let path = Some(std::path::PathBuf::from(&*gyroflow_project_data_string));
let blocking = true;
let cancel_flag = Arc::new(AtomicBool::new(false));
let mut is_preset = false;
match stab.import_gyroflow_data(
gyroflow_project_data_string.as_bytes(),
blocking,
path,
None,
|_|(),
cancel_flag,
&mut is_preset
Expand Down Expand Up @@ -227,11 +226,12 @@ pub extern "C" fn importMediaFile(
}

//---------------------------------------------------------
// Prepare metadata if file has .mxf or .braw extension:
// If it's a BRAW file, then we'll get metadata from
// Objective-C land:
//---------------------------------------------------------
let metadata;
if width > 0 && height > 0 {
log::info!("[Gyroflow Toolbox Rust] It's a MXF or BRAW file!");
//log::info!("[Gyroflow Toolbox Rust] It's a MXF or BRAW file!");
metadata = Some(VideoMetadata {
duration_s: duration_s,
fps: fps,
Expand Down
4 changes: 4 additions & 0 deletions Source/Gyroflow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
22F73D8C2A604A2B00A6F326 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22F73D8B2A604A2B00A6F326 /* MetalKit.framework */; };
22F73D8E2A604A3100A6F326 /* MetalPerformanceShaders.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22F73D8D2A604A3100A6F326 /* MetalPerformanceShaders.framework */; };
22F73D912A604BB100A6F326 /* TileableRemoteBRAW.metal in Sources */ = {isa = PBXBuildFile; fileRef = 22F73D8F2A604BB100A6F326 /* TileableRemoteBRAW.metal */; };
22F73D942A606DF400A6F326 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22F73D932A606DF400A6F326 /* AVFoundation.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -156,6 +157,7 @@
22F73D8D2A604A3100A6F326 /* MetalPerformanceShaders.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalPerformanceShaders.framework; path = System/Library/Frameworks/MetalPerformanceShaders.framework; sourceTree = SDKROOT; };
22F73D8F2A604BB100A6F326 /* TileableRemoteBRAW.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = TileableRemoteBRAW.metal; sourceTree = "<group>"; };
22F73D902A604BB100A6F326 /* TileableRemoteBRAWShaderTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileableRemoteBRAWShaderTypes.h; sourceTree = "<group>"; };
22F73D932A606DF400A6F326 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -173,6 +175,7 @@
files = (
22F73D8E2A604A3100A6F326 /* MetalPerformanceShaders.framework in Frameworks */,
22F73D8C2A604A2B00A6F326 /* MetalKit.framework in Frameworks */,
22F73D942A606DF400A6F326 /* AVFoundation.framework in Frameworks */,
22F73D7A2A6038E300A6F326 /* BlackmagicRawAPI.framework in Frameworks */,
2239AB212943F8F600028B77 /* Accelerate.framework in Frameworks */,
2239AB232943F8F600028B77 /* PluginManager.framework in Frameworks */,
Expand Down Expand Up @@ -209,6 +212,7 @@
2239AB0F2943F8F600028B77 /* Frameworks */ = {
isa = PBXGroup;
children = (
22F73D932A606DF400A6F326 /* AVFoundation.framework */,
22F73D8D2A604A3100A6F326 /* MetalPerformanceShaders.framework */,
22F73D8B2A604A2B00A6F326 /* MetalKit.framework */,
22F73D892A604A2500A6F326 /* Metal.framework */,
Expand Down
77 changes: 7 additions & 70 deletions Source/Gyroflow/Plugin/GyroflowPlugIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ - (void)importDroppedMedia:(NSURL*)url {

NSLog(@"[Gyroflow Toolbox Renderer] importDroppedMedia URL: %@", [url path]);

NSString *extension = [url pathExtension];
NSString *extension = [[url pathExtension] lowercaseString];
NSFileManager *fileManager = [NSFileManager defaultManager];

if ([extension isEqualToString:@"gyroflow"]) {
Expand Down Expand Up @@ -2701,39 +2701,12 @@ - (void)readLastProjectFromGyroflowPreferencesFile {
//
//---------------------------------------------------------

//---------------------------------------------------------
// Get MXF Metadata With Path:
//---------------------------------------------------------
- (void)getMXFMetadataWithPath:(NSString *)filePath {
NSURL *fileURL = [NSURL fileURLWithPath:filePath];

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];

//Duration
CMTime duration = asset.duration;
float durationInSeconds = CMTimeGetSeconds(duration);
NSLog(@"Duration: %f seconds", durationInSeconds);

//Frames per second
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([videoTracks count] > 0) {
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
float fps = videoTrack.nominalFrameRate;
NSLog(@"FPS: %f", fps);

//Width and Height
CGSize videoSize = videoTrack.naturalSize;
NSLog(@"Width: %f", videoSize.width);
NSLog(@"Height: %f", videoSize.height);
}
}

//---------------------------------------------------------
// Import Gyroflow Project with Optional URL:
//---------------------------------------------------------
- (void)importMediaWithOptionalURL:(NSURL*)optionalURL {

//NSLog(@"[Gyroflow Toolbox Renderer] Import Media File!");
NSLog(@"[Gyroflow Toolbox Renderer] Import Media File!");

NSURL *url = nil;
BOOL isAccessible = [optionalURL startAccessingSecurityScopedResource];
Expand Down Expand Up @@ -2790,16 +2763,17 @@ - (void)importMediaWithOptionalURL:(NSURL*)optionalURL {
NSLog(@"[Gyroflow Toolbox Renderer] Import Media File Path: %@", path);

//---------------------------------------------------------
// If the media is a BRAW or MXF, then we need to pass
// in some metadata.
// If the media is a BRAW file then we need to pass
// in some metadata to Rust-land:
//---------------------------------------------------------
uint32_t width = 0;
uint32_t height = 0;
double duration_s = 0;
double fps = 0;
int32_t rotation = 0;

NSString *extension = [url pathExtension];
NSString *extension = [[url pathExtension] lowercaseString];

if ([extension isEqualToString:@"braw"]) {
//---------------------------------------------------------
// It's a BRAW file:
Expand All @@ -2816,43 +2790,6 @@ - (void)importMediaWithOptionalURL:(NSURL*)optionalURL {
duration_s = [params.frameCount doubleValue] / [params.frameRate doubleValue];
fps = [params.frameRate doubleValue];
}
} else if ([extension isEqualToString:@"mxf"]) {
//---------------------------------------------------------
// It's a MXF file:
//---------------------------------------------------------
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];

if (asset == nil) {
NSLog(@"[Gyroflow Toolbox Renderer] MXF Metadata Error - AVURLAsset is nil.");
} else {
//---------------------------------------------------------
// Get Duration:
//---------------------------------------------------------
CMTime duration = asset.duration;
duration_s = CMTimeGetSeconds(duration);

//---------------------------------------------------------
// Get Video Track Metadata:
//---------------------------------------------------------
NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([videoTracks count] > 0) {
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];

//---------------------------------------------------------
// Get Frames per Second:
//---------------------------------------------------------
fps = videoTrack.nominalFrameRate;

//---------------------------------------------------------
// Get Width & Height:
//---------------------------------------------------------
CGSize videoSize = videoTrack.naturalSize;
width = videoSize.width;
height = videoSize.height;
}

NSLog(@"[Gyroflow Toolbox Renderer] MXF Metadata");
}
}

NSLog(@"[Gyroflow Toolbox Renderer] width: %u", width);
Expand All @@ -2871,7 +2808,7 @@ - (void)importMediaWithOptionalURL:(NSURL*)optionalURL {
);

NSString *resultString = [NSString stringWithUTF8String: importResult];
//NSLog(@"[Gyroflow Toolbox Renderer] resultString: %@", resultString);
NSLog(@"[Gyroflow Toolbox Renderer] resultString: %@", resultString);

if (resultString == nil || [resultString isEqualToString:@"FAIL"]) {
[self showAlertWithMessage:@"An error has occurred" info:@"Failed to generate a Gyroflow Project from the Media File."];
Expand Down

0 comments on commit 12b31f4

Please sign in to comment.