您好,我正在使用 AVFoundation Framework 播放来自互联网的剪辑。我用AVPlayerItem playerItemWithURL:URL
现在我想检查从该视频文件接收到的字节的大小。我在此页面上找不到任何相关内容: https //developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayerItem_Class/Reference/Reference.html
那么有没有办法找到接收到的字节大小?
基本上我想要完成的是让 AVCaptureDevice 的前置摄像头成为 AVCaptureSession 期间应用程序上的第一个也是唯一的选项。
我环顾了 StackOverflow,提供的所有方法和答案都已从 iOS 10、Swift 3 和 Xcode 8 开始弃用。
我知道您应该使用 AVCaptureDeviceDiscoverySession 枚举设备并查看它们以区分正面和背面,但我不确定如何这样做。
有人可以帮忙吗?如果是这样就太棒了!
这是我的代码:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
previewLayer.frame = singleViewCameraSlot.bounds
self.singleViewCameraSlot.layer.addSublayer(previewLayer)
captureSession.startRunning()
}
lazy var captureSession: AVCaptureSession = {
let capture = AVCaptureSession()
capture.sessionPreset = AVCaptureSessionPreset1920x1080
return capture
}()
lazy var previewLayer: AVCaptureVideoPreviewLayer = {
let preview = AVCaptureVideoPreviewLayer(session: self.captureSession)
preview?.videoGravity = AVLayerVideoGravityResizeAspect
preview?.connection.videoOrientation = AVCaptureVideoOrientation.portrait
preview?.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
preview?.position = CGPoint(x: self.view.bounds.midX, y: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个集合视图,它可以根据时间戳显示相机胶卷中的所有图像和视频。
我只能加载图像或视频,不能同时加载两者。
我试过下面的代码
var photos: PHFetchResult<PHAsset>! // user photos array in collectionView for disaplying video thumnail
func getAssetFromPhoto() {
let options = PHFetchOptions()
options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: true) ]
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue)
photos = PHAsset.fetchAssets(with: options)
print(photos)
photoCollectionView.reloadData() // reload your collectionView
}
Run Code Online (Sandbox Code Playgroud)
正如您在上面的代码片段中看到的,在定义选项时我们只能要求视频采集或图像采集。
我怎样才能将它们两者结合起来。请注意:我愿意接受任何类型的开发建议,作为一种解决方法,我将 PHFetchResult 合并到一个集合中并填充我的集合视图。
这是唯一的方法吗?或者 Apple 是否为相同的 .
嘿,我正在尝试在我的设备上运行实时提要。现在我想每 3 秒拍一张照片,但每次都拍。它发出快门声。这是糟糕的用户体验。
因此,我想从前置摄像头运行实时摄像头流并在特定持续时间(~3 秒)捕获帧。
如何从实时摄像机源中提取帧并将其存储在 UIImage 变量中?
谢谢和干杯!
我正在构建能够录制视频并使用 和 在录制的视频上添加动画叠加的 iOS 应用AVFoundation程序CAAnimation。所有子功能都工作正常,但播放动画时视频背景的结尾是黑色的。它没有渲染我选择的背景视频。我曾经AVAssetWriter录制过视频,并且在相机胶卷上播放得很好。但如果我使用这个录制的视频添加叠加,视频末尾的背景是黑色的。有趣的是,如果我通过本机 iOS 相机应用程序录制视频并使用它添加叠加层,它就可以完美工作。我已经检查过这个问题,但对我没有用。黑色视频 CAAnimation 和 AVFoundation AVAssetExportSession
任何帮助将不胜感激。谢谢
avfoundation caanimation ios avassetwriter avmutablecomposition
假设我想从相机输出中存储一帧
let imageBuffer:CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
some_list.append(imageBuffer.copy())
Run Code Online (Sandbox Code Playgroud)
**
这是通过扩展到 CVPixelBuffer 定义复制函数的方式
extension CVPixelBuffer {
func copy() -> CVPixelBuffer {
precondition(CFGetTypeID(self) == CVPixelBufferGetTypeID(), "copy() cannot be called on a non-CVPixelBuffer")
var _copy : CVPixelBuffer?
CVPixelBufferCreate(
nil,
CVPixelBufferGetWidth(self),
CVPixelBufferGetHeight(self),
CVPixelBufferGetPixelFormatType(self),
CVBufferGetAttachments(self, CVAttachmentMode.shouldPropagate),
&_copy)
guard let copy = _copy else { fatalError() }
CVPixelBufferLockBaseAddress(self, CVPixelBufferLockFlags.readOnly)
CVPixelBufferLockBaseAddress(copy, CVPixelBufferLockFlags(rawValue: 0))
let dest = CVPixelBufferGetBaseAddress(copy)
let source = CVPixelBufferGetBaseAddress(self)
let height = CVPixelBufferGetHeight(self)
let bytesPerRow = CVPixelBufferGetBytesPerRow(self)
memcpy(dest, source, height * bytesPerRow)
CVPixelBufferUnlockBaseAddress(copy, CVPixelBufferLockFlags(rawValue: 0))
CVPixelBufferUnlockBaseAddress(self, CVPixelBufferLockFlags.readOnly) …Run Code Online (Sandbox Code Playgroud) 我正在构建的应用程序的一部分涉及录音。这是相关代码:
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue]
audioRecorder = try AVAudioRecorder(url: self.audioFilename, settings: settings)
Run Code Online (Sandbox Code Playgroud)
我希望质量尽可能好,但我希望允许用户在设置中更改质量(如果可以节省空间)。
AVAudioQuality 的不同值实际上有何作用?随着质量的下降,他们会让文件变小吗?采样率也是如此吗?我见过的很多教程都使用 12000 左右的采样率,尽管我知道专业录音通常是 44100,有什么理由不使用 44100 吗?
这个问题在 Xcode 10.2.1 和 iOS 12 中没有出现。它在 Xcode 11.1 和 iOS 13 中开始
我的应用程序录制视频,当应用程序转到后台时,我停止运行捕获会话并删除预览层。当应用程序返回前台时,我重新启动捕获会话并将预览层添加回:
let captureSession = AVCaptureSession()
var previewLayer: AVCaptureVideoPreviewLayer?
var movieFileOutput = AVCaptureMovieFileOutput()
// *** I initially didn't remove the preview layer in this example but I did remove it in the other 2 examples below ***
@objc fileprivate func stopCaptureSession() {
DispatchQueue.main.async {
[weak self] in
if self?.captureSession.isRunning == true {
self?.captureSession.stopRunning()
}
}
}
@objc func restartCaptureSession() {
DispatchQueue.main.async {
[weak self] in
if self?.captureSession.isRunning == …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AVFoundation. 这有效。我还尝试向视频添加叠加层,例如包含日期的文本标签。
例如:保存的视频不仅是相机看到的,还有时间戳。
这是我保存视频的方式:
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
saveVideo(toURL: movieURL!)
}
private func saveVideo(toURL url: URL) {
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)
}) { (success, error) in
if(success) {
print("Video saved to Camera Roll.")
} else {
print("Video failed to save.")
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个movieOuput是一个AVCaptureMovieFileOutput。我的预览图层不包含任何子图层。我尝试将时间戳标签的图层添加到 previewLayer,但这没有成功。
我已经尝试过Ray Wenderlich 的例子以及这个堆栈溢出问题。最后,我也尝试了这个教程,所有这些都无济于事。
如何为相机胶卷中保存的视频中的视频添加叠加层?
xcode avfoundation video-recording avcapturemoviefileoutput swift
目前我正在使用 AVAudioEngine 从麦克风获取音频样本并成功实现 FFT。为了获得稳定的频率值,我还在 FFT 之前对音频样本实现了 Hann 窗。现在我想对音频样本实施低通滤波器以消除高频。我做了一些关于 iOS 中低通滤波器的研究,但大多数答案都是通过 AVAudioUnit 找到的。这让我很困惑,是否可以仅在 AVAudioEngine 中实现低通滤波器?可以对音频样本应用低通滤波器吗?如果是,我们需要遵循哪种方法?提前致谢。
avfoundation ×10
swift ×7
ios ×6
swift3 ×2
avcapture ×1
avplayer ×1
caanimation ×1
core-audio ×1
iphone ×1
objective-c ×1
photokit ×1
xcode ×1
xcode8 ×1