Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ profile
*.moved-aside
DerivedData
.idea/
.build
Release
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
swift build

release: clean
swift build --configuration=release --build-path ./Release

clean:
rm -rf ./.build
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SPMAssetExporter",
products: [
.library(
name: "SPMAssetExporter",
targets: ["SPMAssetExporter"]
),
],
dependencies: [],
targets: [
.target(
name: "SPMAssetExporter",
dependencies: []
),
]
)
79 changes: 58 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPMAssetExporter

SDAVAssetExportSession
======================

Expand All @@ -8,48 +10,83 @@ You want the ease of use of `AVAssetExportSession` but default provided presets

Usage Example
-------------

For ObjC:
``` objective-c
SDAVAssetExportSession *encoder = [SDAVAssetExportSession.alloc initWithAsset:anAsset];
encoder.outputFileType = AVFileTypeMPEG4;
encoder.outputURL = outputFileURL;
encoder.videoSettings = @
{
{
AVVideoCodecKey: AVVideoCodecH264,
AVVideoWidthKey: @1920,
AVVideoHeightKey: @1080,
AVVideoCompressionPropertiesKey: @
{
{
AVVideoAverageBitRateKey: @6000000,
AVVideoProfileLevelKey: AVVideoProfileLevelH264High40,
},
};
},
};
encoder.audioSettings = @
{
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey: @2,
AVSampleRateKey: @44100,
AVEncoderBitRateKey: @128000,
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey: @2,
AVSampleRateKey: @44100,
AVEncoderBitRateKey: @128000,
};

[encoder exportAsynchronouslyWithCompletionHandler:^
{
if (encoder.status == AVAssetExportSessionStatusCompleted)
{
NSLog(@"Video export succeeded");
}
else if (encoder.status == AVAssetExportSessionStatusCancelled)
{
NSLog(@"Video export cancelled");
}
else
{
NSLog(@"Video export failed with error: %@ (%d)", encoder.error.localizedDescription, encoder.error.code);
}
if (encoder.status == AVAssetExportSessionStatusCompleted)
{
NSLog(@"Video export succeeded");
}
else if (encoder.status == AVAssetExportSessionStatusCancelled)
{
NSLog(@"Video export cancelled");
}
else
{
NSLog(@"Video export failed with error: %@ (%d)", encoder.error.localizedDescription, encoder.error.code);
}
}];

```

And for Swift:

* add the package to your Xcode project (https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)
* import package
* use it in swift code like

```swift
import SPMAssetExporter

// ...

let exporter = SDAVAssetExportSession(asset: asset)!
exporter.outputFileType = processingParameters.outputFileType.rawValue
exporter.outputURL = processingParameters.outputUrl
exporter.videoSettings = [
AVVideoCodecKey: AVVideoCodecType.h264,
AVVideoWidthKey: targetSize.width,
AVVideoHeightKey: targetSize.height,
AVVideoCompressionPropertiesKey: [AVVideoAverageBitRateKey: 1024_000,AVVideoProfileLevelKey: AVVideoProfileLevelH264High40]
]
exporter.audioSettings = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVNumberOfChannelsKey: 1,
AVSampleRateKey: 44100,
AVEncoderBitRateKey: 96_000
]
exporter.videoComposition = videoComposition

exporter.exportAsynchronously(completionHandler: {
switch encoder.status {
// do your work here
}
})
```

Licenses
--------

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// file that was distributed with this source code.
//


#import "SDAVAssetExportSession.h"

@interface SDAVAssetExportSession ()
Expand Down Expand Up @@ -168,7 +167,7 @@ - (void)exportAsynchronouslyWithCompletionHandler:(void (^)(void))handler
[self.writer addInput:self.audioInput];
}
}

[self.writer startWriting];
[self.reader startReading];
[self.writer startSessionAtSourceTime:self.timeRange.start];
Expand Down Expand Up @@ -196,7 +195,7 @@ - (void)exportAsynchronouslyWithCompletionHandler:(void (^)(void))handler
else {
videoCompleted = YES;
}

if (!self.audioOutput) {
audioCompleted = YES;
} else {
Expand Down Expand Up @@ -232,7 +231,7 @@ - (BOOL)encodeReadySamplesFromOutput:(AVAssetReaderOutput *)output toInput:(AVAs
handled = YES;
error = YES;
}

if (!handled && self.videoOutput == output)
{
// update the video progress
Expand Down