HSL stream Video stretched after some time on IOS 15 - ios

First, this is a Youtube link showing the problem: Video stretched. The Youtube video is edited to remove unnecessary parts, I am only showing the important parts. As you can see after some time the video gets stretched.
The original video was uploaded to Azure media services and encoded by Azure media using the built-in "AdaptiveStreaming" preset.
I am using HLS dynamic packaging with this url:
https://amswrdev-usso.streaming.media.azure.net/80a2651c-462f-487f-b1a3-87cb72366255/1zIHQ.ism/manifest(format=m3u8-cmaf)
I am testing it on an Iphone 12 pro max, IOS 15.0.1, swift 5.0
I am using the AVPlayerViewController, this is the code:
import Foundation
import SwiftUI
import AVKit
struct VideoPlayerView: UIViewControllerRepresentable {
var player: AVPlayer
#Binding var gravity: AVLayerVideoGravity
func makeUIViewController(context: UIViewControllerRepresentableContext<VideoPlayerView>) -> AVPlayerViewController {
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false
controller.videoGravity = gravity
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: UIViewControllerRepresentableContext<VideoPlayerView>) {
uiViewController.videoGravity = gravity
}
func dismantleUIViewController(_ uiViewController: AVPlayerViewController, coordinator: Self.Coordinator) {
//print("dismantleUIViewController \(uiViewController)")
}
}
My hypothesis:
Avplayer is not correctly switching to the correct bandwidth
Azure media is not sending the correct variants on the initial playlist
Maybe I don't have the correct parameters for preferredMaximumResolution and preferredForwardBufferDuration? but I don't know what values should be correct.
Dynamic packaging of azure media is now on version 7, maybe is not supported by IOS?
I have been trying to fix it changing my view to have fixed values of height and width but is not working. I have 2 weeks trying to figure out this but nothing is working, Do you have any idea?
Like I said the video is stretched after some time, is not consistent. Sometimes happens immediately and sometimes takes more time but happens.

I'm still on iOS 14 on an iPhone 8 - and it plays just fine for me... so this may be an iOS 15.0.1 issue right now.

Related

Take snapshot of PDF viewer on iOS12

Good afternoon,
I am trying to take a snapshot of a PDF but I am facing some difficulties to access view's content on iOS 12.
In order to display the PDF's content, I've already used two different approaches:
UIDocumentInteractorController
Webview
On iOS 11, I couldn't already take a snapshot of a UIDocumentInteractorController view and the best answer that I could find was this one https://stackoverflow.com/a/13332623/2568889. In short, it says that the document viewer runs in an external process and on its own windows that the main app process doesn't have access to.
The WebView was the solution at that time, until iOS 12 came. While testing on real devices running iOS 12, I had the same issue of not being able to access the viewer's content while taking the snapshot. While inspecting the view hierarchy, it looks like we have a childviewcontroller (PDFHostViewController) that is the one rendering the actual view.
Please take into account that this issue is just happening for PDFs, on regular webpages is working fine!
Code used to take snapshot:
private extension UIView {
func takeSnapshot() -> UIImage {
let format = UIGraphicsImageRendererFormat()
format.opaque = self.isOpaque
let renderer = UIGraphicsImageRenderer(size: self.frame.size, format: format)
return renderer.image { context in
self.drawHierarchy(in: self.frame, afterScreenUpdates: true)
}
}
}
Note: I have also tried to use the native Webview.takeSnapshot(with:,completionHandler) of the web view but it just works for regular webpages, not PDFs
Maybe it works with Apple's PDFKit. As far as i know the PDFView is a subclass of UIView.
import PDFKit
#IBOutlet var pdfView: PDFView!
let pdfDocument = PDFDocument(url: url)
pdfView.document = pdfDocument
And then your extension as PDFView extension

swift AVCapturePhotoOutput capturePhoto hangs preview

Showing preview in 1080 x 1440; getting photo with max resolution (3024 x 4032) and quality on iPhone 8 Plus with code:
capturePhotoOutput?.capturePhoto(with: configurePhotoSettings(), delegate: self)
with photo settings:
private func configurePhotoSettings() -> AVCapturePhotoSettings {
let photoSettings = AVCapturePhotoSettings()
photoSettings.isHighResolutionPhotoEnabled = true
photoSettings.isAutoStillImageStabilizationEnabled = (capturePhotoOutput?.isStillImageStabilizationSupported)!
photoSettings.isAutoDualCameraFusionEnabled = (capturePhotoOutput?.isDualCameraFusionSupported)!
return photoSettings
}
Doing this one by one (like sequential shooting mode) and preview freezes each time for a short time even if I do nothing in didFinishProcessingPhoto.
Looking for solution to make capturing smooth, maybe in background thread, but currently I'm stuck..
The reason of preview hangs is feature called optical stabilization.
You just need to turn it off for smooth preview while capturing photo:
photoSettings.isAutoStillImageStabilizationEnabled = false

AVPlayer not able to play after playing some items

I am building one simple game where I need to display 2 videos to user frequently videos are in my bundle locally. I just want to play that videos on my viewcontroller. My code for that is :
let playerItem = AVPlayerItem(URL: NSURL.fileURLWithPath("\(vdoPath)")) //vdoPath will be random of that two local video files from bundle
let player = AVPlayer(playerItem: playerItem)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
playerViewController.view.backgroundColor = UIColor.clearColor()
playerViewController.showsPlaybackControls = false
playerViewController.view.frame = self.playerView.bounds
self.playerView.addSubview(playerViewController.view)
self.addChildViewController(playerViewController)
player.play()
AVPlayer plays videos for sometimes like I am not facing issue till 12-15 times but when I continue to play more AVPlayer not able to play it showing like this:
There is no issue with my file and path because before getting this I am able to play 12-15 times as I said. please give me proper solution and reason behind this.
For people facing this issue in the future and #JAck's solution not working, here's a solution that worked for me. By the way, my screen was just black. It didn't have the play button with a slash through it... But anyways, the underlying issue for me was that I had too many instances of AVPlayer and AVPlayerLayer (Apple apparently caps this number). Though I was removing the layer and pausing the player when dismissing the view controller, the player was still being retained (I'm guessing). So, my fix was to nil out BOTH the player instance and the player layer instance. Here's my code:
var player: AVPlayer?
var layer: AVPlayerLayer?
Right before dismissing my view controller, I add this snippet:
DispatchQueue.main.async {
self.player?.pause()
self.player = nil
self.layer?.removeFromSuperlayer()
self.layer = nil
}
You need to use player.replacePlayerItem(item) instead of twice calling
if still not working ask me anytime. First let AVPlayer play first video then wait your controller till completion then start another.

Video in SKVideoNode works fine in Xcode simulator, won't play on most devices

I'm developing an app for Swift and Sprite Kit (xCode 6.4, currently building for iOS 8.4). I'm using SKVideoNode in conjunction with AVPlayer to play a full-screen video. The code follows:
let path = NSBundle.mainBundle().pathForResource("SPLASH_x", ofType:"mov")
let vUrl = NSURL.fileURLWithPath(path!)
let asset = AVAsset.assetWithURL(vUrl) as? AVAsset
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(URL: vUrl)
SplashVideo = SKVideoNode(AVPlayer: player)
SplashVideo!.xScale = self.size.width / SplashVideo!.size.width
SplashVideo!.yScale = self.size.height / SplashVideo!.size.height
SplashVideo!.position = CGPointMake(self.frame.midX, self.frame.midY)
self.addChild(SplashVideo!)
var observer: AnyObject? = nil
observer = player.addPeriodicTimeObserverForInterval(CMTimeMake(1,30), queue: dispatch_get_main_queue(),
usingBlock: { (time: CMTime) -> Void in
let secs:Float64 = CMTimeGetSeconds(time)
println("I think it's playing")
if (secs > 0.01) {
self.hideBackground()
println("I think I'm done observing. Background hidden!")
player.removeTimeObserver(observer!)
}
})
println("I think I'm playing the splash video:")
SplashVideo!.play()
(In case it's not clear, this happens in didMoveToView; I have imported Foundation, AVFoundation, and SpriteKit at the top of the file).
This works fine in the simulator; if I build and run for my iPad nothing happens at all--it displays a black screen, or if I remove the time observer (so that the background never gets hidden), I just see the background (The background is the first frame of the movie--I was experiencing a black flash at the beginning of video playback and am using the time observer as a masking technique to hide it). One of my users has reported that it worked for him until he upgraded to iOS9 (less of a concern), another reports that he hears the audio that goes with the .mov file but doesn't see the video itself (more of a concern). So I'm getting a variety of non-working behaviors, which is the best kind of bug. And by best I mean worst.
Things I have tried:
Various versions and combinations of directly linking in Foundation, AVFoundation, SpriteKit when building.
Using AVPlayerLayer instead of SpriteKit (no change in behavior for me, didn't deploy so I don't know if it would help any of my testers).
Removing the time observer entirely (no change).
Searching the interwebs (no help).
Tearing my hair out (ouch).
All were ineffective. And now I am bald. And sad.
Answering my own question: after much trial and error, it appears that you can't scale an SKVideoNode in iOS9 (or possibly this was never supported? The documentation is not clear). It's also true that the simulator for xCode 7 isn't playing video no matter what I do, which wasn't helping matters. In any case, what you can do is change the size property of the Node (and, I guess, let Sprite Kit do the scaling? Documentation seems spotty) and that seems to work:
let asset = AVAsset.assetWithURL(vUrl) as? AVAsset
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(URL: vUrl)
SplashVideo = SKVideoNode(AVPlayer: player)
SplashVideo!.size = self.size
SplashVideo!.position = CGPointMake(self.frame.midX, self.frame.midY)
self.addChild(SplashVideo!)

iOS: making video file from many images generated by code

I need to make a video file from thousands of images generated by code.
I cannot put those images into an array because they are too many--a 30second-long video would consist of 1800 imgae frames. And I don't get all images at once.
To get each image, it first triggers Javascript fucntion in WebView asking if a video frame,which is UIImage, should be generated. if Yes, my code makes UIImage for a video frame one at a time. and the app does other things and at some point it asks webview again for a permission to generate another image. it does this for a thousand times and more.
If Delegate gets a message that says No, the last image was a final video frame so a complete video file should be made at this point and saved to Document directory.
How should I do this? Objective C solutions would be acceptable too. thank you in advance
//ask webview if another video frame should be made
func askWebView() {
webView?.evaluateJavaScript("Ask JS function",completionHandler:nil)
}
Delegate
//Delegate method
func userContentController(userContentController:WKUserContentController,didReceiveScriptMessage message:WKScriptMessage){
let body:String = message.body as! String
if body == "makeAFrame" {
let videoFrame = self.makeImage()
//should asseble video frames
} else {
//No,nomore video frame. write a complete video file to Document directory
}
Generating an UIImage for a video frame
func makeImage() -> UIImage {
//make an image and return it
}

Resources