I want to add a watermark to a video using AVFoundation with specified frame and duration. I can't find the answer from Google and tutorial. A Post on StackOverflow How to watermark your video with different images and different CMTimes using AVFoundation doesn't solve the problem. It just change opacity from start time to end time. Do you have any ideas. Thanks!
Asked
Active
Viewed 1,531 times
5
-
possible duplicate of [How can I add a watermark in a captured video on iOS](http://stackoverflow.com/questions/15932041/how-can-i-add-a-watermark-in-a-captured-video-on-ios) – Desdenova Jan 23 '14 at 07:24
-
I think you will got answer from [here][1] [1]: http://stackoverflow.com/questions/15932041/how-can-i-add-a-watermark-in-a-captured-video-on-ios?lq=1 – kagmanoj Jan 23 '14 at 07:37
-
1Thank @Desdenova kindness, I just want to add watermark to video for segment of video, not add watermark for the whole duration. – HeavenSword Jan 23 '14 at 08:17
-
1I want to set duration of the watermark. The article above demonstrates how to add watermark during the whole video playback. – HeavenSword Jan 27 '14 at 07:50
-
Did you ever find an answer for this? – ScottF Feb 10 '14 at 03:01
-
I didn't find the answer. I think AVFoundation can not do the the job. FFmpeg maybe an answer. Convert the video to frames and then add watermark to specified frame is an alternative method.@Scott F – HeavenSword Feb 14 '14 at 02:52
-
@HeavenSword Have you found solution? I am also facing same issue. – Payal Maniyar Feb 20 '17 at 12:53
-
@HeavenSword i have same problem. if you get solution please post answer how to add water mark at specific time and duration. – sohil Apr 24 '18 at 05:49
1 Answers
0
You will want to use addBoundaryTimeObserver
// Define the times at which you want to trigger events
let specificTimes: [CMTime] = [
CMTime(seconds: 10.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC)), // Example time
CMTime(seconds: 30.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC)) // Another example time
]
// Add a boundary time observer
let timeObserverToken = player.addBoundaryTimeObserver(forTimes: specificTimes, queue: .main) {
// This block of code will be executed when the player's current time crosses any of the specified times.
// You can run your code here.
}
// Later, when you're done observing or when the player is no longer needed:
player.removeTimeObserver(timeObserverToken)

6rchid
- 1,074
- 14
- 19