标签: avfoundation

AVCaptureMetadataOutput 的 metadataObjectTypes 属性的常量?

当使用 AVFoundation 检测图像中的特征(例如人脸或条形码)时,您必须调用如下一行:

AVCaptureMetadataOutput *metadataOutput = ...;
metadataOutput.metadataObjectTypes = metadataOutput.availableMetadataObjectTypes;
Run Code Online (Sandbox Code Playgroud)

检查 availableMetadataObjectTypes 显示以下字符串:

face,
"org.gs1.UPC-E",
"org.iso.Code39",
"org.iso.Code39Mod43",
"org.gs1.EAN-13",
"org.gs1.EAN-8",
"com.intermec.Code93",
"org.iso.Code128",
"org.iso.PDF417",
"org.iso.QRCode",
"org.iso.Aztec"
Run Code Online (Sandbox Code Playgroud)

如果我正在编写条形码扫描应用程序,我不希望框架寻找人脸,所以metadataOutput.availableMetadataObjectTypes我不想传递,而是传递特定的条形码来寻找。而不是使用这些硬编码的字符串,我希望它们在某处被定义为常量。

它们是否存在于框架中的任何地方,还是必须使用硬编码字符串?

constants objective-c avfoundation

1
推荐指数
1
解决办法
3288
查看次数

AVFoundation 从错误的帧速率图像创建视频

我正在尝试使用 AVFoundation 从图像创建视频。关于这种方法已经有多个线程,但我相信它们中的许多都与我在这里面临的问题相同。

视频在 iPhone 上可以正常播放,但不能在 VLC 上播放,例如在 Facebook 和 Vimeo 上也不能正常播放(有时某些帧不同步)。VLC 说视频的帧速率是 0.58 fps,但它应该超过 24 对吧?

有谁知道是什么导致了这种行为?

这是用于创建视频的代码:

self.videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:videoOutputPath] fileType:AVFileTypeMPEG4 error:&error];
    // Codec compression settings
    NSDictionary *videoSettings = @{
                                    AVVideoCodecKey : AVVideoCodecH264,
                                    AVVideoWidthKey : @(self.videoSize.width),
                                    AVVideoHeightKey : @(self.videoSize.height),
                                    AVVideoCompressionPropertiesKey : @{
                                            AVVideoAverageBitRateKey : @(20000*1000), // 20 000 kbits/s
                                            AVVideoProfileLevelKey : AVVideoProfileLevelH264High40,
                                            AVVideoMaxKeyFrameIntervalKey : @(1)
                                            }
                                    };

    AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];

    AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
                                                     assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput
                                                     sourcePixelBufferAttributes:nil];

    videoWriterInput.expectsMediaDataInRealTime = NO;
    [self.videoWriter addInput:videoWriterInput];
    [self.videoWriter …
Run Code Online (Sandbox Code Playgroud)

frame-rate video-processing avfoundation avassetwriter

1
推荐指数
1
解决办法
2020
查看次数

在 IOS 上使用 AVComposition 混合两个音频文件

我正在尝试混合两个音频文件(将一个音频文件放在另一个文件上 - 没有拼接在一起),但我正在努力学习 IOS 上的 AVFoundation。我在这里遵循了这个答案:如何使用 AVMutableCompositionTrack 合并音频和视频

这就是我所拥有的:

//NSURL *audioFilePath = [NSURL fileURLWithPath:@"var/mobile/Applications/822732B6-67B9-485F-BA44-FAACAB34C4FD/Documents/Coisir Cheoil10_09_2014_1429.m4a"];
NSURL *audioUrl = [NSURL fileURLWithPath:@"var/mobile/Applications/822732B6-67B9-485F-BA44-FAACAB34C4FD/Documents/Robot R-3-311_09_2014_2252.m4a"];
// need to fix link to backing Track
NSURL *backingTrackURL = [NSURL fileURLWithPath:@"var/mobile/Applications/822732B6-67B9-485F-BA44-FAACAB34C4FD/Documents/Robot R-3-316_09_2014_1559.m4a"];// need ot fix the link to this
AVURLAsset* backingTrack = [[AVURLAsset alloc] initWithURL:audioUrl options:nil];
AVURLAsset* voiceTrack = [[AVURLAsset alloc] initWithURL:backingTrackURL options:nil];

AVMutableComposition* mixComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];


[compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, backingTrack.duration)
                                    ofTrack:[[backingTrack tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0]
                                     atTime:kCMTimeZero
                                      error:nil];

AVMutableCompositionTrack *compositionVoiceTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio …
Run Code Online (Sandbox Code Playgroud)

audio avfoundation ios

1
推荐指数
1
解决办法
3889
查看次数

Swift IOS 使用 AVFoundation 录制视频和音频

我能够通过在此处解决此问题来成功获取录制的视频

基本上

  1. AVCaptureFileOutputRecordingDelegate原型继承
  2. 循环访问可用设备
  3. 使用相机创建会话
  4. 开始录音
  5. 停止录音
  6. 通过实现上述原型的方法获取录制视频

但该文件不附带音频。

根据这个问题,我必须单独录制音频并使用提到的类合并视频和音频

但我不知道如何同时实现视频和音频录制。

for device in devices {
    // Make sure this particular device supports video
    if (device.hasMediaType(AVMediaTypeVideo)) {
        // Finally check the position and confirm we've got the back camera
        if(device.position == AVCaptureDevicePosition.Back) {
            captureDevice = device as? AVCaptureDevice
            if captureDevice != nil {
                print("Capture device found")

                beginSession()
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个循环中,只有可用的设备类型是 .Front 和 .Back

avfoundation ios swift

1
推荐指数
2
解决办法
1万
查看次数

AVFoundation 旋转屏幕 - Obj C

我正在努力改变视频的方向。它以纵向记录,然后以横向保存。更改变换只会使视频在横向视频中旋转。在这个带有 M_PI_2 的例子中,它消失了,因为它旋转了屏幕或平面。但是如果我把它改成 M_PI_2/2 或者它看起来是歪的。我知道 AVFoundation 默认情况下会这样做。我该如何改变?我从本教程中得到了很多这样的代码:https : //www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos 但使用 AVMutableVideoCompositionLayerInstruction 不起作用。

AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                    preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime insertTime = kCMTimeZero;
for(AVAsset *videoAsset in self.videoArray){
    [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:insertTime error:nil];
    // Updating the insertTime for the next insert
    insertTime = CMTimeAdd(insertTime, videoAsset.duration);
}
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(M_PI_2);
videoTrack.preferredTransform = rotationTransform;

// 3.1 - Create AVMutableVideoCompositionInstruction
AVMutableVideoCompositionInstruction *mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.timeRange = videoTrack.timeRange;

// 3.2 - Create an AVMutableVideoCompositionLayerInstruction for the video track and fix …
Run Code Online (Sandbox Code Playgroud)

transform objective-c video-processing avfoundation ios

1
推荐指数
1
解决办法
393
查看次数

实时更改 AVSpeechUtterance 率

我目前正在开发一个使用 AVSynthesizer 将文本转换为语音的 iOS 应用程序。

我想要做的是,当合成器说话时,可以通过滑块更改发声率,并且说话的速度会发生变化。

我在滑块的 IBAction 中这样做: self.utterance = sender.value

但合成器不会改变速度。我一直在寻找信息,但我还没有找到。我能做什么?提前致谢。

xcode avfoundation ios avspeechsynthesizer avspeechutterance

1
推荐指数
1
解决办法
1648
查看次数

如何为 CATextLayer 的字符串设置动画?

我目前正在使用 AVMutableComposition 在视频中叠加一些文本,我想根据某个时间间隔重复更改字符串。我正在尝试使用 Core Animation 来实现这一点;但是,字符串属性似乎不是可动画的。有没有其他方法可以实现目标?谢谢。

代码(不工作):

func getSubtitlesAnimation(withFrames frames: [String], duration: CFTimeInterval)->CAKeyframeAnimation {
    let animation = CAKeyframeAnimation(keyPath:"string")
    animation.calculationMode = kCAAnimationDiscrete
    animation.duration = duration
    animation.values = frames
    animation.keyTimes = [0,0.5,1]
    animation.repeatCount = Float(frames.count)
    animation.isRemovedOnCompletion = false
    animation.fillMode = kCAFillModeForwards
    animation.beginTime = AVCoreAnimationBeginTimeAtZero
    return animation
}
Run Code Online (Sandbox Code Playgroud)

avfoundation ios swift

1
推荐指数
1
解决办法
2023
查看次数

AVCapturePhotoOutput - 设置不可重复使用

我正在运行 ios 12 swift 4.2。

我已经实现了一个基本的相机捕获会话,并且正在点击其中的图像。一切都很好,直到我在自动/开/关模式之间切换闪光灯。单击第一张照片然后更改闪光模式后,应用程序崩溃并显示错误:

[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] Settings may not be re-used'
Run Code Online (Sandbox Code Playgroud)

以下是相机实现:

var captureSession: AVCaptureSession!
var videoPreviewLayer: AVCaptureVideoPreviewLayer!
var capturePhotoOutput: AVCapturePhotoOutput!
let capturePhotoSettings = AVCapturePhotoSettings()


var previewView: UIView!


override func viewDidLoad() {
    startCameraSession()
    setupCaptureOutput()
}

@objc // Tap on a button to capture
func takePhotoOnTap() {
    guard let capturePhotoOutput = self.capturePhotoOutput else { return }

    capturePhotoSettings.isAutoStillImageStabilizationEnabled = true
    capturePhotoSettings.isHighResolutionPhotoEnabled = true
    capturePhotoSettings.flashMode = .auto
    let _ = getSettings(camera: captureDevice!, flashMode: spotmiCameraOptions.flashMode)
    capturePhotoOutput.capturePhoto(with: capturePhotoSettings, delegate: self)
}


    //This is …
Run Code Online (Sandbox Code Playgroud)

camera avfoundation ios avcapturesession swift

1
推荐指数
1
解决办法
2156
查看次数

-Swift.h 头文件中没有名为“AVCaptureVideoDataOutputSampleBufferDelegate”的类型或协议

我有一个 Objective-C 项目,其中我在 Obj-C 脚本中使用 Swift 脚本。

在其中一个 Swift 脚本中,我有一个类:

@objc public class VideoCapture: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
~~bunch of functions~~
}
Run Code Online (Sandbox Code Playgroud)

因为它是一个 Obj-C 项目,所以我在它前面加上了 @obj,以便它们出现在我的 ($project_name-Swift.h) 头文件中。

我收到了头文件中所写内容的错误:

// 来自头文件的片段:project_name-Swift.h

 #import <AVFoundation/AVFoundation.h>.  <— I added this to make sure that AVFoundation is present in the header file

SWIFT_CLASS("_TtC17FLIROneSDKExample12VideoCapture")
@interface VideoCapture : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>   <<——!!! error: No type or protocol named 'AVCaptureVideoDataOutputSampleBufferDelegate'
- (void)captureOutput:(AVCaptureOutput * _Nonnull)output didOutputSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer fromConnection:(AVCaptureConnection * _Nonnull)connection;
- (void)captureOutput:(AVCaptureOutput * _Nonnull)output didDropSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer fromConnection:(AVCaptureConnection * _Nonnull)connection;
- …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c avfoundation ios swift

1
推荐指数
1
解决办法
2687
查看次数

导出的慢动作视频存在音频问题

我正在开发一个应用程序,它允许您将从用户的照片库中选择的照片和视频合并为一部电影。到目前为止,我的应用程序可以轻松处理常规视频、实时照片(作为视频)和静态照片。但是,我在慢动作视频(和时间流逝,就此而言)方面遇到了很多麻烦。

我的主要问题是:慢动作视频的慢动作片段中的音频极度失真(例如,听起来有点嗡嗡声、机器人和断断续续的声音)。视频显示正常。

根据这个问题的答案,我决定首先使用 AVAssetExportSession 和最高质量预设将慢动作视频的 AVComposition 导出到临时目录,然后使用生成的文件创建一个 AVURLAsset 以用于我的合成。我可以确认这个最初导出的视频也有音频失真。我正在做的就是尝试导出我从 PHAsset 获取的 AVAsset 而不做任何更改。

我的问题是:如何从用户的库中获取慢动作视频并将其作为 .mov 文件导出到临时目录,以便按预期播放,慢动作片段的音频正确音高变化而不会极度失真?

AVAssetExportSession 只是不能处理这个问题吗?我应该改用 AVAssetWriter 吗?我不确定发布任何代码会有所帮助,因为我所做的只是设置一个临时目录路径和一个 AVAssetExportSession 来导出成功的 AVComposition。

我的应用程序是用 Swift 编写的,但我会用 Objective C 来回答。

avfoundation ios swift

1
推荐指数
1
解决办法
783
查看次数