How to correctly get video orientation in iOS after saving to server

I tried under the code to convert the video from ALAssetto NSData, this one is NSDatasent to the server correctly.

Problem:

But the problem is that when I get a sketch from NSData on the server, the image is not correctly oriented for some videos and correctly displays other videos. I also think that the video is also not oriented correctly.

So I have to include in the code all something extra. I know how to orient the image, but I do not know how to properly orient the video.

-(NSData *)ConvertVideoToNSData:(ALAsset *)asset{

NSData *VideoData;
        ALAssetRepresentation *rep = [asset defaultRepresentation];

        Byte *buffer = (Byte*)malloc(rep.size);
        NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
        VideoData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
        return VideoData;
}
+4
source share
1 answer

Try

CGSize dimesions = [representation dimensions];
if (dimesions.height > dimesions.width)
    orientation = 1; //Portrait
else
    orientation = 0; //Lanscape
0

Source: https://habr.com/ru/post/1532662/


All Articles