iosobjective-cavfoundationavmutablecompositionvideo-watermarking

how to add subtitle to mp4 in iOS


i already know that i should use AVFoundationto get the CGContextRef from .mp4 file;

and use like :

CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:36];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, 400)];
[subtitle1Text setString:[self.subtitles objectAtIndex:idx]];
[subtitle1Text setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text setForegroundColor:[[UIColor whiteColor] CGColor]];

[subtitle1Text drawInContext:context];

to make subtitles;

now the question is how can i get CGContextRef from .mp4 file?

i mean i've got the url of .mp4 file, but how can i add CATextLayer in the mp4?


Solution

  • You have to use AVFoundation framework in order to add text on video you can have a look into the following link for more detail. You have add the text layer on video layer and then have to export it.

    AVMutableComposition

    Have a look into bellow sample code there is a way to add watermark you can create subtitles by changing few properties like start time and end time.

    AVSimpleEditoriOS