1

Goal: Use AVCaptureMovieFileOutput to record video to a .mov file. While video is recording, I want to upload it to S3. The uploading part should be feasible with Multi-Part upload. (Mac OS X +10.8 app)

Problem: How do I read from a .mov file in chunks, while the file is being written to with AVCaptureMovieFileOutput and growing in size?

What I did so far:

// session = AVCaptureSession with audio and video inputs

fileOutput = [[AVCaptureSession alloc] init];
[session addOutput:fileOutput]

[session startRunning]
[fileOutput startRecordingToOutputFileURL: fileUrl recordingDelegate:self]

// In async dispatch queue
inputStream = [NSInputStream inputStreamWithFileAtPath:fileUrl]
// schedule in run loop, open and run

At this point I start receiving stream:handleEvent: messages on the delegate object with NSStreamEventHasBytesAvailable. But after a few seconds the messages stops coming in (after total bytes of 250.000-300.000 bytes (0.2MB)) This happens even though the .mov file grows in size to >10MB.

Questions:

  1. Why does the NSInputStream delegate not continue to receive stream events?

  2. Is the data available initially not reliable?

  3. Is this overall a feasible approach? Or is there another way of achieving what I want?

Thanks!

Jonas Bylov
  • 1,494
  • 2
  • 15
  • 28

1 Answers1

0

I have a sample at http://www.gdcl.co.uk/2013/02/20/iOS-Video-Encoding.html that reads from a movie file while recording to the file from the camera (iOS 6). I'm using a separate AVAssetWriter, but it looks as though this should work fine for you.

Geraint Davies
  • 2,847
  • 15
  • 9
  • Thanks for the input, Geraint. In the article you mention that no audio is contained in the file. In my case there's audio recorded to the file. Does that make it impossible? Thanks – Jonas Bylov Jul 04 '13 at 16:55
  • If you just want to copy the file while it's recording, I think that should be fine. You don't need to interpret it, just copy the parts that have been written. You will need to be careful though: the size of the mdat chunk will be updated when the file is closed. Mostly, the file should be written sequentially though. My sample is showing how to use the encoded video data while encoding: for that, you need to write the audio separately (and perhaps remux yourself, having used the hardware for video encoding only). – Geraint Davies Jul 05 '13 at 11:29
  • Ok, so if I understand you correctly, your code sample (although interesting) is not that relevant? I need a complete copy of the .mov file written to disk. You focused on streaming the video to another unit? – Jonas Bylov Jul 22 '13 at 10:55
  • 1
    Your point: reading from a MOV file while it is being written to seems not to work. My point: I have code that does exactly this, for other reasons, so you could look at the differences (or ask me to) and see why yours is failing and mine isn't. Possible differences: I use a separate capture session and asset writer, whereas you use a combined object. I only write video, whereas you are writing both audio and video. – Geraint Davies Jul 22 '13 at 17:06