即时通讯尝试捕获帧缓冲区数据并转换为我的iPhone游戏的视频..即时通讯使用AVAssetWriter来完成这件事.代码在模拟器上工作正常,但在设备本身没有.在设备上它生成一个黑色视频
即时通讯使用以下代码:
//This code initializes the AVAsetWriter and other things
- (void) testVideoWriter {
CGRect screenBoundst = [[UIScreen mainScreen] bounds];
//initialize global info
MOVIE_NAME = @"Documents/Movie5.mp4";
//CGSize size = CGSizeMake(screenBoundst.size.width, screenBoundst.size.height);
CGSize size = CGSizeMake(320, 480);
frameLength = CMTimeMake(1, 5);
currentTime = kCMTimeZero;
currentFrame = 0;
MOVIE_PATH = [NSHomeDirectory() stringByAppendingPathComponent:MOVIE_NAME];
NSError *error = nil;
videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:MOVIE_PATH]
fileType:AVFileTypeMPEG4 error:&error];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:size.width ], AVVideoWidthKey,
[NSNumber numberWithInt:size.height ], AVVideoHeightKey, nil];
writerInput = [AVAssetWriterInput …Run Code Online (Sandbox Code Playgroud) 我正在使用glReadPixels将数据读入CVPixelBufferRef.我用它CVPixelBufferRef作为输入AVAssetWriter.不幸的是,像素格式似乎不匹配.
我认为glReadPixels返回RGBA格式的AVAssetWriter像素数据,同时想要ARGB格式的像素数据.将RGBA转换为ARGB的最佳方法是什么?
这是我到目前为止所尝试的:
CGImageRef作为中间步骤位操作不起作用,因为CVPixelBufferRef似乎不支持下标.该CGImageRef中间步骤做的工作......但我不希望有代码50条额外的线路,有可能正影响性能.
我正在创建一个Quicktime电影文件AVAssetWriter.目前输出视频是"倒置".理论上,我可以通过围绕水平轴旋转180度(基本上"翻转"视频)来纠正这个问题.最好的方法是什么?
我目前正试图以分配CGAffineTransform给myAVAssetWriterInput.transform.也许CGAffineTransformMake(a, b, c, d, tx, ty)会允许我指定正确的仿射变换矩阵?
我正在开发一个项目,我在其中生成一个来自UIImage的视频,我在这里找到了代码,为了优化它,我现在正在苦苦挣扎几天(对于大约300张图片,在模拟器上需要5分钟,并且因为内存而简单地在设备上崩溃了.
我将从今天的工作代码开始(我使用arc):
-(void) writeImageAsMovie:(NSArray *)array toPath:(NSString*)path size:(CGSize)size duration:(int)duration
{
NSError *error = nil;
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path] fileType:AVFileTypeQuickTimeMovie error:&error];
NSParameterAssert(videoWriter);
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:size.width], AVVideoWidthKey,
[NSNumber numberWithInt:size.height], AVVideoHeightKey,
nil];
AVAssetWriterInput* writerInput = [AVAssetWriterInput
assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings];
AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:nil];
NSParameterAssert(writerInput);
NSParameterAssert([videoWriter canAddInput:writerInput]);
[videoWriter addInput:writerInput];
//Start a session:
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:kCMTimeZero];
CVPixelBufferRef buffer = NULL;
buffer = [self newPixelBufferFromCGImage:[[self.frames objectAtIndex:0] CGImage]];
CVPixelBufferPoolCreatePixelBuffer (NULL, adaptor.pixelBufferPool, &buffer);
[adaptor appendPixelBuffer:buffer withPresentationTime:kCMTimeZero];
dispatch_queue_t mediaInputQueue …Run Code Online (Sandbox Code Playgroud) 我正在尝试同时读写由AVAssetWriter编写的H.264 mov文件.我设法提取单个NAL单元,将它们打包到ffmpeg的AVPackets中,并使用ffmpeg将它们写入另一种视频格式.它的工作原理和生成的文件播放效果很好,但播放速度不正确.如何从原始H.264数据计算正确的PTS/DTS值?或者也许还有其他方法可以获得它们?
这是我尝试过的:
将捕获最小/最大帧速率限制为30,并假设输出文件为30 fps.事实上,它的fps总是小于我设定的值.而且,我认为fps在数据包之间并不是一成不变的.
记住每个书面样本的表示时间戳,并假设样本一对一映射到NALU并将保存的时间戳应用于输出数据包.这不起作用.
将PTS设置为0或AV_NOPTS_VALUE.不行.
从谷歌搜索我了解原始H.264数据通常不包含任何时间信息.它有时在SEI中有一些时间信息,但我使用的文件没有它.另一方面,有些应用程序正是我正在尝试做的事情,所以我认为它可能以某种方式.
当我使用AVCaptureVideoDataOutput和AVCaptureAudioDataOutput录制音频+视频时,我遇到了延迟问题.有时视频会阻塞几毫秒,有时音频与视频不同步.
我插入了一些日志并观察到我首先在captureOutput回调中获得了大量视频缓冲区,并且在一段时间后我得到了音频缓冲区(有时我根本没有收到音频缓冲区,结果视频没有声音).如果我评论处理视频缓冲区的代码,我会毫无问题地获得音频缓冲区.
这是我正在使用的代码:
-(void)initMovieOutput:(AVCaptureSession *)captureSessionLocal
{
AVCaptureVideoDataOutput *dataOutput = [[AVCaptureVideoDataOutput alloc] init];
self._videoOutput = dataOutput;
[dataOutput release];
self._videoOutput.alwaysDiscardsLateVideoFrames = NO;
self._videoOutput.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange]
forKey:(id)kCVPixelBufferPixelFormatTypeKey
];
AVCaptureAudioDataOutput *audioOutput = [[AVCaptureAudioDataOutput alloc] init];
self._audioOutput = audioOutput;
[audioOutput release];
[captureSessionLocal addOutput:self._videoOutput];
[captureSessionLocal addOutput:self._audioOutput];
// Setup the queue
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
[self._videoOutput setSampleBufferDelegate:self queue:queue];
[self._audioOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
}
Run Code Online (Sandbox Code Playgroud)
在这里我设置了作者:
-(BOOL) setupWriter:(NSURL *)videoURL session:(AVCaptureSession *)captureSessionLocal
{
NSError *error = nil;
self._videoWriter = [[AVAssetWriter alloc] initWithURL:videoURL fileType:AVFileTypeQuickTimeMovie
error:&error];
NSParameterAssert(self._videoWriter);
// …Run Code Online (Sandbox Code Playgroud) 我知道AVVideoCompositionCoreAnimationTool使用Core动画的方法,并且我使用了它AVMutableComposition,但我正在寻找一种方法来完成相同的动画AVAssetWriter.基本上我想创建CAAnimation(s)并使用AVAssetWriter缓冲时间戳作为动画计时方法.然后为每个帧拉动画属性.
这有可能吗?任何指导正确的方向将不胜感激.
编辑:如果你想知道为什么不只是使用AVAssetExportSession,那是因为我的要求阻止我使用压缩预设,而且我需要CIFilter使用目前无法CALayer在iOS上使用s的s.
我们正在使用AVAssetReader和使用AVAssetWriter的视频编码中AVAssetWriter提到的样式- CRASHES基本上是从视频库/资产库中读取视频,然后以不同的比特率写入以减小其大小(用于最终的网络上传) .
让它为我们工作的诀窍是kCVPixelBufferPixelFormatTypeKey在outputSettingson中指定一个键和值AVAssetReaderTrackOutput,如下所示:
NSDictionary *outputSettings = [NSDictionary
dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
readerTrackOutput =
[[AVAssetReaderTrackOutput alloc] initWithTrack:src_track
outputSettings:outputSettings];
Run Code Online (Sandbox Code Playgroud)
所以基本上我们使用kCVPixelFormatType_32BGRA了kCVPixelBufferPixelFormatTypeKey键的值.
但显然我们可以选择许多可能的像素格式类型.在iOS 6.0.1 iPhone设备上运行技术问答QA1501:核心视频 - 可用像素格式中记录的代码,以下是它显示的支持像素格式类型列表:
Core Video Supported Pixel Format Types:
Core Video Pixel Format Type: 32
Core Video Pixel Format Type: 24
Core Video Pixel Format Type: 16
Core Video Pixel Format Type (FourCC): L565
Core Video Pixel Format Type (FourCC): 2vuy …Run Code Online (Sandbox Code Playgroud) 我有一些文件,-m4a -mp4 -mp3等我想更改这些细节
AVMetadataItem AVMetadataCommonKeyArtworkAVMetadataCommonKeyArtist 我可以做AVAssetExportSession,但我需要更改目录.有没有办法直接在文件上写?
我找到了这个程序,但不起作用:(
NSError *error;
AVAssetWriter *assetWrtr = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:self.path] fileType:AVFileTypeAppleM4A error:&error];
NSLog(@"%@",error);
NSArray *existingMetadataArray = assetWrtr.metadata;
NSMutableArray *newMetadataArray = nil;
if (existingMetadataArray)
{
newMetadataArray = [existingMetadataArray mutableCopy]; // To prevent overriding of existing metadata
}
else
{
newMetadataArray = [[NSMutableArray alloc] init];
}
AVMutableMetadataItem *item = [[AVMutableMetadataItem alloc] init];
item.keySpace = AVMetadataKeySpaceCommon;
item.key = AVMetadataCommonKeyArtwork;
item.value = UIImagePNGRepresentation([[UIImage alloc] initWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@".image"]]);
[newMetadataArray addObject:item];
assetWrtr.metadata = newMetadataArray; …Run Code Online (Sandbox Code Playgroud) 我一直在网上浏览所有内容,但似乎找不到所需的教程或帮助。
使用AVFoundation和Dlib库,我创建了一个应用程序,可以使用手机上的前置摄像头从实时视频中检测人脸。我正在使用Shape Predictor 68 Face Landmarks 执行此操作。为此,我敢肯定我必须使用AVCaptureVideoDataOutputAVMovieFileOutput而不是AVMovieFileOutput,以便可以分析每个帧。
现在,我希望能够将视频保存到文件中,并根据收集的信息AVAssetWriter来执行此操作。我只是在任何地方都找不到太多有关如何开始使用此方法的信息。我对Swift和iOS编程是完全陌生的,并且从Apple文档中不能真正了解很多。
如果有人可以帮助我,将不胜感激!
avassetwriter ×10
ios ×8
avfoundation ×2
iphone ×2
objective-c ×2
video ×2
core-video ×1
ffmpeg ×1
glreadpixels ×1
h.264 ×1
ipad ×1
quicktime ×1
swift ×1
swift4 ×1
xcode ×1