我将AVVideoAverageBitRateKey设置为900000,但是我录制的视频获得了不同的比特率值。总是不同的值,有时850k,有时780k,810k,从不900k。为什么?
这是我所做的设置:
NSNumber *compression = [NSNumber numberWithLong:900000];
AVAsset *videoAsset = [[AVURLAsset alloc] initWithURL:inputURL options:nil];
AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGSize videoSize = videoTrack.naturalSize;
NSDictionary *videoWriterCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:compression, AVVideoAverageBitRateKey, nil];
NSDictionary *videoWriterSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264,
AVVideoCodecKey, videoWriterCompressionSettings,
AVVideoCompressionPropertiesKey, [NSNumber numberWithFloat:videoSize.width],
AVVideoWidthKey, [NSNumber numberWithFloat:videoSize.height],
AVVideoHeightKey, nil];
AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoWriterSettings];
videoWriterInput.expectsMediaDataInRealTime = YES;
videoWriterInput.transform = videoTrack.preferredTransform;
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:outputURL fileType:AVFileTypeQuickTimeMovie error:nil];
[videoWriter addInput:videoWriterInput];
最佳答案
尚无人回答,但复活在这里。比特率是一个复杂的值,与视频方程式中的其他各个变量成比例-与帧速率,分辨率和其他因素有关。使用的编解码器。恒定比特率还是可变比特率?等等。其中一些因素本身将产生有限的影响,这些影响会传递到最终观察到的平均比特率。请注意,您用于指定比特率的键称为AVVideoAverageBitRateKey
-平均值,而不是固定值。要求比特率就像要求数字一样,结果应该接近您所要求的,但可能并不完全相同。