How to add watermark to any oriented video in iOS?
up vote
0
down vote
favorite
I need to add watermark to video but different oriented videos. Below codes are working for me when i add watermark to portrait video, but this code is not working for landscape videos, watermark become stressed.
UIImage *myImage;
myImage =[UIImage imageNamed:@"twinbitWaterMark"];
CALayer *layerCa = [CALayer layer];
layerCa.contents = (id)myImage.CGImage;
float newX = videosize.width - imagesize.width;
float newY = videosize.height - imagesize.height;
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
layerCa.opacity = 1.0;
[layerCa setMasksToBounds:YES];
CALayer *parentLayer=[CALayer layer];
CALayer *videoLayer=[CALayer layer];
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
videoLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:layerCa];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Please help.
ios objective-c video-watermarking
add a comment |
up vote
0
down vote
favorite
I need to add watermark to video but different oriented videos. Below codes are working for me when i add watermark to portrait video, but this code is not working for landscape videos, watermark become stressed.
UIImage *myImage;
myImage =[UIImage imageNamed:@"twinbitWaterMark"];
CALayer *layerCa = [CALayer layer];
layerCa.contents = (id)myImage.CGImage;
float newX = videosize.width - imagesize.width;
float newY = videosize.height - imagesize.height;
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
layerCa.opacity = 1.0;
[layerCa setMasksToBounds:YES];
CALayer *parentLayer=[CALayer layer];
CALayer *videoLayer=[CALayer layer];
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
videoLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:layerCa];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Please help.
ios objective-c video-watermarking
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to add watermark to video but different oriented videos. Below codes are working for me when i add watermark to portrait video, but this code is not working for landscape videos, watermark become stressed.
UIImage *myImage;
myImage =[UIImage imageNamed:@"twinbitWaterMark"];
CALayer *layerCa = [CALayer layer];
layerCa.contents = (id)myImage.CGImage;
float newX = videosize.width - imagesize.width;
float newY = videosize.height - imagesize.height;
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
layerCa.opacity = 1.0;
[layerCa setMasksToBounds:YES];
CALayer *parentLayer=[CALayer layer];
CALayer *videoLayer=[CALayer layer];
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
videoLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:layerCa];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Please help.
ios objective-c video-watermarking
I need to add watermark to video but different oriented videos. Below codes are working for me when i add watermark to portrait video, but this code is not working for landscape videos, watermark become stressed.
UIImage *myImage;
myImage =[UIImage imageNamed:@"twinbitWaterMark"];
CALayer *layerCa = [CALayer layer];
layerCa.contents = (id)myImage.CGImage;
float newX = videosize.width - imagesize.width;
float newY = videosize.height - imagesize.height;
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
layerCa.opacity = 1.0;
[layerCa setMasksToBounds:YES];
CALayer *parentLayer=[CALayer layer];
CALayer *videoLayer=[CALayer layer];
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
videoLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:layerCa];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
Please help.
ios objective-c video-watermarking
ios objective-c video-watermarking
asked Nov 8 at 9:48
Saad
7010
7010
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
I think it is an mistake in your calculation:
Your watermark has landscape or watermark orientation.
By calculating the width and height
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
you are not preserving the original watermark ratio.
In landscape you have to calculate an offset left and right to your frame to preserve the ratio.
add a comment |
up vote
0
down vote
Before saving the file locally create a CATextLayer and attach it to the video. I believe this code will help you which I had written for one my application.
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
NSArray *fieldsArray = overlayFieldsArray;
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
subtitle1Text.wrapped=YES;
subtitle1Text.alignmentMode = kCAAlignmentLeft;
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:textSize];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, fieldsArray.count*textSize+20) ];
NSMutableString *layerText = [NSMutableString stringWithCapacity:0];
for(NSDictionary *fieldDictionary in fieldsArray){
[layerText appendFormat:@" %@ :",[[fieldDictionary allKeys] objectAtIndex:0]];
[layerText appendFormat:@" %@ n",[_candidateDictionary valueForKey:[[fieldDictionary allValues] objectAtIndex:0]]];
}
[subtitle1Text setString:layerText];
[subtitle1Text setForegroundColor:[[UIColor colorForText] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
overlayLayer.backgroundColor = [UIColor colorForLayer].CGColor;
overlayLayer.opacity=0.5f;
CGSize maximumSize = CGSizeMake(600, 600);
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:textSize];
CGSize layerTextSize = [layerText sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:UILineBreakModeWordWrap];
overlayLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[overlayLayer setMasksToBounds:YES];
[overlayLayer addSublayer:subtitle1Text];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
parentLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
add a comment |
up vote
-1
down vote
Some example project here https://github.com/rubygarage/media-watermark
MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.
Please refer the web document :- https://rubygarage.org/blog/open-source-image-and-video-processing-library-for-ios
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think it is an mistake in your calculation:
Your watermark has landscape or watermark orientation.
By calculating the width and height
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
you are not preserving the original watermark ratio.
In landscape you have to calculate an offset left and right to your frame to preserve the ratio.
add a comment |
up vote
0
down vote
I think it is an mistake in your calculation:
Your watermark has landscape or watermark orientation.
By calculating the width and height
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
you are not preserving the original watermark ratio.
In landscape you have to calculate an offset left and right to your frame to preserve the ratio.
add a comment |
up vote
0
down vote
up vote
0
down vote
I think it is an mistake in your calculation:
Your watermark has landscape or watermark orientation.
By calculating the width and height
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
you are not preserving the original watermark ratio.
In landscape you have to calculate an offset left and right to your frame to preserve the ratio.
I think it is an mistake in your calculation:
Your watermark has landscape or watermark orientation.
By calculating the width and height
layerCa.frame = CGRectMake(newX, newY, videosize.width*2, videosize.height*2);
parentLayer.frame=CGRectMake(0, 0, videosize.width, videosize.height);
you are not preserving the original watermark ratio.
In landscape you have to calculate an offset left and right to your frame to preserve the ratio.
edited Nov 8 at 16:58
answered Nov 8 at 16:48
ivion
15025
15025
add a comment |
add a comment |
up vote
0
down vote
Before saving the file locally create a CATextLayer and attach it to the video. I believe this code will help you which I had written for one my application.
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
NSArray *fieldsArray = overlayFieldsArray;
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
subtitle1Text.wrapped=YES;
subtitle1Text.alignmentMode = kCAAlignmentLeft;
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:textSize];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, fieldsArray.count*textSize+20) ];
NSMutableString *layerText = [NSMutableString stringWithCapacity:0];
for(NSDictionary *fieldDictionary in fieldsArray){
[layerText appendFormat:@" %@ :",[[fieldDictionary allKeys] objectAtIndex:0]];
[layerText appendFormat:@" %@ n",[_candidateDictionary valueForKey:[[fieldDictionary allValues] objectAtIndex:0]]];
}
[subtitle1Text setString:layerText];
[subtitle1Text setForegroundColor:[[UIColor colorForText] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
overlayLayer.backgroundColor = [UIColor colorForLayer].CGColor;
overlayLayer.opacity=0.5f;
CGSize maximumSize = CGSizeMake(600, 600);
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:textSize];
CGSize layerTextSize = [layerText sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:UILineBreakModeWordWrap];
overlayLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[overlayLayer setMasksToBounds:YES];
[overlayLayer addSublayer:subtitle1Text];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
parentLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
add a comment |
up vote
0
down vote
Before saving the file locally create a CATextLayer and attach it to the video. I believe this code will help you which I had written for one my application.
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
NSArray *fieldsArray = overlayFieldsArray;
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
subtitle1Text.wrapped=YES;
subtitle1Text.alignmentMode = kCAAlignmentLeft;
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:textSize];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, fieldsArray.count*textSize+20) ];
NSMutableString *layerText = [NSMutableString stringWithCapacity:0];
for(NSDictionary *fieldDictionary in fieldsArray){
[layerText appendFormat:@" %@ :",[[fieldDictionary allKeys] objectAtIndex:0]];
[layerText appendFormat:@" %@ n",[_candidateDictionary valueForKey:[[fieldDictionary allValues] objectAtIndex:0]]];
}
[subtitle1Text setString:layerText];
[subtitle1Text setForegroundColor:[[UIColor colorForText] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
overlayLayer.backgroundColor = [UIColor colorForLayer].CGColor;
overlayLayer.opacity=0.5f;
CGSize maximumSize = CGSizeMake(600, 600);
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:textSize];
CGSize layerTextSize = [layerText sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:UILineBreakModeWordWrap];
overlayLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[overlayLayer setMasksToBounds:YES];
[overlayLayer addSublayer:subtitle1Text];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
parentLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Before saving the file locally create a CATextLayer and attach it to the video. I believe this code will help you which I had written for one my application.
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
NSArray *fieldsArray = overlayFieldsArray;
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
subtitle1Text.wrapped=YES;
subtitle1Text.alignmentMode = kCAAlignmentLeft;
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:textSize];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, fieldsArray.count*textSize+20) ];
NSMutableString *layerText = [NSMutableString stringWithCapacity:0];
for(NSDictionary *fieldDictionary in fieldsArray){
[layerText appendFormat:@" %@ :",[[fieldDictionary allKeys] objectAtIndex:0]];
[layerText appendFormat:@" %@ n",[_candidateDictionary valueForKey:[[fieldDictionary allValues] objectAtIndex:0]]];
}
[subtitle1Text setString:layerText];
[subtitle1Text setForegroundColor:[[UIColor colorForText] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
overlayLayer.backgroundColor = [UIColor colorForLayer].CGColor;
overlayLayer.opacity=0.5f;
CGSize maximumSize = CGSizeMake(600, 600);
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:textSize];
CGSize layerTextSize = [layerText sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:UILineBreakModeWordWrap];
overlayLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[overlayLayer setMasksToBounds:YES];
[overlayLayer addSublayer:subtitle1Text];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
parentLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
Before saving the file locally create a CATextLayer and attach it to the video. I believe this code will help you which I had written for one my application.
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
NSArray *fieldsArray = overlayFieldsArray;
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
subtitle1Text.wrapped=YES;
subtitle1Text.alignmentMode = kCAAlignmentLeft;
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:textSize];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, fieldsArray.count*textSize+20) ];
NSMutableString *layerText = [NSMutableString stringWithCapacity:0];
for(NSDictionary *fieldDictionary in fieldsArray){
[layerText appendFormat:@" %@ :",[[fieldDictionary allKeys] objectAtIndex:0]];
[layerText appendFormat:@" %@ n",[_candidateDictionary valueForKey:[[fieldDictionary allValues] objectAtIndex:0]]];
}
[subtitle1Text setString:layerText];
[subtitle1Text setForegroundColor:[[UIColor colorForText] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
overlayLayer.backgroundColor = [UIColor colorForLayer].CGColor;
overlayLayer.opacity=0.5f;
CGSize maximumSize = CGSizeMake(600, 600);
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:textSize];
CGSize layerTextSize = [layerText sizeWithFont:myFont
constrainedToSize:maximumSize
lineBreakMode:UILineBreakModeWordWrap];
overlayLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[overlayLayer setMasksToBounds:YES];
[overlayLayer addSublayer:subtitle1Text];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
parentLayer.frame = CGRectMake(10, 0, layerTextSize.width*1.1, fieldsArray.count*textSize+20);
[parentLayer addSublayer:overlayLayer];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
answered Nov 8 at 18:47
Subin
23316
23316
add a comment |
add a comment |
up vote
-1
down vote
Some example project here https://github.com/rubygarage/media-watermark
MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.
Please refer the web document :- https://rubygarage.org/blog/open-source-image-and-video-processing-library-for-ios
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
add a comment |
up vote
-1
down vote
Some example project here https://github.com/rubygarage/media-watermark
MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.
Please refer the web document :- https://rubygarage.org/blog/open-source-image-and-video-processing-library-for-ios
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Some example project here https://github.com/rubygarage/media-watermark
MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.
Please refer the web document :- https://rubygarage.org/blog/open-source-image-and-video-processing-library-for-ios
Some example project here https://github.com/rubygarage/media-watermark
MediaWatemark is an open source GPU/CPU-based iOS watermark library for overlays adding to images or video content. It has simple interface and straightforward functionality.
Please refer the web document :- https://rubygarage.org/blog/open-source-image-and-video-processing-library-for-ios
answered Nov 8 at 10:31
user1376400
1157
1157
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
add a comment |
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
Same problem. It is not working for square dimension video.
– Saad
Nov 8 at 10:45
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205149%2fhow-to-add-watermark-to-any-oriented-video-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown