我在iPhone中錄製了一個視頻,我正在獲取其本地文件URL。有什麼方法可以使用URL將視頻旋轉90度?在iOS中通過90度編程旋轉錄制的視頻
0
A
回答
1
您可以使用AVMutableVideoCompositionLayerInstruction
類在導出會話之前旋轉視頻,並且您可以在其上應用Transform
。
這是方法
[yourlayerInstruction setTransform:CGAffineTransformMakeRotation(M_PI/2) atTime:firstAssets.duration];
這裏是全面實施
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoCompositionInstruction * mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeAdd(firstAsset.duration, secondAsset.duration));
AVMutableVideoCompositionLayerInstruction *firstlayerInstruction = [AVMutableVideoCompositionLayerInstruction
videoCompositionLayerInstructionWithAssetTrack:firstTrack];
// set Trasform Here
[firstlayerInstruction setTransform:CGAffineTransformMakeRotation(M_PI/2) atTime:kCMTimeZero];
[firstlayerInstruction setOpacity:0.0 atTime:firstAsset.duration];
mainInstruction.layerInstructions = [NSArray arrayWithObjects:firstlayerInstruction,nil];;
AVMutableVideoComposition *mainCompositionInst = [AVMutableVideoComposition videoComposition];
mainCompositionInst.instructions = [NSArray arrayWithObject:mainInstruction];
mainCompositionInst.frameDuration = CMTimeMake(1, 30);
mainCompositionInst.renderSize = CGSizeMake(320.0, 480.0);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPreset640x480];
exporter.outputURL=url;
exporter.videoComposition=mainCompositionInst;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(),^
{
[self exportDidFinish:exporter];
});
}];
我希望這將幫助你
+0
它工作正常 –
0
如果使用MPMoviePlayerViewController播放視頻: - 那你可以試試這個, 首先從捆綁使用以下行提取您的網址,
NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"your video" ofType:@"mp4"]];
或者你也可以直接在mpmovieplayerviewcontroller使用本地文件的網址
然後創建MPmovieplayerview控制器的對象,並使用您的視頻文件,如下圖所示: -
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:moviePlayerController.view];
希望它有幫助!
+0
那麼這隻會在播放時旋轉視頻,他希望它在輸出視頻到服務器時進行旋轉。 – iphonic
相關問題
- 1. 視頻視圖旋轉90度在Android
- 2. 上傳到互聯網後錄製的視頻旋轉90度
- 3. 在iOS中將文本旋轉90度
- 4. 在AVPlayerViewController中旋轉視頻90度 - 可能嗎?
- 5. 旋轉CALayer 90度?
- 6. 旋轉臺90度
- 7. CGAffineTransform旋轉90度
- 8. 爲什麼我的視圖在旋轉90度之前旋轉?
- 9. 如何使視頻內的視頻旋轉90度並使其成爲全屏
- 10. 旋轉視圖層次結構90度
- 11. Android - 旋轉Admob視圖90度?
- 12. UIIMage視圖旋轉低於90度
- 13. AVMutableComposition旋轉錄制的視頻
- 14. 在Chrome中旋轉90度的圖像
- 15. 旋轉(90度)的ViewGroup根
- 16. 旋轉NSImageView的CALayer 90度
- 17. Android,如何旋轉視頻90度,但不是SurfaceView
- 18. opencv - 視頻看起來不錯,但幀旋轉90度
- 19. iOS - 視頻不能僅在iOS7上通過iPhone旋轉?
- 20. 從iPhone錄製的視頻旋轉180度的FB,Vimeo,Youtube
- 21. 在C中旋轉PPM圖像90度
- 22. 圖片90度旋轉AVCam
- 23. C#旋轉位圖90度
- 24. 地圖旋轉了90度?
- 25. 如何旋轉TeeChart 90度
- 26. 如何旋轉StageVideo 90度
- 27. 旋轉JLabel 90度爪哇
- 28. 圓球90度旋轉
- 29. 矩形旋轉90度libgdx
- 30. 旋轉GoJs形狀90度
@ Anbu.Karthik我沒有得到任何想法,該怎麼辦呢 –
你如何加載你的視頻AVplayer或MPMoviePlayerViewController –
我必須將它與其他視頻合併並將其發送到服務器 –