iOS video streaming and storing on device afterwards iOS video streaming and storing on device afterwards objective-c objective-c

iOS video streaming and storing on device afterwards


Not quite sure here how you get your stream but look in to the AVAssetWriter, AVAssetWriterInput and AVAssetWriterPixelBufferAdaptor and as soon as you receive data you should be able to append the data to the to the pixel buffer adaptor using:

appendPixelBuffer:withPresentationTime:

not sure it will work for you but with some fiddling you should be able to adapt your input to match this method. There are lots of example code for setting up the writer


It's quite easy to save the video. Do something similar to this:

//Saving MovieNSMutableData *data = [[NSMutableData alloc] init];NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];          [archiver encodeObject:*MovieObject* forKey:@"MovieObjectDataKey"];[archiver finishEncoding];[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MovieObjectDefaultsDataKey"];[archiver release];[data release];//Retrieving movie NSData *savedMovieData = [[NSUserDefaults standardUserDefaults] objectForKey:@"MovieObjectDefaultsDataKey"];if (savedMovieData != nil) {    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:savedMovieData];    *MovieObject* = [[unarchiver decodeObjectForKey:@"MovieObjectDataKey"] retain];    [unarchiver finishDecoding];    [savedMovieData release];    [unarchiver release];} else {    //Download Stream of Your Movie}

The only thing you really have to change there is * MovieObject *, once in each step.


I know what you want to achieve, I only got a workaround. I had to implement the same behavior and ended up with streaming the video from the server and downloading it next to streaming. Next time the user tries to stream the video determine whether it was downloaded to disk, otherwise stream it again. In a normal case the video was downloaded properly and could be reviewed offline.