私の iOS アプリでは、EAGLView のコンテンツのビデオを録画しようとしています (カメラの関与はありません)。動画の撮影も問題ありません。録音後、ビデオにいくつかのサウンド トラックを追加し、このビデオを Youtube と facebook で共有する必要があります。私の問題は、iPhone または Mac で再生するとビデオは問題ないのですが、このビデオを YouTube にアップロードすると (Youtube Data Api v3 を使用して)、ビデオが垂直方向に反転または上下逆になることです。
アップロードする前にビデオのフレームを回転させる必要があると思いますが、その方法がわかりません。
どんな助けでも大歓迎です。
ビデオにオーディオトラックを追加するために使用しているコードは次のとおりです。
-(void)prepareVideoForPath:(NSString *)videoPath usingAudio:(NSArray *)audioArray andOutputPath:(NSString *)exportPath{
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
NSURL *videoUrl=[NSURL fileURLWithPath:videoPath];
AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:videoUrl options:optionsDictionary];
AVAssetTrack *FirstAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGAffineTransform firstTransform = FirstAssetTrack.preferredTransform;
AVMutableComposition* mixComposition = [AVMutableComposition composition];
//VideoTrack
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:FirstAssetTrack atTime:kCMTimeZero error:nil];
[compositionVideoTrack setPreferredTransform:firstTransform];
//Audio Track
AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime audioStartTime = kCMTimeZero;
for (NSURL *audioURL in audioArray) {
AVURLAsset *audioAsset = [AVURLAsset URLAssetWithURL:audioURL options:optionsDictionary];
[audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:audioStartTime error:nil];
audioStartTime = CMTimeAdd(audioStartTime, audioAsset.duration);
}
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath];
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"file type %@",_assetExport.outputFileType);
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
// your completion code here
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Mixing complete");
});
}
];
}