合并具有不同视频尺寸的视频,并在合并后更改视频方向 [英] Merge the videos with different video dimensions and change the video orientation after merging

查看:144
本文介绍了合并具有不同视频尺寸的视频,并在合并后更改视频方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I)在合并之前,我们从阵列中获取视频网址(静态视频或摄像头拍摄的视频),然后将其存储到资源中。



II)在将URL存储到资产中的处理,首先,我们将第一个URL转换为'firstVideoAsset',之后我们将第二个URL转换为'secondVideoAsset'。然后合并两个视频并将合并的URL再次存储到'firstVideoAsset'中。



2)之后,将第三个URL带入'secondVideoAsset'。他们合并了两个视频。相同的过程将持续到循环结束。

3)将最终合并的URL发送到MPMoviePlayerController以播放合并视频的预览。



定位问题: -



1)在合并过程中,如果我们以横向方向捕捉视频(即LandscapeLeft),则捕获的视频合并后,进入颠倒模式(即拍摄视频的反转)。



2)所有视频的大小(静态或摄像头拍摄)合并后不会出现相同的大小。



3)如果我们使用前置摄像头拍摄视频,合并完所有后,拍摄的视频就会颠倒过来。 br $>


需要您的帮助: -



1)合并之前,如果我们捕获任何视频定位模式,它们必须在合并后仅进入一个方向(即LandscapeLeft或LandscapeRight)模式。



2)合并所有视频后,在任何方向模式下所有视频(静态或相机拍摄)的尺寸(高度和宽度)应该有相同的尺寸。



3)使用前置摄像头时,如果我们以横向左侧模式捕获视频,则在合并所有视频后,捕获的视频将进入正确的模式。但是,当以横向右侧模式捕获视频时,合并所有视频后捕获的视频将以颠倒方式进入。(即反转原始捕获的视频)。



4)使用后置摄像头时,如果我们以横向左侧模式捕获视频,则在合并所有视频后,捕获的视频将颠倒过来(即反转原始捕获的视频)。但是,当以横向右侧模式捕获视频时,合并所有视频后捕获的视频将以正确模式进行。

I) Before merging, we take the videos URLs(static videos or camera captured videos) from array, and store them into assets.

II) In the processing of storing the URLs into assets,

1) First, we take the first URL into 'firstVideoAsset', after that we take second URL into 'secondVideoAsset'. Then merge the two videos and store the merged URL into again 'firstVideoAsset'.

2) After that, take the take third URL into 'secondVideoAsset'. Them merge the two videos. Same process will go on until the loop ends.
3) Send the final merged URL into MPMoviePlayerController to play the 'preview' of the merged video.

Orientation issue:-

1) While in the merging process, if we capture the video in 'landscape' orientation(i.e. LandscapeLeft), the captured video after merging, is coming in 'Upside-down' mode(i.e. reverse of captured video).

2) The sizes of all the videos(static or camera captured) are not coming in same size after merging.

3) If we capture the video using front camera, after merging all, the captured videos are coming in upside down.

Need help from your side:-

1) Before merging, if we capture the videos in any orientation mode, they have to come in only one orientation(i.e. LandscapeLeft or LandscapeRight) mode after merging.

2) After merging all the videos, the sizes(height and width) of all the videos(static or camera captured) in any orientation mode, should come in same sizes.

3) While using front camera, if we capture the video in Landscape left mode, after merging all the videos, the captured videos will come correct mode. But, when capture the video in Landscape right mode, the captured videos after merging all the videos will come in Upside down.(i.e. Reverse of original captured video).

4) While using back camera, if we capture the video in Landscape left mode, after merging all the videos, the captured videos will come in Upside down.(i.e. Reverse of original captured video) . But, when capture the video in Landscape right mode, the captured videos after merging all the videos will come in correct mode.

推荐答案

您可以检查视频的方向在为AVMutableVideoCompositionInstruction创建对象时在上面的代码中运行时间。





You can check the orientation of the video run time in above code while you create object for AVMutableVideoCompositionInstruction.


AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mutableComposition duration]);
AVAssetTrack *videoTrack = [[mutableComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

AVMutableVideoCompositionLayerInstruction * layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];

UIImageOrientation videoAssetOrientation_  = UIImageOrientationUp;
BOOL  isVideoAssetPortrait_  = NO;
CGAffineTransform videoTransform = assetVideoTrack.preferredTransform;

if(videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0)
{
    videoAssetOrientation_= UIImageOrientationRight;
    isVideoAssetPortrait_ = YES;
}
if(videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0)
{
    videoAssetOrientation_ =  UIImageOrientationLeft;
    isVideoAssetPortrait_ = YES;
}

CGFloat FirstAssetScaleToFitRatio = 320.0 / assetVideoTrack.naturalSize.width;
if(isVideoAssetPortrait_)
{
    videoSize=CGSizeMake(350,400);
    FirstAssetScaleToFitRatio = 320.0/assetVideoTrack.naturalSize.height;
    CGAffineTransform FirstAssetScaleFactor = CGAffineTransformMakeScale(FirstAssetScaleToFitRatio,FirstAssetScaleToFitRatio);
    [layerInstruction setTransform:CGAffineTransformConcat(assetVideoTrack.preferredTransform, FirstAssetScaleFactor) atTime:kCMTimeZero];
}
else
{
    videoSize=CGSizeMake(assetVideoTrack.naturalSize.width,assetVideoTrack.naturalSize.height);
}


这篇关于合并具有不同视频尺寸的视频,并在合并后更改视频方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆