Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get watermarking to work #306

Closed
jln19 opened this issue May 9, 2016 · 17 comments
Closed

Cannot get watermarking to work #306

jln19 opened this issue May 9, 2016 · 17 comments

Comments

@jln19
Copy link

jln19 commented May 9, 2016

Couldn't find any documentation or a working example of watermarking videos. The below is what I could piece together. Can you tell me what is wrong with this? The video gets exported, but the watermark never appears. The watermark is a valid .png file (my_watermark@2x.png) in the app bundle.

AVAsset *asset = self.recordSession.assetRepresentingSegments;
    NSURL *tempUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"videomarked.mov"]];

    SCAssetExportSession *assetExportSession = [[SCAssetExportSession alloc] initWithAsset:asset];
    assetExportSession.outputUrl = tempUrl;
    assetExportSession.outputFileType = AVFileTypeMPEG4;
    assetExportSession.videoConfiguration.preset = SCPresetMediumQuality;
    assetExportSession.videoConfiguration.watermarkImage = [UIImage imageNamed:@"my_watermark"];
    assetExportSession.videoConfiguration.watermarkFrame = CGRectMake(0, 0, 320, 480);
    [assetExportSession exportAsynchronouslyWithCompletionHandler: ^{
        if (assetExportSession.error == nil) {
            // I get success here, but the video does not have a watermark

        } else {
            // Something bad happened

        }
    }];

I've confirmed that generatedWatermarkImage is valid in SCAssetExportSession:_buildWatermarkFilterForVideoSize

@rFlex
Copy link
Owner

rFlex commented May 11, 2016

Do you have a small project that you can share so I can investigate? That would be so awesome :)

@jln19
Copy link
Author

jln19 commented May 11, 2016

I will try to whip one up. In the meantime though can you confirm that watermarking has worked for you?

@jln19
Copy link
Author

jln19 commented May 12, 2016

@rFlex Here is the simple project showing that watermarking doesn't work, at least from what I can tell. Thanks for investigating :)

SCRecorderWatermarkTest.zip

@Klucherev
Copy link

Klucherev commented May 13, 2016

@rFlex Hi! I think problem is in - (SCFilter *)_generateRenderingFilterForVideoSize:(CGSize)videoSize method.
if (renderingFilter.isEmpty) { renderingFilter = nil; }
alway returns nil if no custom filter is setted ignoring watermark

@rFlex rFlex closed this as completed in bcba4ef May 16, 2016
@rFlex
Copy link
Owner

rFlex commented May 16, 2016

Thanks a lot for the help!. @Klucherev yeah good call, that was what the problem was :).

@jln19
Copy link
Author

jln19 commented May 16, 2016

@rFlex I tried making this update. Now there is a crash at line 317 of SCFilter.m. -[CIImage imageByCompositingOverImage:]: unrecognized selector sent to instance 0x14648c40

Try running the test project with your commit added.

@rFlex
Copy link
Owner

rFlex commented May 16, 2016

Are you running on iOS 7?

@jln19
Copy link
Author

jln19 commented May 16, 2016

Yes, that device was iOS7. I tested again on iOS9 and didn't get the crash, which makes sense. However, why does adding the watermark change the orientation of the video?
before
after

@rFlex
Copy link
Owner

rFlex commented May 16, 2016

This is another issue where your input video has a orientation metadata that isn't being respected by SCRecorder. You may be able to fix that by setting keepInputAffineTransform to false in SCVideoConfiguration

@jln19
Copy link
Author

jln19 commented May 16, 2016

`assetExportSession.videoConfiguration.keepInputAffineTransform = NO;`

results in this:

img_7943

This is the desired result:
desired

@rFlex
Copy link
Owner

rFlex commented May 16, 2016

Ok, I will check it out some time today

@jln19
Copy link
Author

jln19 commented May 18, 2016

@rFlex any updates on this? I've invested a lot of time implementing SCRecorder as a solution to our video recording/playback needs but if watermarking doesn't work I can't use it... and explain to my company why I have to start over :(

@rFlex
Copy link
Owner

rFlex commented May 18, 2016

SCRecorderWatermarkTest 3.zip

Here is a working example based of your project.

@jln19
Copy link
Author

jln19 commented May 19, 2016

Thanks. What did you change? ViewController.m looks the same. Did you make changes in the SCRecorder files?

@rFlex
Copy link
Owner

rFlex commented May 19, 2016

I added a videoComposition that will take care of transforming your video so the output video doesn't have any special rotation metadata.

@jln19
Copy link
Author

jln19 commented May 22, 2016

I see. Thank you.

rFlex added a commit that referenced this issue Jun 20, 2016
@UlanNurmatov
Copy link

It seems that I can't add watermark without adding a filter. How do I add a watermark without using a filter?

Here's my code:

guard self.asset != nil else { return }
            let assetExportSession = SCAssetExportSession.init(asset: self.asset)
            assetExportSession.delegate = self
            assetExportSession.inputAsset = self.asset
            assetExportSession.contextType = SCContextType.auto
            assetExportSession.outputUrl = self.recordSession.outputUrl
            assetExportSession.outputFileType = AVFileType.mp4.rawValue
            assetExportSession.videoConfiguration.filter = SCFilter.init(ciFilterName: "CIPhotoEffectFade")
            assetExportSession.videoConfiguration.watermarkImage = UIImage(named: "twitter")
            assetExportSession.videoConfiguration.watermarkFrame = CGRect(x: 0, y: 0, width: 200, height: 40)
            assetExportSession.videoConfiguration.preset = SCPresetHighestQuality
            assetExportSession.exportAsynchronously {
                if assetExportSession.error == nil {
                    self.saveVideo(withURL: assetExportSession.outputUrl!)
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants