Skip to content

Using video data from photo gallary #2

Description

@trident10

I am trying to get get the data of video from the photo library. I am using following code:-

{
videoArray = [self getContentFrom:group withAssetFilter:[ALAssetsFilter allVideos]];
if (videoArray.count) {
ALAssetRepresentation *rep = [videoArray lastObject];
Byte *buffer = (Byte *)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

            RtmpWrapper *rtmp = [[RtmpWrapper alloc] init];
            BOOL ret = [rtmp openWithURL:@"rtmp://173.224.117.133:1935/oflaDemo/1" enableWrite:YES];
            if (ret) {
                NSData *video =
                    data;
                NSLog(@"original video length: %d", [video length]);
                NSUInteger length = [video length];
                NSUInteger chunkSize = 20 * 5120;
                NSUInteger offset = 0;

                // Let's split video to small chunks to publish to media server
                do {
                    NSUInteger thisChunkSize = length - offset > chunkSize ? chunkSize : length - offset;
                    NSData *chunk = [NSData dataWithBytesNoCopy:(char *)[video bytes] + offset
                                                         length:thisChunkSize
                                                   freeWhenDone:NO];
                    offset += thisChunkSize;

                    // Write new chunk to rtmp server
                    [rtmp write:chunk withCompletion: ^(NSUInteger sent, NSError *error) {
                        NSLog(@"sent -> %d", sent);
                        if (error) {
                            NSLog(@"error -> %@", [error description]);
                        }
                    }];
                    sleep(1);
                }
                while (offset < length);
            }

            // Close rtmp connection and release class object
            [rtmp close];
        }
    }

It is not displaying video on website. Any reason what I am doing wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions