Skip to content

Instantly share code, notes, and snippets.

func exportVideoWithWatermark(inputURL: URL, outputURL: URL, watermark: UIImage) {
guard let composition = addWatermark(to: inputURL, watermark: watermark) else {
print("Failed to add watermark")
return
}
guard let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality) else {
print("Failed to create export session")
return
}
import AVFoundation
func addWatermark(to videoURL: URL, watermark: UIImage) -> AVMutableComposition? {
// Create a new mutable composition
let mixComposition = AVMutableComposition()
// Add a new mutable track to the composition and get the first video track from the asset
guard let track = mixComposition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid)),
let asset = AVAsset(url: videoURL).tracks(withMediaType: .video).first else {
return nil
if let navigationBar = navigationBar as? UINavigationBar {
navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont.ok_bold(20)]
}
.h file declarations
@property (strong, nonatomic) UINavigationController *navigationController;
.m app delegate implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc] init];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:self.viewController animated:YES];
// Override point for customization after application launch.
struct PostContent: Codable {
struct Paragraph: Codable {
let id: String
let text: String
}
struct Section: Codable {
let id: String
let startIndex: Int
}
var paragraphs: [Paragraph]
@kmdarshan
kmdarshan / sample.json
Created September 23, 2019 07:05
sample json
{
"paragraphs": [{
"id": "p0",
"text": "aaa"
},
{
"id": "p1",
"text": "bbb"
},
{
@kmdarshan
kmdarshan / .cpp
Created August 28, 2019 14:05
stopping debugger
#ifdef _MSC_VER
// windows OS
# define BREAK_HERE() __debugbreak()
#elif defined(ARCH_X64) || defined(ARCH_X86)
// linux or iOS based systems
# define BREAK_HERE() __asm__("int $3")
#else
# define BREAK_HERE() raise(SIGTRAP)
#endif
@kmdarshan
kmdarshan / factory.swift
Created August 28, 2019 14:03
Factory method implementation in Swift
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
enum Maps : Int {
case google = 1
case apple
}
@kmdarshan
kmdarshan / attributedText.swift
Created August 21, 2019 20:10
Using attributed text in Swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let html = """
<html>
<body>
<p style="color: blue;
font-size: 20px;
">
@kmdarshan
kmdarshan / gist:2c015c0d0b7746df4a10a15aeb18acf3
Created August 21, 2019 19:58
Detecting interlaced videos using ffmpeg
/Users/darshan/Downloads/ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y /dev/null -i /Users/darshan/Dropbox/Public/1080i/interlaced/Mug\ Drop_Interlaced_4ss.mp4
video:303750kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[Parsed_idet_0 @ 0x7facaf200000] Repeated Fields: Neither: 63 Top: 20 Bottom: 18
[Parsed_idet_0 @ 0x7facaf200000] Single frame detection: TFF: 81 BFF: 0 Progressive: 20 Undetermined: 0
[Parsed_idet_0 @ 0x7facaf200000] Multi frame detection: TFF: 101 BFF: 0 Progressive: 0 Undetermined: 0