Apple‘s LIve Photo:how the video is pre-recorded when taking pictures? - ios

I would like to build an App about capture a Live Photo but I have no idea How to record the video 1.5 seconds before the button is pressed。

I think the basic idea is to keep recording to a buffer. The buffer should hold the last n seconds of video (3 seconds in your case). When the button is pressed copy the buffer.
I haven't done any development in ios, so i will be of no use in providing the code.

Related

IOS Apply a slow motion effect to a video while shooting

Is it possible to apply slow motion effect while recording video?
This means that the recording has not finished yet, the file has not been saved, but the user sees the recording process in slow motion.
I think it is important to understand what slow-motion actually means. To "slow down motion" in a movie, you need to film more images per second than usually and play this movie afterwards in normal speed, that's making the slow motion effect.
Example: Videos are often shot in 30 frames per second (fps), so for one second of movie you're creating 30 single images. If you want a motion to be half as fast, you need to shoot 60 fps (60 images per second). If you play those 60 images at half-speed (the normal 30fps), it will result in a movie of 2 second lengths showing the slow-motion effect.
As you can see, you cannot record and show a slow-motion effect at the same time. You'll need to save it first and then play it slower than recorded.

How to set delay in seconds to the camera capture on iOS?

I want to know if setting a delay in seconds to the camera feed is possible on iOS with Swift.
Let's say I add a 30 second delay to my camera. If I am pointing the camera at a person who is crouching down, and then that person stands up, my camera is not going to show that until those 30 seconds have passed. In other words, it will continue to show the person crouched until that time has passed.
how can I achieve this?
This sounds extremely difficult. Problem is camera recording is bringing in (most likely) 30 frames a second. So those buffers from 30 seconds ago need to be saved somewhere, and in raw form that is a TON of data so you can't just keep those in memory.
You don't want to write as images because the compression is garbage compared to video.
Perhaps the best way would be to setup your capture, then capture your video in say 10 second segments, save to file, then display those video file segments on an AVPlayer or something. That way it's 'delayed' for the user.
Either way, from my understanding of how things work, the main challenge is what to do with those buffers while waiting to display them. You could potentially stream it somewhere, but then you need a whole backend to support that and then stream it back, seems silly.

SWIFT: Tips for getting videos to download faster?

I have an iOS app that downloads videos from Firebase (Cloud Firestore) with a feed similar to Instagram/TikTok. However, I can't get the videos to be readily available before a user scrolls to the video. Any tips would be super helpful. How does TikTok do it? Do they save a whole bunch of videos to file in the background on load?
My current VideoDownloadManager:
Checks if video is already loaded in temp cache or local file,
and if not:
Downloads video url (view Firebase's downloadURL)
Returns the video url for immediate use (before playing it still
has some delay for buffering)
Stores the video url in a temp
cache (in case user scrolls away and scrolls back)
Begins to write video to file and removes video from temp cache on completion
With the current set up, videos play efficiently after they are downloaded. But if a video is not downloaded yet and a user scrolls to that video, it takes too long for (#1/2) above to complete and buffer enough to play. I am already using OperationQueues and prioritizing the current video over any other background videos - but this isn't fast enough still.
TikTok videos are almost always readily available as a user scrolls. What the secret?
Thanks for your help!
I have a few tips for you:
1- when you are loading your stream you should start preheating video URLs in a background thread.
2- try not to download complete files, and just cache or buffer a small amount of file like 1MB.
3- with .mp4 files you can play videos even if they are not downloaded completely.
4- start full download when the video starts playing based on the buffer rate or video length.
5- try to use videos with the smallest file size and bitrates. when you are creating them, try to convert them to a convenient format. my suggestion will be:
Video:
video bit rate -> 12.5
video size -> 960x540
conversion format -> h264
Sound:
rate -> 44100
encoding bit rate -> 96000
6- check if the video has a buffered range of more than 25% when you are going to start the playback.
7- don't forget to do the downloads in a temp folder and clean that folder regularly. This helps avoid huge app size, the consequence of not doing that will may lead users to delete your app!!.
For iOS developers: this is my videoConverter.
also, you can use this cache video player GSPlayer

The Amazing audio engine 2 - Crossfade looping

I am using the amazing audio engine 2 library for my sequencer app and I want to implement Crossfade loop audio.
Here is explanation :
When user press any key in sequencer piano it will play some audio file and and that audio file will continue to play in loop until user release the key. But that loop will be crossfade to itself.
I am using AEAudioFilePlayerModule for looping but not sure how to crossfade audio file with this class.
Explanation of Cross fade :
Start/End: This setting allows me to choose where in the audio file I want the app to constantly loop so that if user taps+holds note down for a long time, the audio will sound continuously until the user releases his finger.
XFade: This function (crossfade) allows me to chose how to fade between the end and start of the audio loop. This is good so
that the sound will loop smoothly. Here, 9999 is set. So at about 5k samples before the 200k end point, the audio for this note
will begin to fade away and at the same time, the audio loop starting at 50k samples will fade in for a duration of about 5k samples (1/2 the XFade amount).
Please help.
Thank you.

How do I just save last few seconds of a captured video (AVCaptureSession)

I want the user the record a continuos video at 240 FPS using iPhone 6. When the user presses a button, it should just save the last 10 seconds on file system for a later viewing pleasure.
How do I achieve this? I haven't found any good answer to this task.
I'm toying around with AVCaptureSession and AVCaptureMovieFileOutput which automatically writes the stream onto the disk.
One approach is to not use AVCaptureMovieFileOutput and build a ring buffer in memory and on button press, just save those 10 seconds onto the disk. Achievable using NSData?
Second approach I can think of is just use AVCaptureMovieFileOutput as is, but on button press, just keep the last 10 seconds and cut off the rest to save space.
Currently I don't have any clue how I can do any of those 2 approaches. Can someone point me to the right direction?

Resources