Skip to content

Commit

Permalink
WaterMark Update
Browse files Browse the repository at this point in the history
  • Loading branch information
黄锐灏 committed Jan 11, 2019
1 parent 1617c63 commit 73270dc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Binary file not shown.
6 changes: 3 additions & 3 deletions WAVideoBox/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ - (IBAction)addWaterMark:(id)sender {
__weak typeof(self) wself = self;

[_videoBox appendVideoByPath:_videoPath];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.7, 0.2, 0.12)];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.2, 0.2, 0)];

[_videoBox asyncFinishEditByFilePath:filePath complete:^(NSError *error) {
if (!error) {
Expand Down Expand Up @@ -192,7 +192,7 @@ - (IBAction)composeEdit:(id)sender {
[_videoBox appendVideoByPath:_videoPath];
[_videoBox appendVideoByPath:_testThreePath];
[_videoBox replaceSoundBySoundPath:_testTwoPath];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.7, 0.2, 0.1)];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.2, 0.2, 0)];

[_videoBox rotateVideoByDegress:180];
[_videoBox dubbedSoundBySoundPath:_testOnePath];
Expand Down Expand Up @@ -228,7 +228,7 @@ - (IBAction)magicEdit:(id)sender {
[_videoBox rangeVideoByTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMake(3600, 600))];

[_videoBox appendVideoByPath:_testOnePath];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.7, 0.2, 0.12)];
[_videoBox appendWaterMark:[UIImage imageNamed:@"waterMark"] relativeRect:CGRectMake(0.7, 0.2, 0.2, 0)];
[_videoBox rangeVideoByTimeRange:CMTimeRangeMake(CMTimeMake(3600, 600), CMTimeMake(3600, 600))];

[_videoBox appendVideoByPath:_testTwoPath];
Expand Down
6 changes: 2 additions & 4 deletions WAVideoBox/WAVideoBox/WAAVSeCommand/WAAVSERotateCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ - (NSUInteger)degressFromTransform:(CGAffineTransform)transForm

- (void)converRect:(CALayer *)layer naturalRenderSize:(CGSize)size renderSize:(CGSize)renderSize{



if (!CGSizeEqualToSize(size, renderSize)) {
// 还原绝对位置
CGRect relativeRect = CGRectMake(layer.frame.origin.x / size.width, 1 - (layer.frame.origin.y + layer.bounds.size.height) / size.height, layer.bounds.size.width / size.width, layer.bounds.size.height / size.height);
CGRect relativeRect = CGRectMake(layer.frame.origin.x / size.width, layer.frame.origin.y / size.height, layer.bounds.size.width / size.width, layer.bounds.size.height / size.height);

layer.frame = CGRectMake(renderSize.width * relativeRect.origin.x,renderSize.height * (1 - relativeRect.origin.y) - renderSize.height * relativeRect.size.height,renderSize.width * relativeRect.size.width, renderSize.height * relativeRect.size.height);
layer.frame = CGRectMake(renderSize.width * relativeRect.origin.x,renderSize.height * relativeRect.origin.y,renderSize.width * relativeRect.size.width, renderSize.height * relativeRect.size.height);

}
}
Expand Down
5 changes: 2 additions & 3 deletions WAVideoBox/WAVideoBox/WAVideoBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "WAAVSEGearboxCommand.h"
#import "WAAVSEGearboxCommandModel.h"
typedef NS_ENUM(NSUInteger,WAVideoExportRatio) {
WAVideoExportRatioLowQuality,// 自动分辩率
WAVideoExportRatioMediumQuality,// 自动分辩率
Expand Down Expand Up @@ -81,7 +81,6 @@ typedef NS_ENUM(NSUInteger,WAVideoExportRatio) {
*/
- (BOOL)rangeVideoByTimeRange:(CMTimeRange)range;


/**
视频截取
Expand All @@ -102,7 +101,7 @@ typedef NS_ENUM(NSUInteger,WAVideoExportRatio) {
/**
为视频加入水印
@param waterImg 图片
@param relativeRect 相对尺寸 x ,y , width , height值均为 (0 ~ 1)
@param relativeRect 相对视频尺寸对比(0~1)), x(与视频左部的距离为VideoWidth * x) ,y (与视频底部的距离为VideoHeight * y), width (图片宽度为VideoWidth * width),height(图片高度为VideoHeight * height),height可以直接设为零即为等比缩放
@return 操作状态
*/
- (BOOL)appendWaterMark:(UIImage *)waterImg relativeRect:(CGRect)relativeRect;
Expand Down
11 changes: 10 additions & 1 deletion WAVideoBox/WAVideoBox/WAVideoBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,17 @@ - (BOOL)appendWaterMark:(UIImage *)waterImg relativeRect:(CGRect)relativeRect{
WAAVSEImageMixCommand *command = [[WAAVSEImageMixCommand alloc] initWithComposition:composition];
command.imageBg = NO;
command.image = waterImg;


[command imageLayerRectWithVideoSize:^CGRect(CGSize videoSize) {
return CGRectMake(videoSize.width * relativeRect.origin.x,videoSize.height * (1 - relativeRect.origin.y) - videoSize.height * relativeRect.size.height,videoSize.width * relativeRect.size.width, videoSize.height * relativeRect.size.height);

CGFloat height = 0;
if (relativeRect.size.height) {
height = videoSize.height * relativeRect.size.height;
}else{
height = videoSize.width * relativeRect.size.width * waterImg.size.height / waterImg.size.width;
}
return CGRectMake(videoSize.width * relativeRect.origin.x,videoSize.height * relativeRect.origin.y,videoSize.width * relativeRect.size.width, height);
}];
[command performWithAsset:composition.mutableComposition];
}
Expand Down

0 comments on commit 73270dc

Please sign in to comment.