我们正在尝试导出视频并保持其FPS。发生了什么事
对于1秒钟的视频剪辑示例:
我们想要的-在所有情况下均可导出以匹配相机胶卷FPS。我们也在压缩视频。
我们尝试通过查看以下内容和其他内容来解决问题:
How do I control AVAssetWriter to write at the correct FPS
How to set expected framerate to AVAssetWriterInput
我猜我们可能需要一种完全不同的方法-尚未解决-这是用于尝试上传设置为以原始速度播放的240 fps视频的代码-结果为30 fps 1第二个视频(而不是240 fps的1秒视频):
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
options.version = PHVideoRequestOptionsVersionCurrent;
[[PHImageManager defaultManager] requestAVAssetForVideo:_phasset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix *
_Nullable audioMix, NSDictionary * _Nullable info)
{
if(([asset isKindOfClass:[AVComposition class]] && ((AVComposition *)asset).tracks.count == 2)) {
SDAVAssetExportSession *encoder = [[SDAVAssetExportSession alloc] initWithAsset:asset];
encoder.outputFileType = AVFileTypeQuickTimeMovie;
encoder.outputURL = url;
encoder.videoSettings = @
{
AVVideoCodecKey: AVVideoCodecH264,
AVVideoWidthKey: [NSNumber numberWithInteger:newWidth],
AVVideoHeightKey: [NSNumber numberWithInteger:newHeight],
AVVideoCompressionPropertiesKey: @
{
// AVVideoAverageBitRateKey: [NSNumber numberWithInteger:bitrate * 1024],
AVVideoAverageBitRateKey: [NSNumber numberWithInteger:bitrate * 1024],
AVVideoProfileLevelKey: AVVideoProfileLevelH264High40,
// AVVideoMaxKeyFrameIntervalKey: [NSNumber numberWithInt:240],
AVVideoExpectedSourceFrameRateKey: [NSNumber numberWithInteger:240]
},
};
encoder.audioSettings = @
{
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey: @1,
AVSampleRateKey: @44100,
AVEncoderBitRateKey: @128000,
};
[encoder exportAsynchronouslyWithCompletionHandler:^{
if (encoder.status == AVAssetExportSessionStatusCompleted) {
NSURL *URL = encoder.outputURL;
// exported video's fps is not 240 fps on here
}
}];
} else {
…
}
}
关于如何修复当前代码的任何建议-或如何以其他可行的方式进行处理?