Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add text on video in iPhone
    primarykey
    data
    text
    <p>I want to add a text or string ON the video being played by MPMoviePlayerViewController in a way that it becomes part of the video being played. So that, when I post that video on Facebook or Twitter the text must be shown above the video.</p> <p>For this I have tried getting all the frames of the video and then write text on each of those frames and then again make a video of all those frames. But this way, I am getting memory issues and it crashes on the device.</p> <pre><code> - (NSArray*)getVideoFramesFromMovieController:(MPMoviePlayerViewController*)mpMoviePlayerVC { NSLog(@"Getting frames from a video asset."); // videoFrames = [NSMutableArray array]; NSMutableArray *videoFrames = [NSMutableArray array]; for(float i= 0; i &lt;= mpMoviePlayerVC.moviePlayer.duration; ) { UIImage *singleFrameImage = [mpMoviePlayerVC.moviePlayer thumbnailImageAtTime:i timeOption:MPMovieTimeOptionExact]; [videoFrames addObject:singleFrameImage]; NSLog(@"Got frame number : %d",[videoFrames count]); i = i + (1/self.frameRate) ; //frame capturing duration i.e. 15fps //self.frameRate } NSLog(@"Total frames: %d",[videoFrames count]); return [NSArray arrayWithArray:videoFrames]; } </code></pre> <p>Method above gives me all the frames, i write a text on all those text, say "hello", and then make a video of all these frames.</p> <pre><code> -(void)writeImageAsMovie:(NSArray *)array toPath:(NSString*)path size:(CGSize)size { NSLog(@"Inside writeImageAsMovie method."); NSError *error = nil; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: [NSURL fileURLWithPath:path] fileType:AVFileTypeMPEG4 error:&amp;error]; NSParameterAssert(videoWriter); NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey, [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil]; AVAssetWriterInput* writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain]; AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:nil]; NSParameterAssert(writerInput); NSParameterAssert([videoWriter canAddInput:writerInput]); [videoWriter addInput:writerInput]; //Start a session: [videoWriter startWriting]; [videoWriter startSessionAtSourceTime:kCMTimeZero]; dispatch_queue_t dispatchQueue = dispatch_queue_create("mediaInputQueue", NULL); int __block frame = 0; [writerInput requestMediaDataWhenReadyOnQueue:dispatchQueue usingBlock:^{ while ([writerInput isReadyForMoreMediaData]) { NSLog(@"Total frames to be written: %d",[array count]); if(++frame &gt;= [array count]) //total frames { [writerInput markAsFinished]; [videoWriter finishWriting]; [videoWriter release]; break; } CVPixelBufferRef buffer = (CVPixelBufferRef)[self pixelBufferFromCGImage:[[array objectAtIndex:frame]CGImage] andSize:size]; if (buffer) { if(![adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(frame, self.frameRate)]) NSLog(@"FAIL"); else NSLog(@"Success:%d", frame); CFRelease(buffer); } } }]; NSLog(@"outside for loop"); [self performSelector:@selector(waitTillVideoFinishes) withObject:nil afterDelay:20.0]; } </code></pre> <p>It is working fine on the mac, but crashes on the device because of memory issues.</p> <p>I'hv also tried various ways to watermark the text on the video but could not get through. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload