我试图从一些图片创建一部电影.它适用于高清图片({720,1280})或更低的分辨率.但是当我尝试使用全高清图片{1080,1920}创建电影时,视频会被加扰.这是一个链接,可以看到它的外观http://www.youtube.com/watch?v=BfYldb8e_18.你有什么想法我可能做错了吗?
- (void) createMovieWithOptions:(NSDictionary *) options
{
@autoreleasepool {
NSString *path = [options valueForKey:@"path"];
CGSize size = [(NSValue *)[options valueForKey:@"size"] CGSizeValue];
NSArray *imageArray = [options valueForKey:@"pictures"];
NSInteger recordingFPS = [[options valueForKey:@"fps"] integerValue];
BOOL success=YES;
NSError *error = nil;
AVAssetWriter *assetWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path]
fileType:AVFileTypeQuickTimeMovie
error:&error];
NSParameterAssert(assetWriter);
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithFloat:size.width], AVVideoWidthKey,
[NSNumber numberWithFloat:size.height], AVVideoHeightKey,
nil];
AVAssetWriterInput *videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings];
// Configure settings for the pixel buffer adaptor.
NSDictionary* bufferAttributes …Run Code Online (Sandbox Code Playgroud) 我正在使用a编写带有AVAssetWriter的MP4视频文件AVAssetWriterInputPixelBufferAdaptor.
来源是a的视频UIImagePickerController,可以从相机或资产库中新近捕获.现在质量是UIImagePickerControllerQualityTypeMedium.
有时候作家失败了.它的状态是AVAssetWriterStatusFailed,AVAssetWriter对象的错误属性是:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo=0xf5d8990 {NSLocalizedFailureReason=An unknown error occurred (-536870210),
NSUnderlyingError=0x4dd8e0 "The operation couldn’t be completed. (OSStatus error -536870210.)",
NSLocalizedDescription=The operation could not be completed
Run Code Online (Sandbox Code Playgroud)
错误发生在代码运行的大约20%的时间.它似乎在iPhone 4/4S上比在iPhone 5上更频繁地失败.
如果源视频质量较高,它也会更频繁地出现.使用UIImagePickerControllerQualityTypeLow,错误不会经常发生.使用UIImagePickerControllerQualityTypeHigh,错误更频繁地发生.
我还注意到了其他一些事情:它似乎有点波澜.当它失败时,即使我删除了应用程序并重新安装它,以下运行也经常会失败.这让我想知道,我的程序是否泄漏了一些内存,即使应用程序被杀,该内存是否仍然存活(甚至可能?).
这是我用来渲染视频的代码:
- (void)writeVideo
{
offlineRenderingInProgress = YES;
/* --- Writer Setup --- */
[locationQueue cancelAllOperations];
[self stopWithoutRewinding];
NSError *writerError = nil;
BOOL succes;
succes = [[NSFileManager defaultManager] removeItemAtURL:self.outputURL error:nil];
// DLog(@"Url: %@, …Run Code Online (Sandbox Code Playgroud) 我想修剪一个视频文件.我想从图库中选择视频并将其转换为15秒的视频.如果我使用拾取器视图控制器进行常规修剪,它不会指定时间并只显示帧,但我需要修复15秒.我怎样才能做到这一点?
我正在尝试更改摄像机视图Front和.Back它运行良好Pause/Record.如果Flip Camera View录制的视频没有翻转选项它工作正常.但如果我们曾经,那么进一步录制视频不保存导致AVAssetWriterStatusFailed- The operation could not be completed.任何人都可以帮我找到我出错的地方吗?以下是我的代码.
Run Code Online (Sandbox Code Playgroud)- (void)flipCamera{ NSArray * inputs = _session.inputs; for ( AVCaptureDeviceInput * INPUT in inputs ) { AVCaptureDevice * Device = INPUT.device ; if ( [ Device hasMediaType : AVMediaTypeVideo ] ) { AVCaptureDevicePosition position = Device . position ; AVCaptureDevice * newCamera = nil ; AVCaptureDeviceInput * newInput = nil ; if ( position == AVCaptureDevicePositionFront ) newCamera = …
我试图反过来制作视频.在AVPlayer中播放资源时,我设置rate = -1以使其以反向格式工作.但如何导出该视频?我查看了文档.阅读有关avassetwrite,sambuffers,作品,但没有找到任何方法来做到这一点.以下链接由我提供
http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
反向视频演示 - https://github.com/mikaelhellqvist/ReverseClip
以上示例不再适用于IOS 8.甚至它不会反转音频.如果有人给我一些暗示,那么我可以做进一步.我在过去的5天里被困在这里但在文档中没有找到任何答案.
video avfoundation avassetwriter avmutablecomposition avassetreader
我目前正在制作一个小应用程序,将我的mac上的网络摄像头延时,将捕获的帧保存到png,我正在考虑将捕获的帧导出为单个视频.
我使用CGImage来处理原始图像,并将它们设置在一个数组中,但我不确定那里是从那里开始的.我从自己的研究中得知,我必须以某种方式使用AVAssetWriter和AVAssetWriterInput.
我在这里看了一下,阅读了苹果文档并搜索了谷歌.但是所有的指南等都是obj-c而不是swift,这使得它很难理解(因为我没有Obj-C的经验).
任何帮助将非常感谢.
非常感谢,卢克.
我用 录制视频AVAssetWriter。用户可以发送视频,然后我打电话finishWriting,或者取消录制,然后我打电话cancelWriting。
我如何记录:
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!){
guard !message_to_send else{
return
}
guard is_recording else{
return
}
guard CMSampleBufferDataIsReady(sampleBuffer) else{
print("data not ready")
return
}
guard let w=file_writer else{
print("video writer nil")
return
}
guard let sb=sampleBuffer else{
return
}
if w.status == .unknown /*&& start_recording_time==nil*/{
if captureOutput==video_output{
print("\nSTART RECORDING")
w.startWriting()
start_recording_time=CMSampleBufferGetPresentationTimeStamp(sb)
w.startSession(atSourceTime: start_recording_time!)
}else{
return
}
}
if w.status == .failed{
print("failed with error:", w.error ?? "") …Run Code Online (Sandbox Code Playgroud) 我试图从提取音轨.mp4的视频文件,并转换成.m4a音频文件,这个outputSettings使用AVAssetWriter类
AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:2], AVNumberOfChannelsKey,
[NSNumber numberWithInt:128000], AVEncoderBitRateKey, // 128 kbps
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
nil];
Run Code Online (Sandbox Code Playgroud)
案例1:带有音轨参数的.mp4视频文件(打印用CMFormatDescriptionRef):
mediaType:'soun'
mediaSubType:'aac '
mSampleRate: 44100.000000
mFormatID: 'aac '
mChannelsPerFrame: 2
ACL: {Stereo (L R)}
Run Code Online (Sandbox Code Playgroud)
结果:成功创建.m4a具有已定义输出参数的输出文件
案例2:带有音轨参数的.mp4视频文件(打印方式CMFormatDescriptionRef):
mediaType:'soun'
mediaSubType:'aac '
mSampleRate: 48000.000000
mFormatID: 'aac '
mChannelsPerFrame: 6
ACL: …Run Code Online (Sandbox Code Playgroud) objective-c avfoundation ios avassetwriter avassetwriterinput
这是我之前未回答的问题的扩展:AVCaptureSession is not Recording audio from the mic in Swift
我非常不清楚如何编写实时修改的视频和从麦克风录制的音频。我已经寻找了几个月,但一无所获。似乎使我的问题与其他问题区分开来的是,我在 captureOutput 函数中从sampleBuffer 获取图像缓冲区,将其转换为图像,修改它,然后将其写回 AVAssetWriterInputPixelBufferAdaptor,而不是将输出中的所有内容记录为正常视频。从这里开始,我不知道如何从sampleBuffer获取音频,或者这是否是正确的方法,尽管我已经看到其他人从captureOutput获取AudioBufferList。
至少,这是我在主课上的内容:
class CaptureVC: UIViewController, AVCapturePhotoCaptureDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIPickerViewDataSource,UIPickerViewDelegate {
var captureSession: AVCaptureSession?
var stillImageOutput: AVCapturePhotoOutput?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
let videoOutput = AVCaptureVideoDataOutput()
let audioOutput = AVCaptureAudioDataOutput()
var assetWriter: AVAssetWriter?
var assetWriterPixelBufferInput: AVAssetWriterInputPixelBufferAdaptor?
var assetWriterAudioInput: AVAssetWriterInput?
var currentSampleTime: CMTime?
var currentVideoDimensions: CMVideoDimensions?
var videoIsRecording = false
override func viewDidLoad() {
super.viewDidLoad()
let backCamera = AVCaptureDevice.default(for:AVMediaType.video)
let microphone = AVCaptureDevice.default(.builtInMicrophone, for: AVMediaType.audio, position: .unspecified)
var …Run Code Online (Sandbox Code Playgroud) iPhone 12/12 pro 支持以 10 位格式而不是 8 位格式录制杜比视觉 HDR 视频,但从 iOS 14.1 SDK 中不清楚 AVCaptureVideoDataOutput 是否支持传送 10 位样本缓冲区,这些缓冲区可以使用 AVAssetWriter 附加到视频文件。有没有人想过在SDK中是否可能?
编辑:许多应用程序(例如 Apple 的 Clips 应用程序)已开始支持 Dolby Vision 10 位视频录制。但是我尝试了所有可用的 API,包括 videoHDREnabled,但它不起作用。所以明确的问题是如何使用 AVFoundation API 录制 HDR(杜比视觉)视频?
EDIT2:我能够找出支持 10 位像素缓冲区格式的设备格式(即“x420”,而不是将 420v 或 420f 作为媒体子类型的设备格式)。在 iPhone 12 mini 上,4 种设备格式支持kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange 中的10 位像素缓冲区传送,尽管 AVFoundation 文档说这不是支持的像素格式(引用 - “在 iOS 上,唯一支持的键是 kCVPixelBufferPixelFormatTypeKey。支持的像素格式是 kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange,kCVPixelBufferPixelFormatTypeKey。和 kCVPixelFormatType_32BGRA .”)。下一步是确定是否可以手动选择用于录制的 HDR 格式为 Dolby Vision、HLG 或 HDR10。
avfoundation ios avcapturesession avassetwriter avcapturevideodataoutput
avassetwriter ×10
avfoundation ×5
ios ×5
objective-c ×3
swift ×3
avasset ×2
iphone ×2
cocoa-touch ×1
ios5 ×1
macos ×1
mobile ×1
video ×1