I've implemented a way to upload video to youtube, etc. using multipart post, or save a video to the camera roll locally. However, with large videos I get watchdogged due to too large of a memory footprint, because currently I have to put the entire video in memory in order to post it or save it.
What are the steps I could take to break up a large video into manageable chunks?
You can save your video to a file and use nsstream to read chunks of the video and send them, you'll have to keep some state to remember what u sent and what's left but it shouldn't be too bad to implement, for example
BOOL done=FALSE;
NSInputStream *stream=nil;
NSString *myFile=@"..."; //your file path
stream=[[NSInputStream alloc] initWithFileAtPath:myFile ];
while(!done)
{
int chunkSize=500000; //500 kb chunks
uint8_t buf[chunkSize];
//reads into the buffer and returns size read
NSInteger size=[stream read:buf maxLength:chunkSize];
NSLog(@"read %d bytes)", size);
NSData * datum=[[NSData alloc] initWithBytes:buf length:size];
//when we actually read something thats less than our chunk size we are done
if(size<chunkSize)
done=TRUE;
//send data
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With