How to link / sync animation with live video

App Descrtiption : Speedometer. It has a needle and an animated needle as an overlay on the video. I output the needle animation to the video through post-processing. I use AVAssetExportSession and create an AVComposition containing my animated layers, as well as video and audio tracks from the video. It works great. Videos, animated needles.

Currently, to play the animation during post-processing, I have saved all speed changes over time, since the "recording" of the video began. During postprocessing, I then start the timer based on the saved time / speed data so that I can animate the needle at the next speed.

Problem . The resulting video / animation pair is not completely accurate, and often there is a mismatch between the speed displayed when shooting video, as well as during playback and composition. (usually a needle is preceded by a video) due to the fact that composition / compression during export is not necessary in real time.

Question . Is there a way to include speed information in the video stream and then access it when exporting it so that the video and speedometer are consistent in time?

It would be nice to get a callback at a specific time during the export that contains speed data.

As always ... thanks!

+5
source share
5 answers

.

CA , , , .

+1

iPhone, , . , HTTP LIve Streaming HTTP Live Streaming Tools.

id3taggenerator mediafilesegmenter. :

id3taggenerator -o camera1.id3 -text "Dolly camera"
id3taggenerator -o camera2.id3 -text "Tracking camera"

, , . . . " ". :

60 id3 camera1.id3
120 id3 camera2.id3

- , , . mediafilesegmenter , , , .

, MPMoviePlayerController . . : http://jmacmullin.wordpress.com/2010/11/03/adding-meta-data-to-video-in-ios/

+1

CAAnimations beginTime, , AVVideoComposition + AVVideoCompositionCoreAnimationTool, . , :

, ...

, , .

+1

, , , , - ( 1/30 , 30 ) . - CALayers .

CAAnimation, beginTime, 1/30 . . , . , , , , , . , , .

/******** this has not been compiled but you should get the idea ************

// Before starting the AVAssetExportSession session and after the AVMutableComposition routine

CALayer* speedoBackground = [[CALayer alloc] init]; // background layer for needle layers
[speedoBackground setFrame:CGRectMake(x,y,width,height)]; // size and location
[speedoBackground setBackgroundColor:[[UIColor grayColor] CGColor]];
[speedoBackground setOpacity:0.5] // partially see through on video

// loop through the data
for (int index = 0; index < [dataArray count]; index++) {

  CALayer* speedoNeedle = [[CALayer alloc] init]; // layer for needle drawing
  [speedoNeedle setFrame:CGRectMake(x,y,width,height)]; // size and location
  [speedoNeedle setBackgroundColor:[[UIColor redColor] CGColor]];
  [speedoNeedle setOpacity:1.0]; // probably not needed

  // your needle drawing routine for each data point ... e.g.
  [self drawNeedleOnLayer:speedoNeedle angle:[self calculateNeedleAngle[dataArray objectAtIndex:index]]];

  CABasicAnimation *needleAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
  needleAnimation.fromValue = [NSNumber numberWithFloat:(float)0.0];
  needleAnimation.toValue = [NSNumber numberWithFloat:(float)1.0]; // fade in
  needleAnimation.additive = NO;
  needleAnimation.removedOnCompletion = NO; // it obscures previous layers
  needleAnimation.beginTime = index*animationDuration;
  needleAnimation.duration = animationDuration -.03; // it will not animate at this speed but layer will appear immediately over the previous layer at the correct media time
  needleAnimation.fillMode = kCAFillModeBoth;
  [speedoNeedle addAnimation:needleAnimation forKey:nil];
  [speedoBackground addSublayer:needleOverlay];
}

[parentLayer addSublayer:speedoBackground];

.
.
.
// when the AVAssetExportSession has finished, make sure you clear all the layers
parentLayer.sublayers = nil;

, . , , , , .

+1

This year, WWDC is hosting a session that may offer a different approach to what you are doing. You can watch the video here: http://developer.apple.com/videos/wwdc/2011/ . Look for one called “Working with Media in AVFoundation”. Interesting bits for about 26 minutes or so. I'm not quite sure that I understand the problem, but when I read it, this session happened to me.

Sincerely.

0
source

All Articles