Getting a snapshot image of a video

The following code captures and display a static image of the Publisher video, adds it to the main view, and sets a UIImage object for the image:

if let publisherView = publisher.view,
        let screenCapture = publisherView.snapshotView(afterScreenUpdates: true) {
    self.view.addSubview(screenCapture)
    UIGraphicsBeginImageContextWithOptions(publisherView.bounds.size, false, UIScreen.main.scale)
    view.drawHierarchy(in: publisherView.bounds, afterScreenUpdates: true)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}

The following code captures and display a static image of the subscriber video, adds it to the main view, and sets a UIImage object for the image:

if let subscriberView = subscriber?.view,
        let screenCapture = subscriberView.snapshotView(afterScreenUpdates: true) {
    self.view.addSubview(screenCapture)
    UIGraphicsBeginImageContextWithOptions(subscriberView.bounds.size, false, UIScreen.main.scale)
    view.drawHierarchy(in: subscriberView.bounds, afterScreenUpdates: true)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}