zumzum
zumzum

Reputation: 20238

AVAssetWriter: preview recorded .mp4 before calling `finishWriting`?

I am using AVAssetWriter to record a video (with audio) form iOS camera. Everything works great.

I now want to allow the user to preview the video before saving, meaning, before calling finishWriting on the AVAssetWriter instance.

My original thought was to copy the current file the writer is writing to during recoding to a preview url, and then use another AVAssetWriter to finalize that file and then play it.

However, I am not sure how to properly initialize a second AVAssetWriter for preview purposes, so I can call finishWriting on it at the preview url...

Anyone knows how I could implement preview functionality to allow a user to preview the currently recorded mp4 before calling finishWriting?

Upvotes: 0

Views: 261

Answers (2)

Kunguma Harish
Kunguma Harish

Reputation: 1

Given the constraints of AVAssetWriter, the video file indeed cannot be played back until finishWriting has been called and the file is finalized. Unfortunately, this means that any attempts to preview the video file during the writing process will result in an incomplete or corrupt file.

Summary • No Direct Playback During Writing: Since the file is not finalized until after finishWriting, you cannot preview the video until this method has been executed.

Alternative Approaches

  1. Use a Temporary Preview: Instead of directly previewing the video file being written, consider rendering a few frames of the video (or a still image) as a temporary preview using AVPlayer or a simple UllmageView.
  2. Export to a Specific Location: Once the video is fully exported, you can then preview it. This means you'll have to wait until the entire process is complete.

Conclusion If you're looking for an approach to play the video during the encoding process, there isn't a viable option because of how AVAssetWriter works. You will need to wait until the writing is completed before the video can be played back successfully.

Upvotes: 0

Gordon Childs
Gordon Childs

Reputation: 36159

Anyone knows how I could implement preview functionality to allow a user to preview the currently recorded mp4 before calling finishWriting?

You must call finishWriting in order to have a viewable mp4 file.

So call finishWriting, let the user preview the resulting file and then decide whether to delete it or keep it.

Upvotes: 0

Related Questions