4

I tried below code to convert video from ALAsset to NSData, this NSData is submitting to the server correctly.

Problem:

But the problem is when I get the thumbnail from NSData in the server, the image is not oriented correctly for some videos and showing correctly for other videos. Also i feel that Video also not oriented correctly.

So do I have to include any thing extra in my code. I know how to orient Image but I don't know how to orient correctly a 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;
}
user2706827
  • 195
  • 2
  • 11
  • What makes you think that the video data is bad, not thumbnails generation itself ? – A-Live Mar 20 '14 at 13:43
  • You can try to use [this answer](http://stackoverflow.com/a/4684110/792677), but what you really need to do is to correct the question (with the title) because it is too board, unclear and it contradicts itself. – A-Live Mar 20 '14 at 14:11
  • Ok. I already checked that link. But it suggest to make orientation from server. What i want is to make correct orientation from device it self. – user2706827 Mar 20 '14 at 14:19
  • Separate comment, what are you doing with the VideoData to convert it to video? I'm struggling with this problem on this question: http://stackoverflow.com/questions/22390679/convert-incoming-nsstream-to-view – Eric Mar 20 '14 at 15:05
  • Eric, Am not converting VideoData to video on device. When i uploading (POST) VideoData to server am storing video in some folder then getting the URL of that video and playing that video with `MPMoviePlayerViewController` . My problem is regarding orientation. – user2706827 Mar 20 '14 at 15:17

1 Answers1

0

Try with

CGSize dimesions = [representation dimensions];
if (dimesions.height > dimesions.width)
    orientation = 1; //Portrait
else
    orientation = 0; //Lanscape
jose920405
  • 7,982
  • 6
  • 45
  • 71