Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetWriter: how to write to a single file multiple times

I am able to record video and save it in documents directory using AVFondation, now i want to re-open that saved video file and start recording again from the end of that file, is that possible or do i have to create multiple video files and merge them, please advise!

Regards,

like image 992
Asif Mujteba Avatar asked Feb 02 '26 05:02

Asif Mujteba


2 Answers

I'm pretty sure there isn't a way to get the AVAssetWriter mux to append to an existing file. And of course if you need to prepend all the existing data when starting a new file, you will be slow to start.

An alternative is to start a new temporary file, and copy the data in the background into a third file, using something similar to http://www.gdcl.co.uk/2013/02/20/iOS-Video-Encoding.html. That is, you have file 1, which was closed when you suspended. You start writing to file 2 when you resume, and simultaneously read from 1 and write to a new file 3. when you've exhausted 1, you can read from file 2 (using the example code linked to above) and append that to file 3.

G

like image 161
Geraint Davies Avatar answered Feb 03 '26 19:02

Geraint Davies


I think you should read the saved video, and then append the recorded video in NSData format, and rewrite the whole data again.. You can use NSMutableData to appendData..

like image 44
iphonic Avatar answered Feb 03 '26 18:02

iphonic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!