【问题标题】:AVPlayer rotates portrait video to landscapeAVPlayer 将纵向视频旋转为横向
【发布时间】:2015-04-29 23:00:55
【问题描述】:

我正在使用 AVcapture 录制视频并在 AVplayer 中播放。

    NSURL *videoUrl1 = [self.mediaInfo objectAtIndex:0];
AVURLAsset *videoAsset1 = [AVURLAsset URLAssetWithURL:videoUrl1 options:nil];
NSURL *videoUrl2 = [self.mediaInfo objectAtIndex:1];
AVURLAsset *videoAsset2 = [AVURLAsset URLAssetWithURL:videoUrl2 options:nil];
AVAssetTrack *videoTrack1 = [[videoAsset1 tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];
AVAssetTrack *videoTrack2 = [[videoAsset2 tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];

两个音轨放在一起:

     [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video1) ofTrack:videoTrack1 atTime:kCMTimeZero error:nil];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, video2) ofTrack:videoTrack2 atTime:(compositionVideoTrack.timeRange.duration) error:nil];

玩过:

    AVPlayerItem * newPlayerItem = [AVPlayerItem playerItemWithAsset:self.composition];
//newPlayerItem.videoComposition = mainCompositionInst;
self.mediaPlayer = [AVPlayer playerWithPlayerItem:newPlayerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.mediaPlayer];
[[self view].layer insertSublayer:self.playerLayer atIndex:0];
self.playerLayer.frame = [self view].layer.bounds;
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill ;

[self playItem];

奇怪的是,对于完全相同的文件,初始 AVURLAsset 的 preferredTransform 与 A​​VAssetTrack 不同:

AVURLASSET

txf.a = 1.000000 txf.b = 0.000000 txf.c = 0.000000 txf.d = 1.000000 txf.tx = 0.000000 txf.ty = 0.000000

AVAssetTrack

txf.a = 0.000000 txf.b = 1.000000 txf.c = -1.000000 txf.d = 0.000000 txf.tx = 480.000000 txf.ty = 0.000000

任何帮助解决这个轮换将不胜感激, 提前致谢。

CL

【问题讨论】:

  • 我也有同样的问题。你能说说你是怎么解决的吗?
  • 解决这个问题非常困难,我建议阅读所有这些以了解 AVfoundation link 的原理另外,请注意,根据操作系统和手机型号,您会得到不同的结果,所以在在这种情况下,我必须确定手机型号并应用必要的转换。祝你好运!

标签: ios rotation orientation avplayer avasset


【解决方案1】:

创建视频合成

vidComposition = [AVMutableVideoComposition videoComposition];

设置vidComposition.instructions = mainInstruction (AVMutableVideoCompositionInstruction) 用 AVPlayer 编辑视频播放后

取消注释 newPlayerItem.videoComposition = mainCompositionInst; 并设置 vidComposition 而不是 mainCompositionInst。 newPlayerItem.videoComposition = vidComposition;

对于编辑视频,本教程可能会对您有所帮助。 raywenderlich.com/13418/how-to-play-record-edit-videos-in-io‌​s

我希望这会有所帮助。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 2012-09-11
  • 1970-01-01
相关资源
最近更新 更多