This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIImage (Resize) | |
- (UIImage*)scaleBy:(float)scale; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)presentImagePicker:(UIView *)sender { | |
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; | |
imagePicker.modalPresentationStyle = UIModalPresentationPopover; | |
imagePicker.popoverPresentationController.sourceView = sender; | |
imagePicker.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny; | |
[self presentViewController:imagePicker animated:YES completion:nil]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import AVFoundation | |
- (UIImage*)thumbnailFromVideo:(NSURL *)url atTime:(float)time { | |
AVAsset *asset = [AVAsset assetWithURL:url]; | |
// get 3 decimal places | |
// ex: 3.39235350 --> 3.392 | |
float nearest = roundf(time * 1000) / 1000; | |
// make CMTime from float | |
// because of 3 decimal places, we use 10000 (10^4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kxmovie on github | |
First: cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/developer/SDKs/ to find out what SDKs are existed in your OS | |
Second: open Rake file and modify SDK_VERSION='9.2' -> your SDK version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################################################################### | |
# Choose your ffmpeg version and your currently-installed iOS SDK version: | |
# | |
VERSION="2.0.2" | |
SDKVERSION="7.0" | |
ARCHS="armv7 armv7s i386" | |
# | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here are steps: | |
1. Build FFmpeg for iOS | |
There some scripts to build FFmpeg for iOS | |
ex: https://github.com/kewlbear/FFmpeg-iOS-build-script | |
2. After build complete, copy all *.a to your iOS project folder. | |
They will be automatically add to Linked Frameworks and Libraries (in Project settings -> General) | |
ex: libavutil.a, libavformat.a, libavcodec.a,... | |
3. Add depedencies to Linked Frameworks and Libraries | |
Add libz.dylib (or libz.tbd), libiconv.dylib | |
4. Go to Project settings -> Build Settings, add the path which contains all *.a files in your iOS project folder to Library Search Paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Hello, world!"]; | |
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)]; | |
[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:24] range:NSMakeRange(3, 3)]; | |
NSData *data = [string dataFromRange:NSMakeRange(0, string.length) | |
documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFDTextDocumentType, | |
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} | |
error:nil]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sometimes, for some reason, you have to use AVAssetWriter to record videos from camera instead of using movile file output. | |
I had experienced some issue by that recording method due to lacking of tutorial and SO questions :)) | |
Noted for everyone who met the issue: black first frame | |
if (CMSampleBufferDataIsReady(sampleBuffer)) { | |
if (videoWriter.status != AVAssetWriterStatusWriting) { | |
CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); | |
[videoWriter startWriting]; | |
[videoWriter startSessionAtSourceTime:startTime]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <arpa/inet.h> | |
- (NSString *)getStringFromAddressData:(NSData *)dataIn { | |
struct sockaddr_in *socketAddress = nil; | |
NSString *ipString = nil; | |
socketAddress = (struct sockaddr_in *)[dataIn bytes]; | |
ipString = [NSString stringWithFormat: @"%s", | |
inet_ntoa(socketAddress->sin_addr)]; ///problem here | |
return ipString; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]; | |
AVPlayer *player = [AVPlayer playerWithURL:videoURL]; | |
AVPlayerViewController *playerViewController = [AVPlayerViewController new]; | |
playerViewController.player = player; | |
[self presentViewController:playerViewController animated:YES completion:nil]; | |
NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]; | |
AVPlayer *player = [AVPlayer playerWithURL:videoURL]; | |
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; | |
playerLayer.frame = self.view.bounds; |
OlderNewer