Skip to content

Commit 4294de6

Browse files
authored
Merge pull request #24 from Synopsis/development
Beta 3
2 parents b4bca6c + 310c10f commit 4294de6

File tree

9 files changed

+205
-71
lines changed

9 files changed

+205
-71
lines changed

OpenTimelineIO-Sample/OpenTimelineIO-Reader.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
179179
CODE_SIGN_ENTITLEMENTS = "OpenTimelineIO-Reader/OpenTimelineIO_Reader.entitlements";
180180
CODE_SIGN_STYLE = Automatic;
181-
CURRENT_PROJECT_VERSION = 2;
181+
CURRENT_PROJECT_VERSION = 3;
182182
DEVELOPMENT_ASSET_PATHS = "\"OpenTimelineIO-Reader/Preview Content\"";
183183
DEVELOPMENT_TEAM = SHG3AW6YV7;
184184
ENABLE_HARDENED_RUNTIME = YES;
@@ -201,7 +201,7 @@
201201
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
202202
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
203203
MACOSX_DEPLOYMENT_TARGET = 13.5;
204-
MARKETING_VERSION = "1.0 Beta 2";
204+
MARKETING_VERSION = "1.0 Beta 3";
205205
PRODUCT_BUNDLE_IDENTIFIER = "ai.ozu.OpenTimelineIO-Reader";
206206
PRODUCT_NAME = "$(TARGET_NAME)";
207207
SDKROOT = auto;
@@ -220,7 +220,7 @@
220220
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
221221
CODE_SIGN_ENTITLEMENTS = "OpenTimelineIO-Reader/OpenTimelineIO_Reader.entitlements";
222222
CODE_SIGN_STYLE = Automatic;
223-
CURRENT_PROJECT_VERSION = 2;
223+
CURRENT_PROJECT_VERSION = 3;
224224
DEVELOPMENT_ASSET_PATHS = "\"OpenTimelineIO-Reader/Preview Content\"";
225225
DEVELOPMENT_TEAM = SHG3AW6YV7;
226226
ENABLE_HARDENED_RUNTIME = YES;
@@ -243,7 +243,7 @@
243243
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
244244
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
245245
MACOSX_DEPLOYMENT_TARGET = 13.5;
246-
MARKETING_VERSION = "1.0 Beta 2";
246+
MARKETING_VERSION = "1.0 Beta 3";
247247
PRODUCT_BUNDLE_IDENTIFIER = "ai.ozu.OpenTimelineIO-Reader";
248248
PRODUCT_NAME = "$(TARGET_NAME)";
249249
SDKROOT = auto;
9.7 KB
Binary file not shown.
Binary file not shown.

OpenTimelineIO-Sample/OpenTimelineIO-Reader/OpenTimelineIO_ReaderDocument.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class OpenTimelineIO_ReaderDocument: FileDocument, ObservableObject
8888
queue: .main,
8989
using: { [weak self] time in
9090

91-
print("update current time \(time)")
9291
self?.currentTime = time.toOTIORationalTime()
9392

9493
})

OpenTimelineIO-Sample/OpenTimelineIO-Reader/Views/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct ContentView: View
140140
.lineLimit(1)
141141
.font(.system(size: 10))
142142

143-
Slider(value: $secondsToPixels, in: 10...1000)
143+
Slider(value: $secondsToPixels, in: 1...1000)
144144
.controlSize(.mini)
145145
.frame(width: 200)
146146
}

OpenTimelineIO-Sample/OpenTimelineIO-Reader/Views/TimelineView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ struct TimelineView : View {
6363
.frame(height: 40)
6464
.offset(x:100)
6565
//
66-
// Divider()
6766

6867
ForEach(0..<videoTracks.count, id: \.self) { index in
6968

70-
let track = videoTracks[index]
69+
// Reverse
70+
let track = videoTracks[(videoTracks.count - 1 ) - index]
7171

7272
TrackView(track: track,
7373
backgroundColor: Color("VideoTrackBaseColor"),
7474
secondsToPixels: self.$secondsToPixels,
7575
selectedItem: self.$selectedItem )
7676
}
7777

78+
Divider()
79+
7880
ForEach(0..<audioTracks.count, id: \.self) { index in
7981

8082
let track = audioTracks[index]

Sources/OpenTimelineIO-AVFoundation/OpenTimelineIO-Extensions/Clip.swift

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,29 @@ import TimecodeKit
1313
extension Clip
1414
{
1515
// see https://opentimelineio.readthedocs.io/en/latest/tutorials/time-ranges.html
16-
func toAVAssetAndMapping(baseURL:URL? = nil, useTimecode:Bool = true, rescaleToAsset:Bool = true) throws -> (asset:AVAsset, timeMaping:CMTimeMapping)?
16+
func toAVAssetAndMapping(baseURL:URL? = nil, trackType:AVMediaType, useTimecode:Bool = true, rescaleToAsset:Bool = true) throws -> (asset:AVAsset, timeMaping:CMTimeMapping)?
1717
{
18-
guard
19-
let externalReference = self.mediaReference as? ExternalReference,
20-
let asset = externalReference.toAVAsset(baseURL: baseURL)
21-
// let parent = self.parent as? Item
18+
19+
let asset:AVURLAsset
20+
21+
if let externalReference = self.mediaReference as? ExternalReference,
22+
let maybeAsset = externalReference.toAVAsset(baseURL: baseURL)
23+
{
24+
25+
guard !maybeAsset.tracks(withMediaType: trackType).isEmpty else { return nil }
26+
27+
asset = maybeAsset
28+
}
2229
else
2330
{
24-
return nil
31+
//see AWS Picchu Edit - Premiere cant import either?
32+
//we have a generator or just a dead reference?
33+
let missingMediaURL = Bundle.main.url(forResource: "MediaNotFound", withExtension: "mp4")!
34+
let missingAsset = AVURLAsset(url: missingMediaURL)
35+
36+
guard !missingAsset.tracks(withMediaType: trackType).isEmpty else { return nil }
37+
38+
asset = missingAsset
2539
}
2640

2741
var timeRangeInAsset = try self.trimmedRange()
@@ -67,6 +81,22 @@ extension Clip
6781
// let timeRangeInParentTrackNoTC = timeRangeInParentTrack.startTime - startTimeCode.cmTimeValue.toOTIORationalTime()
6882
// timeRangeInParentTrack = TimeRange(startTime: timeRangeInParentTrackNoTC, duration: timeRangeInParentTrack.duration)
6983
}
84+
85+
// We might find ourselves with a situation where the timecode of the source media in the timeline existed, but we are working with proxies without TC
86+
// This means we need to deduce if the time in OTIO differs from the assets and adjust accordingly
87+
else if let firstVideoTrackStart = asset.tracks(withMediaType: .video).first
88+
{
89+
let assetAvailableTime = try self.availableRange()
90+
91+
// If our start times differ...
92+
if firstVideoTrackStart.timeRange.start.toOTIORationalTime() != assetAvailableTime.startTime
93+
{
94+
let timeDifference = assetAvailableTime.startTime - firstVideoTrackStart.timeRange.start.toOTIORationalTime()
95+
96+
let assetStartTimeNoTC = timeRangeInAsset.startTime - timeDifference
97+
timeRangeInAsset = TimeRange(startTime: assetStartTimeNoTC, duration: timeRangeInAsset.duration)
98+
}
99+
}
70100
}
71101
catch Timecode.MediaParseError.missingOrNonStandardFrameRate
72102
{

Sources/OpenTimelineIO-AVFoundation/OpenTimelineIO-Extensions/ExternalReference.swift

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension ExternalReference
5353
if FileManager.default.fileExists(atPath: path)
5454
{
5555
let sourceURL = URL(filePath: path)
56-
return AVURLAsset(url: sourceURL)
56+
return self.tryLoadAssetAtResolvedURL(url: sourceURL)
5757
}
5858
else if let baseURL = baseURL
5959
{
@@ -62,7 +62,7 @@ extension ExternalReference
6262

6363
if FileManager.default.fileExists(atPath: sourceURL.path(percentEncoded: false))
6464
{
65-
return AVURLAsset(url: sourceURL)
65+
return self.tryLoadAssetAtResolvedURL(url: sourceURL)
6666
}
6767

6868
// we cant have a base url with a relative path to root dir...
@@ -73,12 +73,56 @@ extension ExternalReference
7373
var sourceURL = baseURL.appending(path: pathWithoutRoot )
7474
if FileManager.default.fileExists(atPath: sourceURL.path(percentEncoded: false))
7575
{
76-
return AVURLAsset(url: sourceURL)
76+
return self.tryLoadAssetAtResolvedURL(url: sourceURL)
7777
}
7878
}
7979
}
8080

81-
return nil
81+
let missingMediaURL = Bundle.main.url(forResource: "MediaNotFound", withExtension: "mp4")!
82+
83+
return AVURLAsset(url: missingMediaURL)
84+
}
85+
86+
fileprivate func tryLoadAssetAtResolvedURL(url:URL) -> AVURLAsset
87+
{
88+
// do some very simple semantics to see if theres a chance we can load the asset
89+
90+
let supported:Bool
91+
92+
switch url.pathExtension
93+
{
94+
case "mp4":
95+
supported = true
96+
case "mov":
97+
supported = true
98+
case "m4v":
99+
supported = true
100+
101+
102+
case "m4a":
103+
supported = true
104+
case "mp3":
105+
supported = true
106+
case "aiff":
107+
supported = true
108+
case "wav":
109+
supported = true
110+
111+
112+
default:
113+
supported = false
114+
}
115+
116+
if supported
117+
{
118+
return AVURLAsset(url: url)
119+
}
120+
121+
let notSupportedMedia = Bundle.main.url(forResource: "MediaNotSupported", withExtension: "mp4")!
122+
123+
return AVURLAsset(url: notSupportedMedia)
124+
82125
}
126+
83127
}
84128

0 commit comments

Comments
 (0)