Skip to content

Commit

Permalink
Merge pull request BradLarson#1886 from RedQueenCoder/SimpleVideoFilt…
Browse files Browse the repository at this point in the history
…erPullRequest

Sample project showing how to save filtered video on the Mac
  • Loading branch information
BradLarson committed Jan 8, 2015
2 parents 37d5ac6 + c9d4f53 commit eecb459
Show file tree
Hide file tree
Showing 12 changed files with 1,485 additions and 0 deletions.

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions examples/Mac/SimpleVideoFilter/SimpleVideoFilter/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <Cocoa/Cocoa.h>
#import "SLSSimpleVideoFilterWindowController.h"

@interface AppDelegate : NSObject <NSApplicationDelegate>
{
SLSSimpleVideoFilterWindowController *simpleVideoFilterWindowController;
}

@end

21 changes: 21 additions & 0 deletions examples/Mac/SimpleVideoFilter/SimpleVideoFilter/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "AppDelegate.h"
#import <GPUImage/GPUImage.h>

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
simpleVideoFilterWindowController = [[SLSSimpleVideoFilterWindowController alloc] initWithWindowNibName:@"SLSSimpleVideoFilterWindowController"];
[simpleVideoFilterWindowController showWindow:self];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}

@end

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
34 changes: 34 additions & 0 deletions examples/Mac/SimpleVideoFilter/SimpleVideoFilter/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.redqueencoder.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Red Queen Coder, LLC. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Cocoa/Cocoa.h>
#import <GPUImage/GPUImage.h>

@interface SLSSimpleVideoFilterWindowController : NSWindowController
{
GPUImageAVCamera *videoCamera;
GPUImageOutput<GPUImageInput> *filter;
GPUImageMovieWriter *movieWriter;
}

@property (weak) IBOutlet GPUImageView *videoView;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#import "SLSSimpleVideoFilterWindowController.h"

@interface SLSSimpleVideoFilterWindowController ()

@end

@implementation SLSSimpleVideoFilterWindowController


- (void)windowDidLoad {
[super windowDidLoad];

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.

// Instantiate video camera
videoCamera = [[GPUImageAVCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraDevice:nil];
videoCamera.runBenchmark = YES;

// Create filter and add it to target
filter = [[GPUImageSepiaFilter alloc] init];
[videoCamera addTarget:filter];

// Save video to desktop
NSError *error = nil;

NSURL *pathToDesktop = [[NSFileManager defaultManager] URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
NSURL *pathToMovieFile = [pathToDesktop URLByAppendingPathComponent:@"movie.mp4"];
NSString *filePathString = [pathToMovieFile absoluteString];
NSString *filePathSubstring = [filePathString substringFromIndex:7];
unlink([filePathSubstring UTF8String]);

// Instantiate movie writer and add targets
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:pathToMovieFile size:CGSizeMake(640.0, 480.0)];
movieWriter.encodingLiveVideo = YES;

self.videoView.fillMode = kGPUImageFillModePreserveAspectRatio;
[filter addTarget:movieWriter];
[filter addTarget:self.videoView];

// Start capturing
[videoCamera startCameraCapture];

double delayToStartRecording = 0.5;
dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Start recording");

videoCamera.audioEncodingTarget = movieWriter;
[movieWriter startRecording];

double delayInSeconds = 10.0;
dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){

[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
NSLog(@"Movie completed");

});
});

}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SLSSimpleVideoFilterWindowController">
<connections>
<outlet property="videoView" destination="dd0-IN-e64" id="tXV-v8-36j"/>
<outlet property="window" destination="QvC-M9-y7g" id="eyV-Nd-iwu"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Simple Video Filter View" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="660" height="500"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="660" height="500"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dd0-IN-e64" customClass="GPUImageView">
<rect key="frame" x="10" y="10" width="640" height="480"/>
</customView>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="viU-Oc-5RF"/>
</connections>
</window>
</objects>
</document>
13 changes: 13 additions & 0 deletions examples/Mac/SimpleVideoFilter/SimpleVideoFilter/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// main.m
// SimpleVideoFilter
//
// Created by Janie Clayton-Hasz on 1/8/15.
// Copyright (c) 2015 Red Queen Coder, LLC. All rights reserved.
//

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
}
24 changes: 24 additions & 0 deletions examples/Mac/SimpleVideoFilter/SimpleVideoFilterTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.redqueencoder.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// SimpleVideoFilterTests.m
// SimpleVideoFilterTests
//
// Created by Janie Clayton-Hasz on 1/8/15.
// Copyright (c) 2015 Red Queen Coder, LLC. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>

@interface SimpleVideoFilterTests : XCTestCase

@end

@implementation SimpleVideoFilterTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}

- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}

@end

0 comments on commit eecb459

Please sign in to comment.