4

Does anybody knows how to use an AVAssetWriter in AVFoundation to store uncompressed frames into a mov ? I'm actually using the following snippets for ProRes4444 contents:

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   AVVideoCodecAppleProRes4444, AVVideoCodecKey,
                                   widthNum, AVVideoWidthKey,
                                   heightNum, AVVideoHeightKey,
                                   nil];
assetWriterInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain];

Reading from the AVAssetWriter headers, is says to use kCVPixelFormat constants from core video constants, I've tried the following:

kCVPixelFormatType_32RGBA,AVVideoCodecKey

But it does not seem to work. Anyone has some hints on this topics ?

thanks a lot !

Leonardo Bernardini
  • 1,076
  • 13
  • 23
  • I was wondering if you managed to do this? – Tzar Dec 13 '17 at 22:15
  • 1
    yes 5 years ago but I do not have access to the source code anymore... I was able to find the correct flags with trials and errors... – Leonardo Bernardini Dec 14 '17 at 09:26
  • One more question: were you able to record in ProRes or Animation format? I just need to know if such encoding is possible on iOS, as I can’t find anyone doing this. – Tzar Dec 14 '17 at 13:21
  • I worked on Mac os X, animation was not possible through AV Foundations it's a legacy codec supported only by Quicktime. ProRes is possible on Mac OS X but I do not think it's supported on iOS because it lacks HW acceleration, as far as I know iOS devices only accelerates H264 encoding (maybe H265 on the latest( – Leonardo Bernardini Dec 14 '17 at 20:46
  • Thanks! See my question here: https://stackoverflow.com/questions/47651412/how-to-record-video-in-prores-codec-on-ios – Tzar Dec 14 '17 at 21:00

2 Answers2

1

kCVPixelFormatType_32RGBA is not a codec type, it is a pixel format.

These are the supported codecs. I am not sure if kCMVideoCodecType_422YpCbCr8 is the uncompressed option or not but kCMVideoCodecType_Animation should do the job otherwise. It uses lossless compression (similar to zipping a file and then restoring it without any loss of quality).

BlueVoodoo
  • 3,626
  • 5
  • 29
  • 37
  • Yes, I know the apple animation codec, that's exactly what I was looking for, but it seams I'm not able to wrap the constant into the dictionary AVAssetWriter expects. I've tried it as a string, wrapped into an NSNumber , but no way, the compression fails. I'm passing it as the value of AVVideoCodecKey constant. Do you have a working code example ? – Leonardo Bernardini Sep 27 '12 at 22:28
  • Note that YUV is not lossless, this is a conversion from RGB to YUV colorspace that throws away 1/2 the information in the UV channels. – MoDJ Sep 10 '18 at 21:12
0

If you need very high quality video you can set the the keyframe rate to 1 and set the bitrate really high. All frames will be key frames so you can 'scrub' the video if you wanted to. You will not loose much information if any at all. Also look at the AVCaptureSessionPresetiFrame960x540 and other in AVCaptureSession.h. Here is the description for the one I mentioned

@constant AVCaptureSessionPresetiFrame960x540
@abstract
    An AVCaptureSession preset producing 960x540 Apple iFrame video and audio content.

@discussion
    Clients may set an AVCaptureSession instance's sessionPreset to AVCaptureSessionPresetiFrame960x540
    to achieve 960x540 quality iFrame H.264 video at ~30 Mbits/sec with AAC audio.  QuickTime
    movies captured in iFrame format are optimal for editing applications.
Steve McFarlin
  • 3,576
  • 1
  • 25
  • 24