diff --git a/AVF Batch Converter/Info.plist b/AVF Batch Converter/Info.plist index 247af91..4160241 100644 --- a/AVF Batch Converter/Info.plist +++ b/AVF Batch Converter/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleGetInfoString - 1.6.6 + 1.6.7 CFBundleIconFile CFBundleIdentifier @@ -19,11 +19,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.6.6 + 1.6.7 CFBundleSignature ???? CFBundleVersion - 1.6.6 + 1.6.7 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/AVF Batch Converter/VVAVFTranscoder.m b/AVF Batch Converter/VVAVFTranscoder.m index 25b7a1c..f436d9a 100644 --- a/AVF Batch Converter/VVAVFTranscoder.m +++ b/AVF Batch Converter/VVAVFTranscoder.m @@ -251,6 +251,21 @@ - (void) transcodeFileAtPath:(NSString *)src toPath:(NSString *)dst { NSString *exportCodecString = [baseVideoExportSettings objectForKey:AVVideoCodecKey]; //OSType exportCodec = (exportCodecString==nil) ? 0 : VVPackFourCC_fromChar((char *)[exportCodecString UTF8String]); //OSType trackCodec = CMFormatDescriptionGetMediaSubType(trackFmt); + + // if the export settings specify a resolution, and that resolution doesn't match this track's resolution, we need to perform the transcode step + CMFormatDescriptionRef trackFmt = (CMFormatDescriptionRef)[formatDescriptions objectAtIndex:0]; + NSNumber *tmpNum = nil; + NSSize exportSize = NSMakeSize(-1,-1); + CMVideoDimensions vidDims = CMVideoFormatDescriptionGetDimensions(trackFmt); + NSSize trackSize = NSMakeSize(vidDims.width, vidDims.height); + tmpNum = [baseVideoExportSettings objectForKey:AVVideoWidthKey]; + exportSize.width = [tmpNum doubleValue]; + tmpNum = [baseVideoExportSettings objectForKey:AVVideoHeightKey]; + exportSize.height = [tmpNum doubleValue]; + if (exportSize.width>0 && exportSize.height>0 && !NSEqualSizes(exportSize,trackSize)) { + transcodeThisTrack = YES; + } + // if the export settings don't specify a codec, skip the transcode on the track if (exportCodecString==nil) { //NSLog(@"\t\texport directions explicitly state to skip transcode on track %@",trackPtr); diff --git a/HapInAVFoundation/AVAssetWriterHapInput.h b/HapInAVFoundation/AVAssetWriterHapInput.h index 3e07467..2711f46 100644 --- a/HapInAVFoundation/AVAssetWriterHapInput.h +++ b/HapInAVFoundation/AVAssetWriterHapInput.h @@ -36,8 +36,8 @@ This class is the main interface for using AVFoundation to encode and output vid NSSize exportDXTImgSize; // 'exportImgSize' rounded up to a multiple of 4 unsigned int exportChunkCounts[2]; BOOL exportHighQualityFlag; // NO by default, YES if the quality slider is > .8 in hap or hap alpha codecs - size_t exportSliceCount; - size_t exportSliceHeight; + size_t exportSliceCount; // 1 by default/if slicing is disabled. if slicing is enabled, this is the # of slices. + size_t exportSliceHeight; // calculated using image height + slice count. the number of rows of pixels in a slice. OSType encoderInputPxlFmts[2]; // the encoder wants pixels of a particular format. this is the format they want. uint32_t encoderInputPxlFmtBytesPerRow[2]; // the number of bytes per row in the buffers created to convert to 'encoderInputPxlFmts' diff --git a/HapInAVFoundation/AVAssetWriterHapInput.m b/HapInAVFoundation/AVAssetWriterHapInput.m index 6ce2101..6d4bbb9 100644 --- a/HapInAVFoundation/AVAssetWriterHapInput.m +++ b/HapInAVFoundation/AVAssetWriterHapInput.m @@ -1,4 +1,5 @@ #import "AVAssetWriterHapInput.h" +#import #include "HapPlatform.h" #import "HapCodecSubTypes.h" #import "PixelFormats.h" @@ -379,22 +380,58 @@ - (BOOL) appendPixelBuffer:(CVPixelBufferRef)pb withPresentationTime:(CMTime)t a //NSLog(@"%s",__func__); // if there's a pixel buffer to encode, let's take care of that first if (pb!=NULL) { - // lock the base address of the pixel buffer, get a ptr to the raw pixel data- i'll either be converting it or encoding it + // lock the base address of the pixel buffer CVPixelBufferLockBaseAddress(pb,kHapCodecCVPixelBufferLockFlags); + // get the size of the image in the cvpixelbuffer, we need to compare it to the export size to determine if we need to do a resize... + NSSize pbSize = NSMakeSize(CVPixelBufferGetWidth(pb),CVPixelBufferGetHeight(pb)); + + // get a ptr to the raw pixel data- i'll either be resizing/converting it or encoding this ptr. void *sourceBuffer = CVPixelBufferGetBaseAddress(pb); size_t sourceBufferBytesPerRow = CVPixelBufferGetBytesPerRow(pb); + + // allocate the resize buffer if i need it + void *resizeBuffer = nil; + if (!NSEqualSizes(pbSize, exportImgSize)) { + // make a vImage struct for the pixel buffer we were passed + vImage_Buffer pbImage = { + .data = sourceBuffer, + .height = pbSize.height, + .width = pbSize.width, + .rowBytes = sourceBufferBytesPerRow + }; + // make the resize buffer + size_t resizeBufferSize = encoderInputPxlFmtBytesPerRow[0] * exportImgSize.height; + resizeBuffer = CFAllocatorAllocate(_HIAVFMemPoolAllocator, resizeBufferSize, 0); + // make a vImage struct for the resize buffer we just allocated + vImage_Buffer resizeImage = { + .data = resizeBuffer, + .height = exportImgSize.height, + .width = exportImgSize.width, + .rowBytes = encoderInputPxlFmtBytesPerRow[0] + }; + // scale the pixel buffer's vImage to the resize buffer's vImage + vImage_Error vErr = vImageScale_ARGB8888(&pbImage, &resizeImage, NULL, kvImageHighQualityResampling | kvImageDoNotTile); + if (vErr != kvImageNoError) + NSLog(@"\t\terr %ld scaling image in %s",vErr,__func__); + else { + // update the sourceBuffer- we just resized the buffer we were passed, so it should have the same pixel format + sourceBuffer = resizeImage.data; + sourceBufferBytesPerRow = resizeImage.rowBytes; + } + } + + // allocate any format conversion buffers i may need void *_formatConvertBuffers[2]; _formatConvertBuffers[0] = nil; _formatConvertBuffers[1] = nil; void **formatConvertBuffers = _formatConvertBuffers; // this exists because we can't refer to arrays on the stack from within blocks - - // allocate any format conversion buffers i may need for (int i=0; iCFBundlePackageType FMWK CFBundleShortVersionString - 1.5.2 + 1.5.3 CFBundleSignature ???? CFBundleVersion