gpt4 book ai didi

ios - 在 ios 中解码 h264

转载 作者:可可西里 更新时间:2023-11-01 05:00:19 25 4
gpt4 key购买 nike

我是 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;

我对此完全天真,请帮助...从哪里开始///

谢谢

最佳答案

更简单的解决方案是使用 MPMoviePlayerController。它接收 mov 或 mv4 文件的输入(来自本地文件系统或通过 URL)。

另一种选择是使用 AVPlayer 类。

希望对你有帮助

大卫

关于ios - 在 ios 中解码 h264,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8880084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com