Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
よくある動画アプリのあれを実装したい。
Search
nakajijapan
May 28, 2014
Technology
0
2.7k
よくある動画アプリのあれを実装したい。
Instagram, Vine, SlideStory のような動画アプリで動画を保存する仕込みが気になったので実装しました。
nakajijapan
May 28, 2014
Tweet
Share
More Decks by nakajijapan
See All by nakajijapan
サービスにおけるDesign Systemの構築
nakajijapan
6
3.4k
Markdownをリアルタイムに解析する
nakajijapan
4
4.3k
Firebase Authorization
nakajijapan
0
210
Intoducing Izumo
nakajijapan
1
1.8k
Practical CloudKit
nakajijapan
1
1.7k
Introducing to Ajimi - プロダクトを味見していこう
nakajijapan
0
2k
Shari
nakajijapan
1
2.6k
Japan Apple Pay Development
nakajijapan
0
240
業務で絶対必要にならない技術
nakajijapan
0
770
Other Decks in Technology
See All in Technology
ARRが3年で10倍になったプロダクト開発とAI活用の軌跡
akiroom
0
190
Nutanixにいらっしゃいませ。Moveと仮想マシン移行のポイント紹介
shadowhat
0
240
サービスの拡大に伴うオペレーション課題に立ち向かう / 20241128_cloudsign_pdm
bengo4com
0
770
12/2(月)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #1 with AWS Heroes)
minorun365
PRO
1
240
Kubernetesを知る
logica0419
17
4.4k
Amazon ECSとCloud Runの相互理解で広げるクラウドネイティブの景色 / Mutually understanding Amazon ECS and Cloud Run
iselegant
18
2.3k
GPUと画像生成AIが拓くマーケティングとビジネスの未来:次世代の可能性
iotcomjpadmin
0
300
突き破って学ぶコンテナセキュリティ/container-breakout-cncj-lt
mochizuki875
3
140
Bytebaseで実現する データベース管理の効率化
shogo452
1
290
Postman Flowsで作るAPI連携LINE Bot
miura55
0
220
SONY AITRIOSによるAIエッジセンシングの新たな可能性(仮)
iotcomjpadmin
0
310
50以上のマイクロサービスを支えるアプリケーションプラットフォームの設計・構築の後悔と進化 #CNDW2024 / regrets and evolution of application platform
toshi0607
5
620
Featured
See All Featured
Scaling GitHub
holman
458
140k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Why Our Code Smells
bkeepers
PRO
334
57k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
400
Adopting Sorbet at Scale
ufuk
73
9.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Transcript
BQQಓ !OBLBKJKBQBO Α͋͘Δಈը ΞϓϦͷ͋Ε Λ࣮͍ͨ͠
!OBLBKJKBQBO 4PGUXBSF&OHJOFFS (.01&1"#0JOD
৺ྶࣸਅΞϓϦ͓Θ͔Γ͍͚ͨͩͨͩΖ͏͔
৺ྶಈըΞϓϦ͏Ұ͝ཡ͍ͨͩ͜͏
"7'PVOEBUJPO ࠓճʂʂ
͋ͷಈըΛอଘ͢ΔΠ ϯλʔϑΣʔε͕ؾʹ ͳͬͨͷͰ࣮ͨ͠ɻ
༷
εΫϦʔϯΛλον ͨ͠ΒಈըΛอଘ։ ࢝ͯ͠εΫϦʔϯ͔ ΒΕͨΒอଘऴྃ
"7$BQUVSF4FTTJPO
"7$BQUVSF0VUQVU
"7$BQUVSF0VUQVU ɾ"7$BQUVSF.PWJF'JMF0VUQVU ɾ"7$BQUVSF4UJMM*NBHF0VUQVU ɾ"7$BQUVSF7JEFP%BUB0VUQVU ɾ"7$BQUVSF"VEJP%BUB0VUQVU
"7$BQUVSF0VUQVU ɾ"7$BQUVSF.PWJF'JMF0VUQVU ɾ'JMFT ɾ"7$BQUVSF4UJMM*NBHF0VUQVU ɾ*NBHF ɾ"7$BQUVSF7JEFP%BUB0VUQVU ɾ"7$BQUVSF"VEJP%BUB0VUQVU
ɾ-JWFEBUB
"7$BQUVSF0VUQVU ɾ"7$BQUVSF.PWJF'JMF0VUQVU ɾ'JMFT ɾ"7$BQUVSF4UJMM*NBHF0VUQVU ɾ*NBHF ɾ"7$BQUVSF7JEFP%BUB0VUQVU ɾ"7$BQUVSF"VEJP%BUB0VUQVU
ɾ-JWFEBUB
"7$BQUVSF"VEJP%BUB0VUQVU AVCaptureVideoDataOutputSampleBufferDelegate AVCaptureAudioDataOutputSampleBufferDelegate "7$BQUVSF7JEFP%BUB0VUQVU
#pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate ! - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection { ! if (!CMSampleBufferDataIsReady(sampleBuffer)) { NSLog(@"sampleBuffer data is not ready"); } ! CMTime currentTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); ! if (self.touching) { ! // Video if ([captureOutput isKindOfClass:[AVCaptureVideoDataOutput class]]) { [self addSamplebuffer:sampleBuffer withWriterInput:(AVAssetWriterInput *)self.assetWriterInputVideo]; } // Audio else if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]]) { [self addSamplebuffer:sampleBuffer withWriterInput:(AVAssetWriterInput *)self.assetWriterInputAudio]; } ! } ! self.recordStartTime = currentTime; } AVCaptureVideoDataOutputSampleBufferDelegate AVCaptureAudioDataOutputSampleBufferDelegate
8SJUJOH
εΫϦʔϯΛλον ͨ͠ΒಈըΛอଘ։ ࢝ͯ͠εΫϦʔϯ͔ ΒΕͨΒอଘऴྃ
εΫϦʔϯΛλον ͨ͠ΒಈըΛอଘ։ ࢝ͯ͠εΫϦʔϯ͔ ΒΕͨΒอଘऴྃ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; -
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
"7"TTFU8SJUFS "7"TTFU8SJUFS*OQVU
4UBSU8SJUJOH อଘରͷϑΝΠϧΛࢦఆͯ͠ॳظԽ ϝσΟΞλΠϓΛࢦఆ TFU&YQFDUT.FEJB%BUB*O3FBM5JNFΛ0/ʹ͢Δ "7"TTFU8SJUFSʹ"7"TTFU8SJUFS*OQVUΛΈࠐΉ ॻ͖ࠐΈ։࢝
4UBSU8SJUJOH // AVAssetWriter self.assetWriter = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:AVFileTypeQuickTimeMovie error:&error]; !
! // movie NSDictionary *videoSetting = self.videoSettings; self.assetWriterInputVideo = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; [self.assetWriterInputVideo setExpectsMediaDataInRealTime:YES]; ! ! // audio NSDictionary *audioSetting = self.audioSettings; self.assetWriterInputAudio = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioSetting]; [self.assetWriterInputAudio setExpectsMediaDataInRealTime:YES]; ! ! [self.assetWriter addInput:self.assetWriterInputVideo]; [self.assetWriter addInput:self.assetWriterInputAudio]; ! // queue self.movieWritingQueue = dispatch_queue_create("Movie Writing Queue", DISPATCH_QUEUE_SERIAL); ! // Record [self.assetWriter startWriting]; [self.assetWriter startSessionAtSourceTime:self.recordStartTime];
4UBSU8SJUJOH // AVAssetWriter self.assetWriter = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:AVFileTypeQuickTimeMovie error:&error]; !
! // movie NSDictionary *videoSetting = self.videoSettings; self.assetWriterInputVideo = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; [self.assetWriterInputVideo setExpectsMediaDataInRealTime:YES]; ! ! // audio NSDictionary *audioSetting = self.audioSettings; self.assetWriterInputAudio = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioSetting]; [self.assetWriterInputAudio setExpectsMediaDataInRealTime:YES]; ! ! [self.assetWriter addInput:self.assetWriterInputVideo]; [self.assetWriter addInput:self.assetWriterInputAudio]; ! // queue self.movieWritingQueue = dispatch_queue_create("Movie Writing Queue", DISPATCH_QUEUE_SERIAL); ! // Record [self.assetWriter startWriting]; [self.assetWriter startSessionAtSourceTime:self.recordStartTime];
4UBSU8SJUJOH // AVAssetWriter self.assetWriter = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:AVFileTypeQuickTimeMovie error:&error]; !
! // movie NSDictionary *videoSetting = self.videoSettings; self.assetWriterInputVideo = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; [self.assetWriterInputVideo setExpectsMediaDataInRealTime:YES]; ! ! // audio NSDictionary *audioSetting = self.audioSettings; self.assetWriterInputAudio = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioSetting]; [self.assetWriterInputAudio setExpectsMediaDataInRealTime:YES]; ! ! [self.assetWriter addInput:self.assetWriterInputVideo]; [self.assetWriter addInput:self.assetWriterInputAudio]; ! // queue self.movieWritingQueue = dispatch_queue_create("Movie Writing Queue", DISPATCH_QUEUE_SERIAL); ! // Record [self.assetWriter startWriting]; [self.assetWriter startSessionAtSourceTime:self.recordStartTime];
4UBSU8SJUJOH // AVAssetWriter self.assetWriter = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:AVFileTypeQuickTimeMovie error:&error]; !
! // movie NSDictionary *videoSetting = self.videoSettings; self.assetWriterInputVideo = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; [self.assetWriterInputVideo setExpectsMediaDataInRealTime:YES]; ! ! // audio NSDictionary *audioSetting = self.audioSettings; self.assetWriterInputAudio = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioSetting]; [self.assetWriterInputAudio setExpectsMediaDataInRealTime:YES]; ! ! [self.assetWriter addInput:self.assetWriterInputVideo]; [self.assetWriter addInput:self.assetWriterInputAudio]; ! // queue self.movieWritingQueue = dispatch_queue_create("Movie Writing Queue", DISPATCH_QUEUE_SERIAL); ! // Record [self.assetWriter startWriting]; [self.assetWriter startSessionAtSourceTime:self.recordStartTime];
4UBSU8SJUJOH // AVAssetWriter self.assetWriter = [AVAssetWriter assetWriterWithURL:self.outputURL fileType:AVFileTypeQuickTimeMovie error:&error]; !
! // movie NSDictionary *videoSetting = self.videoSettings; self.assetWriterInputVideo = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSetting]; [self.assetWriterInputVideo setExpectsMediaDataInRealTime:YES]; ! ! // audio NSDictionary *audioSetting = self.audioSettings; self.assetWriterInputAudio = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioSetting]; [self.assetWriterInputAudio setExpectsMediaDataInRealTime:YES]; ! ! [self.assetWriter addInput:self.assetWriterInputVideo]; [self.assetWriter addInput:self.assetWriterInputAudio]; ! // queue self.movieWritingQueue = dispatch_queue_create("Movie Writing Queue", DISPATCH_QUEUE_SERIAL); ! // Record [self.assetWriter startWriting]; [self.assetWriter startSessionAtSourceTime:self.recordStartTime];
4UBSU8SJUJOH - (void)addSamplebuffer:(CMSampleBufferRef)sampleBuffer withWriterInput:(AVAssetWriterInput *)assetWriterInput { CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
! CFRetain(sampleBuffer); CFRetain(formatDescription); dispatch_async(self.movieWritingQueue, ^{ ! if (_assetWriter.status == AVAssetWriterStatusWriting) { ! if (assetWriterInput.readyForMoreMediaData) { ! [assetWriterInput appendSampleBuffer:sampleBuffer]; ! } } ! CFRelease(sampleBuffer); CFRelease(formatDescription); }); }
$.4BNQMF#VGGFS3FG
$.4BNQMF#VGGFS3FG ɾ͋ΔϝσΟΞλΠϓͷαϯϓϧؚ͕·Εͨ$PSF'PVEBUJPO0CKFDUT ɹɾѹॖPSൺѹॖ ɾαϯϓϧ ɾશମͷத͔ΒऔΓग़ͨ͠Ұ෦ͷԿ͔
'JOJTI8SJUJOH ऴྃॲཧ ϑΝΠϧʹอଘ
'JOJTI8SJUJOH [self.assetWriterInputVideo markAsFinished]; [self.assetWriterInputAudio markAsFinished]; [self.assetWriter endSessionAtSourceTime:self.recordStartTime]; [self.assetWriter finishWritingWithCompletionHandler:^{ NSLog(@"self.assetWriter
finishWritingWithCompletionHandler"); [self.movieURLs addObject:self.outputURL]; NSLog(@"%@", self.movieURLs); }];
'JOJTI8SJUJOH [self.assetWriterInputVideo markAsFinished]; [self.assetWriterInputAudio markAsFinished]; [self.assetWriter endSessionAtSourceTime:self.recordStartTime]; [self.assetWriter finishWritingWithCompletionHandler:^{ NSLog(@"self.assetWriter
finishWritingWithCompletionHandler"); [self.movieURLs addObject:self.outputURL]; NSLog(@"%@", self.movieURLs); }];
͍͍ײ͡ʹग़དྷ্͕ͬͨ ͷͰެ։͠·ͨ͠ɻ
/,+.VMUJ.PWJF$BQUVSF7JFX IUUQTHJUIVCDPNOBLBKJKBQBO/,+.VMUJ.PWJF$BQUVSF7JFX
൚༻ੑ͕·ͩΓͳ͍ͷ Ͱʑॗʑͱվળͤͯ͞ ͍͖ͨͩ·͢ɻɻɻɻɻ
ࠂ͍ͤͯͩ͘͞͞
DPNNJOHTPPO
5IBOLT