Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c AVMutableCompositionTrack在导出时倒置_Objective C_Video_Rotation_Avassetwriter_Avmutablecomposition - Fatal编程技术网

Objective c AVMutableCompositionTrack在导出时倒置

Objective c AVMutableCompositionTrack在导出时倒置,objective-c,video,rotation,avassetwriter,avmutablecomposition,Objective C,Video,Rotation,Avassetwriter,Avmutablecomposition,我正在使用一个视频渲染器,它使用gl_readPixels捕获openGL层(irrlicht引擎),并输出一个video.mp4文件。这分为两个阶段,第一阶段捕获视频并保存(AVAssetWriter),第二阶段获取保存的视频并将其与音频曲目(AVMutableCompositionTrack和AVAssetExportSession)组合 然而,当播放此视频(非quicktime)时,尽管我尝试翻转它,但它看起来是颠倒的 我已尝试在第二阶段使用: AVMutableCompositionTr

我正在使用一个视频渲染器,它使用gl_readPixels捕获openGL层(irrlicht引擎),并输出一个video.mp4文件。这分为两个阶段,第一阶段捕获视频并保存(AVAssetWriter),第二阶段获取保存的视频并将其与音频曲目(AVMutableCompositionTrack和AVAssetExportSession)组合

然而,当播放此视频(非quicktime)时,尽管我尝试翻转它,但它看起来是颠倒的

我已尝试在第二阶段使用:

AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[a_compositionVideoTrack insertTimeRange:video_timeRange ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil];

// Flip
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, self.frame.size.height);
a_compositionVideoTrack.preferredTransform = flipVertical;
它可以在iPad上翻转视频(正确播放),但当复制到另一台设备上时,视频仍然显示为倒置

我还尝试使用以下方法翻转AVAssetWriterInput:

videoInput.expectsMediaDataInRealTime = YES;
videoInput.transform = CGAffineTransformMakeScale(1, -1);
它还可以在苹果设备上正确翻转视频,但不能在pc、youtube和facebook上。在PC上定义旋转是否缺少设置或标志

编辑: 我还以右旋转模式使用设备(模拟器或iPad)(我最初使用的是左旋转)。录制视频时,“主页”按钮位于右侧。但是,对于我的视频输出,使用任一旋转都不会影响视频旋转。

编辑2:我现在也尝试翻转视图,其效果与上面的两个更改相同

captureView.transform = CGAffineTransformMakeRotation(180.0f * M_PI / 180.0f)

试试这个,使用
preferedtransport
结合缩放和平移到中心变换,将视频放在正确的位置

祝你好运

AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
    videoComposition.frameDuration = CMTimeMake(1, 30);
videoComposition.renderSize = CGSizeMake([self multiplyBy16: size.width] ,[self multiplyBy16: size.height]);
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
AVMutableVideoCompositionLayerInstruction* transformer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoCompositionTrack];
CGAffineTransform finalTransform ;
CGAffineTransform videoTransform = clipVideoTrack.preferredTransform;

finalTransform = CGAffineTransformConcat(videoTransform,CGAffineTransformMakeTranslation("scale and translate to center transform"));

instruction.layerInstructions = [NSArray arrayWithObjects:transformer,nil];
videoComposition.instructions = [NSArray arrayWithObject: instruction];

我通过在glReadPixels阶段执行交换操作解决了问题。我之前尝试过的大多数方法的问题是,它们往往只是与视频元数据打包在一起,而不是移动任何像素。特别是变换函数实际上不做任何繁重的工作

为需要反转像素的其他人提供的代码。可能有更好的方法,使用一些更优化的代码,请分享,如果你知道一种方法

    // OpenGL
    unsigned int* pixelBufferData = (unsigned int*)CVPixelBufferGetBaseAddress(pixelBuffer);
    glReadPixels(0, 0, self.screen.size.width, self.screen.size.height, GL_BGRA, GL_UNSIGNED_BYTE, pixelBufferData);

    unsigned int base;
    unsigned int top;
    int width = self.screen.size.width;
    int height = self.screen.size.height;
    int half_height = height / 2;
    int base_row_index = height * width;
    int top_row_index = 0;

    for(int y = 0; y < half_height; y++) {
        base_row_index -= width;
        top_row_index += width;

        for(int x = 0; x < width; x++) {
            base = pixelBufferData[top_row_index + x];
            top = pixelBufferData[base_row_index + x];
            pixelBufferData[top_row_index + x] = top;
            pixelBufferData[base_row_index + x] = base;
        }
    }
//OpenGL
unsigned int*pixelBufferData=(unsigned int*)CVPixelBufferGetBaseAddress(pixelBuffer);
glReadPixels(0,0,self.screen.size.width,self.screen.size.height,GL_BGRA,GL_UNSIGNED_字节,pixelBufferData);
无符号整数基;
无符号整数top;
int width=self.screen.size.width;
int height=self.screen.size.height;
int half_height=高度/2;
int base_row_index=高度*宽度;
int top_row_index=0;
对于(int y=0;y<半高;y++){
基本行索引-=宽度;
顶行索引+=宽度;
对于(int x=0;x
使用memcpy和两个缓冲器的优化解决方案:

for (int row = 0; row < height; ++row){
    memcpy(dstBuffer + (height - row - 1) * width * 4, srcBuffer + row * width * 4, width * 4);
}
for(int row=0;row
谢谢,但我也无法让它工作。它似乎与设置可变轨迹的preferredTransform具有相同的效果。