Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AV Foundation

A77456b262557e22986345f6d0555c58?s=47 nakajijapan
February 01, 2014

AV Foundation

心霊動画アプリ「もう一度ご覧いただこう」を作成してみて

Conference With Developers 2014

A77456b262557e22986345f6d0555c58?s=128

nakajijapan

February 01, 2014
Tweet

Transcript

  1. "7'PVOEBUJPO ৺ྶಈըΞϓϦʮ΋͏Ұ౓͝ཡ͍ͨͩ͜͏ʯΛ࡞੒ͯ͠Έͯ !OBLBKJKBQBO

  2. ࠓ೔࿩͢͜ͱ w ࣗݾ঺հ w ΞϓϦ঺հ w "7'PVOEBUJPOΛ࢖࣮ͬͨ૷͋Ε͜Ε w ॴײ

  3. ࣗݾ঺հ !OBLBKJKBQBO QBQFSCPZDP

  4. !JTPEJOF

  5. !JTPEJOF ςϨϏͰ΍ΔΑ͏ͳ৺ྶ൪૊ Έ͍ͨͳಈը࡞Γ͍ͨΜ΍ʙ

  6. ͸͍

  7. None
  8. IUUQPXLSJOGPNPWJF ΋͏Ұ౓͝ཡ͍ͨͩ͜͏ ৺ྶಈըΞϓϦ

  9. ओͳػೳ w ಈը࿥ը w ಈըʹ৺ྶΛೖΕΔ w ಈըʹςϩοϓͱϫΠϓ w ಈըͷγνϡΤʔγϣϯʹ߹ΘͤͯφϨʔγϣϯ ΛೖΕΔ

    w ιʔγϟϧڞ༗
  10. w .FEJB1MBZFS'SBNFXPSL w 6*,JU ্Ґ૚ͷϑϨʔϜϫʔΫ

  11. "7'PVOEBUJPO

  12. ௐࠪ

  13. ௐࠪ   w "7'PVOEBUJPO1SPHSBNNJOH(VJEF w .PWJOHUP"7,JUBOE"7'PVOEBUJPOr w $PSF*NBHF&GGFDUTBOE5FDIOJRVFTr w

    "EWBODFE&EJUJOHXJUI"7'PVOEBUJPOr
  14. ߏ੒

  15. εϩʔϞʔγϣϯಈը TFD TFD TFD φϨʔγϣϯԻ੠ ϫΠϓ ը૾߹੒ ಈը݁߹ ಈը݁߹

  16. ࣮૷

  17. ಈը݁߹

  18. // Assetੜ੒ AVURLAsset *videoAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil]; !

    // CompositionTrackੜ੒ AVMutableCompositionTrack* compositionVideoTrack; compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; ! // Ξηοτ͔ΒτϥοΫΛऔಘ AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; ! // ઃఆ [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:videoTrack atTime:self.currentTimeDuration error:nil]; [compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; // Assetੜ੒ [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:self.currentTimeDuration error:nil]; self.currentTimeDuration = [mixComposition duration]; ! // Layer Instructionͷ௥Ճ AVMutableVideoCompositionLayerInstruction *layerInstruction; layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack]; ! [self.layerInstructions addObject:layerInstruction]; ϝσΟΞ৘ใΛอ࣋͠ɺͦͷ৘ใΛऔಘͰ͖Δ
  19. // Assetੜ੒ AVURLAsset *videoAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil]; !

    // CompositionTrackੜ੒ AVMutableCompositionTrack* compositionVideoTrack; compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; ! // Ξηοτ͔ΒτϥοΫΛऔಘ AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; ! // ઃఆ [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:videoTrack atTime:self.currentTimeDuration error:nil]; [compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; // Assetੜ੒ [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:self.currentTimeDuration error:nil]; self.currentTimeDuration = [mixComposition duration]; ! // Layer Instructionͷ௥Ճ AVMutableVideoCompositionLayerInstruction *layerInstruction; layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack]; ! [self.layerInstructions addObject:layerInstruction]; ө૾ΛऔΓग़͢ Ի੠ΛऔΓग़͢
  20. // Assetੜ੒ AVURLAsset *videoAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil]; !

    // CompositionTrackੜ੒ AVMutableCompositionTrack* compositionVideoTrack; compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; ! // Ξηοτ͔ΒτϥοΫΛऔಘ AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; ! // ઃఆ [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:videoTrack atTime:self.currentTimeDuration error:nil]; [compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; // Assetੜ੒ [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:self.currentTimeDuration error:nil]; self.currentTimeDuration = [mixComposition duration]; ! // Layer Instructionͷ௥Ճ AVMutableVideoCompositionLayerInstruction *layerInstruction; layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack]; ! [self.layerInstructions addObject:layerInstruction]; ίϯϙδγϣϯΛ૊ΈཱͯΔ
  21. ը૾ͷ߹੒ͱ Ξχϝʔγϣϯ

  22. None
  23. // generate parent layer CALayer* layerRoot = [CALayer layer]; CALayer*

    layerVideo = [CALayer layer]; . . . . videoComp = [AVMutableVideoComposition videoComposition]; videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:layerVideo inLayer:layerRoot]; $"-BZFSʹ$"#BTJD"OJNBUJPOͰ ઃఆͨ͠ΞχϝʔγϣϯΛ௥Ճ͢Δ
  24. ϫΠϓಈը

  25. None
  26. // Assetੜ੒ AVURLAsset *videoAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil]; //

    CompositionTrackੜ੒ AVMutableCompositionTrack* compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; // Trackऔಘ AVAssetTrack* videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; ! // ઃఆ CMTime timeDuration; timeDuration = videoAsset.duration; ! [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, timeDuration) ofTrack:videoTrack atTime:kCMTimeZero error:nil]; [compositionVideoTrack setPreferredTransform:[videoTrack preferredTransform]]; AVMutableVideoCompositionLayerInstruction* layerInstruction; layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack]; [layerInstruction setTransform:CGAffineTransformConcat(scale, trnsration) atTime:kCMTimeZero]; ! [self.layerInstructions addObject:layerInstruction]; ΞϑΟϯม׵
  27. εϩʔϞʔγϣϯ

  28. // શମʹରͯ͠εϩʔϞʔγϣϯॲཧΛ͔͚Δ CMTime durationSlow = CMTimeSubtract(videoAsset.duration, CMTimeMake(9, 1)); [mixComposition scaleTimeRange:CMTimeRangeMake(CMTimeMake(19,

    1), durationSlow) toDuration:CMTimeMake(durationSlow.value * 2.0, durationSlow.timescale)]; ࣮ࡍͷө૾Λ̎ഒͷ࣌ؒͰग़ྗͤ͞Δ
  29. εϩʔϞʔγϣϯ ϫΠϓಈը ը૾ͷ߹੒ͱΞχϝʔγϣϯ ಈը݁߹ ࣮૷

  30. "7'PVOEBUJPO

  31. ॴײ w Ϋϥε໊௕͔ͬͨΓ࣮૷ྔ͕ଟͯ͘େมʂ w ͱ͸͍͑ઃܭ͸͢͹Β͍͠ w ৘ใ͕গͳ͍ w ϋϚΔͱ਺೔໎૸ঢ়ଶ w

    ࢓ࣄͰશ͘׆͔ͤͳ͍ʂʂʂ
  32. 4BNQMF.PWJF IUUQTXXXZPVUVCFDPNXBUDI WLKPXF43%* %FNP.PWJF IUUQTXXXZPVUVCFDPNXBUDI WSKUNK:6

  33. 5IBOLT