[英]decoding h264 in ios
我是AVFoundation和解碼過程的新手。我需要解碼h264視頻文件並在iphone中播放...任何人都可以給我指導。
我不想使用ffmpeg或任何第三方庫來做到這一點。 據我所知使用Avfoundation編碼是可能的...這里是我認為用於編碼但完全不確定的代碼...
float bitsPerPixel;
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(currentFormatDescription);
int numPixels = dimensions.width * dimensions.height;
int bitsPerSecond;
// Assume that lower-than-SD resolutions are intended for streaming, and use a lower bitrate
if ( numPixels < (640 * 480) )
bitsPerPixel = 4.05; // This bitrate matches the quality produced by AVCaptureSessionPresetMedium or Low.
else
bitsPerPixel = 11.4; // This bitrate matches the quality produced by AVCaptureSessionPresetHigh.
bitsPerSecond = numPixels * bitsPerPixel;
NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInteger:dimensions.width], AVVideoWidthKey,
[NSNumber numberWithInteger:dimensions.height], AVVideoHeightKey,
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey,
[NSNumber numberWithInteger:30], AVVideoMaxKeyFrameIntervalKey,
nil], AVVideoCompressionPropertiesKey,
nil];
if ([assetWriter canApplyOutputSettings:videoCompressionSettings forMediaType:AVMediaTypeVideo]) {
assetWriterVideoIn = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo outputSettings:videoCompressionSettings];
assetWriterVideoIn.expectsMediaDataInRealTime = YES;
assetWriterVideoIn.transform = [self transformFromCurrentVideoOrientationToOrientation:self.referenceOrientation];
if ([assetWriter canAddInput:assetWriterVideoIn])
[assetWriter addInput:assetWriterVideoIn];
else {
NSLog(@"Couldn't add asset writer video input.");
return NO;
}
}
else {
NSLog(@"Couldn't apply video output settings.");
return NO;
}
return YES;
我對此完全天真,請幫助......從哪里開始///
謝謝
您可以參考並構建官方示例代碼: AVPlayerDemo以查看其工作原理。 它使用AV Foundation框架,主要是AVPlayer API來播放視頻文件而且性能非常出色。 要通過AVPlayerDemo播放視頻文件,您應該通過itunes將視頻文件復制到iOS設備,並在AVPlayerDemo應用程序上選擇iPod庫。
更簡單的解決方案是使用MPMoviePlayerController。 它接收輸入mov或mv4文件(來自本地文件系統或通過URL)。
另一種選擇是使用AVPlayer類。
希望能幫助到你,
大衛
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.