Skip to content

Commit

Permalink
Refactored SCAssetExportSession so it uses the SCAudioConfiguration a…
Browse files Browse the repository at this point in the history
…nd SCVideoConfiguration

the same way the SCRecorder does.
Fixed a possible "deadlock" when a buffer failed to be appended.
  • Loading branch information
rFlex committed Dec 5, 2014
1 parent cc4661a commit 58c389f
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 214 deletions.
7 changes: 4 additions & 3 deletions Examples/Sources/SCVideoPlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ - (void)saveToCameraRoll {
[self.recordSession mergeRecordSegmentsUsingPreset:AVAssetExportPresetHighestQuality completionHandler:completionHandler];
} else {
SCAssetExportSession *exportSession = [[SCAssetExportSession alloc] initWithAsset:self.recordSession.assetRepresentingRecordSegments];
exportSession.filterGroup = currentFilter;
exportSession.sessionPreset = SCAssetExportSessionPresetHighestQuality;
exportSession.videoConfiguration.filterGroup = currentFilter;
exportSession.videoConfiguration.preset = SCPresetHighestQuality;
exportSession.audioConfiguration.preset = SCPresetHighestQuality;
exportSession.videoConfiguration.maxFrameRate = 35;
exportSession.outputUrl = self.recordSession.outputUrl;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.keepVideoSize = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
completionHandler(exportSession.outputUrl, exportSession.error);
}];
Expand Down
2 changes: 1 addition & 1 deletion Library/SCRecorder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
DC551C4D17ADD66000E37F8F /* Sources */ = {
isa = PBXGroup;
children = (
DCA1639F1A2028DC00505966 /* Configuration */,
DCAA1F2219C90021002065CA /* Recorder */,
DCAA1F2119C90018002065CA /* Focus */,
DCAA1F2019C8FED5002065CA /* FilterDisplayers */,
Expand Down Expand Up @@ -331,7 +332,6 @@
DCAA1F2219C90021002065CA /* Recorder */ = {
isa = PBXGroup;
children = (
DCA1639F1A2028DC00505966 /* Configuration */,
DC50285218E4F23F004E833F /* SCRecordSession.h */,
DC50285318E4F23F004E833F /* SCRecordSession.m */,
DC50285518E4FA5E004E833F /* SCRecorder.h */,
Expand Down
71 changes: 20 additions & 51 deletions Library/Sources/SCAssetExportSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,43 @@
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "SCFilterGroup.h"

extern NSString *SCAssetExportSessionPresetHighestQuality;
extern NSString *SCAssetExportSessionPresetMediumQuality;
extern NSString *SCAssetExportSessionPresetLowQuality;
#import "SCVideoConfiguration.h"
#import "SCAudioConfiguration.h"

@interface SCAssetExportSession : NSObject

// The input asset to use
/**
The input asset to use
*/
@property (strong, nonatomic) AVAsset *inputAsset;

// The outputUrl to which the asset will be exported
/**
The outputUrl to which the asset will be exported
*/
@property (strong, nonatomic) NSURL *outputUrl;

// The type of file to be written by the session
/**
The type of file to be written by the export session
*/
@property (strong, nonatomic) NSString *outputFileType;

// The settings applied to the video's AVAssetWriterInput
// If nil, this will be automatically set depending on the sessionPreset
@property (strong, nonatomic) NSDictionary *videoSettings;

/**
If not invalid, this will limit the number of frame duration. Video frames
may be skipped to ensure it doesn't exceed this value.
If true, the export session will use the GPU for rendering the filters
*/
@property (assign, nonatomic) CMTime maxVideoFrameDuration;

// The settings applied to the audio's AVAssetWriterInput
// If nil, this will be automatically set depending on the sessionPreset
@property (strong, nonatomic) NSDictionary *audioSettings;

// The filterGroup that hold a list of Core Image filters.
// Can be nil
@property (strong, nonatomic) SCFilterGroup *filterGroup;

// If videoSettings or/and audioSettings is nil, this will be a hint of the settings
// to set. Setting this value is not mandatory if both videoSettings and audioSettings are set.
// Value can be SCAssetExportSessionPresetHighest, SCAssetExportSessionPresetMedium or SCAssetExportSessionPresetLow;
@property (copy, nonatomic) NSString *sessionPreset;

// If videoSettings are not set, the video size will be preserved no matter which
// session preset was set.
@property (assign, nonatomic) BOOL keepVideoSize;

// If true, the videoTransform property will be ignored and the videoTransform
// will be the same as the input asset
@property (assign, nonatomic) BOOL keepVideoTransform;

// If true, the export session will use the GPU for rendering the filters.
@property (assign, nonatomic) BOOL useGPUForRenderingFilters;

// If keepVideoTransform is not true, this will override the transform to use for the video
@property (assign, nonatomic) CGAffineTransform videoTransform;

// If an error occured during the export, this will contain that error
@property (readonly, nonatomic) NSError *error;

/**
Whether it should ignore the audio in the inputAsset.
If true, the output asset will not contains a audio track.
Access the configuration for the video.
*/
@property (assign, nonatomic) BOOL ignoreAudio;
@property (readonly, nonatomic) SCVideoConfiguration *videoConfiguration;

/**
Whether it should ignore the video in the inputAsset.
If true, the output asset will not contains a video track.
Access the configuration for the audio.
*/
@property (assign, nonatomic) BOOL ignoreVideo;
@property (readonly, nonatomic) SCAudioConfiguration *audioConfiguration;

// If an error occured during the export, this will contain that error
@property (readonly, nonatomic) NSError *error;

- (id)init;

Expand All @@ -100,8 +69,8 @@ extern NSString *SCAssetExportSessionPresetLowQuality;
@property (readonly, nonatomic) AVAssetWriterInput *videoInput;

- (void)markInputComplete:(AVAssetWriterInput *)input error:(NSError *)error;
- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer;
- (void)processPixelBuffer:(CVPixelBufferRef)pixelBuffer presentationTime:(CMTime)presentationTime;
- (BOOL)processSampleBuffer:(CMSampleBufferRef)sampleBuffer;
- (BOOL)processPixelBuffer:(CVPixelBufferRef)pixelBuffer presentationTime:(CMTime)presentationTime;
- (void)beginReadWriteOnInput:(AVAssetWriterInput *)input fromOutput:(AVAssetReaderOutput *)output;
- (BOOL)needsInputPixelBufferAdaptor;

Expand Down
Loading

0 comments on commit 58c389f

Please sign in to comment.