Ijkplayer: iOS IJKPlayer如何 转换画面的方向?

Created on 22 May 2017  ·  2Comments  ·  Source: bilibili/ijkplayer

如题,就是想改变 画面的方向,接收的是RTMP 流.但是不得方法,望指教

Most helpful comment

想变的话也可以变 稍微用点黑科技就行了 方法就是 先获取视频地址的视频方向 然后根据视频的方向 如果是90度旋转的 就把你展示ijk的画面的frame 的高和宽对调一下 然后改变一下这个控件的垂直方向 就可以了

我就是用这种方法解决的这个问题 虽然有点繁琐 但是效果满足需求了

//先获取视频地址的旋转方向
NSInteger rotationNumber = [self degressFromVideoFileWithURL:model.url];

//判断旋转角度
if (rotationNumber == 90) {

 playerView.frame = CGRectMake(playerView.frame.origin.x,playerView.frame.origin.y, self.bounds.size.height, self.bounds.size.width);

 playerView.transform = CGAffineTransformMakeRotation(M_PI_2);

 playerView.frame = CGRectMake(0,0, playerView.frame.size.width, playerView.frame.size.height);

}else{

 playerView.frame = self.bounds;
}

//获取视频URL的旋转方向

  • (NSUInteger)degressFromVideoFileWithURL:(NSURL *)url
    {
    NSUInteger degress = 0;
AVAsset *asset = [AVAsset assetWithURL:url];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([tracks count] > 0) {
    AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
    CGAffineTransform t = videoTrack.preferredTransform;

    if(t.a == 0 && t.b == 1.0 && t.c == -1.0 && t.d == 0){
        // Portrait
        degress = 90;
    }else if(t.a == 0 && t.b == -1.0 && t.c == 1.0 && t.d == 0){
        // PortraitUpsideDown
        degress = 270;
    }else if(t.a == 1.0 && t.b == 0 && t.c == 0 && t.d == 1.0){
        // LandscapeRight
        degress = 0;
    }else if(t.a == -1.0 && t.b == 0 && t.c == 0 && t.d == -1.0){
        // LandscapeLeft
        degress = 180;
    }
}

return degress;

}

All 2 comments

IJKPlayer 是个播放器,画面的方向 也取决于 录制或者推流端的 视频方向,之前我是使用LFLiveKit 框架进行推流的,画面是竖屏录制的,然而我居然想在播发器这边把它转过来,也是傻的可以,哈哈.
最后在录屏端 LFLiveKit 那边找到横屏录制的方法.所以这个问题关了.

想变的话也可以变 稍微用点黑科技就行了 方法就是 先获取视频地址的视频方向 然后根据视频的方向 如果是90度旋转的 就把你展示ijk的画面的frame 的高和宽对调一下 然后改变一下这个控件的垂直方向 就可以了

我就是用这种方法解决的这个问题 虽然有点繁琐 但是效果满足需求了

//先获取视频地址的旋转方向
NSInteger rotationNumber = [self degressFromVideoFileWithURL:model.url];

//判断旋转角度
if (rotationNumber == 90) {

 playerView.frame = CGRectMake(playerView.frame.origin.x,playerView.frame.origin.y, self.bounds.size.height, self.bounds.size.width);

 playerView.transform = CGAffineTransformMakeRotation(M_PI_2);

 playerView.frame = CGRectMake(0,0, playerView.frame.size.width, playerView.frame.size.height);

}else{

 playerView.frame = self.bounds;
}

//获取视频URL的旋转方向

  • (NSUInteger)degressFromVideoFileWithURL:(NSURL *)url
    {
    NSUInteger degress = 0;
AVAsset *asset = [AVAsset assetWithURL:url];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([tracks count] > 0) {
    AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
    CGAffineTransform t = videoTrack.preferredTransform;

    if(t.a == 0 && t.b == 1.0 && t.c == -1.0 && t.d == 0){
        // Portrait
        degress = 90;
    }else if(t.a == 0 && t.b == -1.0 && t.c == 1.0 && t.d == 0){
        // PortraitUpsideDown
        degress = 270;
    }else if(t.a == 1.0 && t.b == 0 && t.c == 0 && t.d == 1.0){
        // LandscapeRight
        degress = 0;
    }else if(t.a == -1.0 && t.b == 0 && t.c == 0 && t.d == -1.0){
        // LandscapeLeft
        degress = 180;
    }
}

return degress;

}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaogu-space picture xiaogu-space  ·  3Comments

lingchen52 picture lingchen52  ·  3Comments

MRsJackYang picture MRsJackYang  ·  4Comments

zhangkom picture zhangkom  ·  3Comments

yuyashuai picture yuyashuai  ·  3Comments