gpt4 book ai didi

iphone - iOS 上的实时视频清理

转载 作者:行者123 更新时间:2023-11-28 22:48:08 27 4
gpt4 key购买 nike

Media Foundation 中的标准电影播放器​​似乎不支持非常流畅的擦洗。我想让显示的视频在您将手指滑过栏时不断刷新,而不是像默认情况下那样每隔几秒跳一次。起初我以为默认控件可能内置了某种延迟,但使用我自己的 slider 设置播放时间并没有帮助。有什么想法吗?

编辑:我还在试验,看起来可能的擦洗起点之间有一个固定的间隔。也许有一些方法可以减少间隔。

最佳答案

这对我有用。我在幻灯片更改时从视频 Assets 中抓取一帧。请参阅下面的代码。它是从我当前的项目中截取的,可能包含一些错误,但你会明白的。它在 Swift 1 中,但希望没问题。

var urlVideo :NSURL = NSURL()
var vidLength :CMTime = CMTime()
var durInSeconds: Float = 0.00
var timescale:CMTimeScale = CMTimeScale()
var videoInfo:NSDictionary = NSDictionary()
var chosePosSlider:UISlider = UISlider()

@IBOutlet weak var imgCont: UIImageView!

func generateThumnail(url : NSURL, fromTime:Float64) -> UIImage {

var asset :AVAsset = AVAsset.assetWithURL(url) as! AVAsset
var assetImgGenerate : AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)

assetImgGenerate.appliesPreferredTrackTransform = true
assetImgGenerate.requestedTimeToleranceAfter = kCMTimeZero;
assetImgGenerate.requestedTimeToleranceBefore = kCMTimeZero;

var error : NSError? = nil
var time : CMTime = CMTimeMakeWithSeconds(fromTime, timescale)
var img : CGImageRef = assetImgGenerate.copyCGImageAtTime(time, actualTime: nil, error: &error)
var frameImg : UIImage = UIImage(CGImage: img)!

return frameImg

}

func sliderValueDidChange(sender:UISlider!) {

var newTime:Float = durInSeconds * sender.value
setFrame(newTime)

}

func setFrame(pos:Float) {
imgCont.image = generateThumnail(urlVideo, fromTime: Float64(pos))
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

self.dismissViewControllerAnimated(true, completion: nil)

videoInfo = info as NSDictionary
urlVideo = videoInfo.objectForKey(UIImagePickerControllerMediaURL) as! NSURL

var asset :AVAsset = AVAsset.assetWithURL(urlVideo) as! AVAsset

vidLength = asset.duration
durInSeconds = Float(CMTimeGetSeconds(vidLength))
timescale = vidLength.timescale

chosePosSlider = UISlider(frame:CGRectMake(20, 450, 340, 20))
chosePosSlider.minimumValue = 0
chosePosSlider.maximumValue = 1
chosePosSlider.continuous = true
chosePosSlider.tintColor = UIColor.greenColor()
chosePosSlider.value = 0
chosePosSlider.addTarget(self, action: "sliderValueDidChange:", forControlEvents: .ValueChanged)
self.view.addSubview(chosePosSlider)


setFrame(0.0)

}

关于iphone - iOS 上的实时视频清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12655612/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com