HybridCamera icon indicating copy to clipboard operation
HybridCamera copied to clipboard

Add support for merging video segments

Open eonist opened this issue 6 years ago • 13 comments
trafficstars

support merging video segments: https://www.raywenderlich.com/188034/how-to-play-record-and-merge-videos-in-ios-and-swift

eonist avatar Oct 02 '19 17:10 eonist

Unfortunately, I don't have much time to help you right now due to lots of studying. Nonetheless, I just saw you made a bunch of commits and found this issue. If only portrait is needed, please check out this question I answered myself using the very same tutorial. It works great for me! And might save you a bit of time ;)

blurtime avatar Oct 04 '19 18:10 blurtime

Which answer and question? For merging videos ?

eonist avatar Oct 04 '19 19:10 eonist

No worries. Feedback is also help, and doesn’t require you to unfocused in school ;)

eonist avatar Oct 04 '19 19:10 eonist

Sorry, seems like Alzheimer's is already kicking in 😂 here's the link: https://stackoverflow.com/questions/57083151/change-preferredtransform-of-assetvideotrack-to-solve-mirroring-issue-when-mergi

blurtime avatar Oct 04 '19 19:10 blurtime

Hi @eonist, how are you doing? I recently managed to start coding again and I want to finally finish one of my projects. I tried solving the issue of switching the camera while recording as shown here but couldn't make it work. As far as I am concerned I see two options. One of them is to use Mutli Cam Session which IMO is a little overkill (more or less literally burns your GPU). The second option is that we separate the audio entirely and record it as one separate file, then record a number of videos and keep track of the time when one was stopped and the next one was started and merge all of this together keeping the time in mind and filling the small stops of the video with a black screen (which for portrait mode is very easy). I could code this easily (link in the answer above). What would you think of this?

blurtime avatar Jun 20 '20 23:06 blurtime

Hi, Man. Doing great. One of my projects got funded the last 6 months so having fun with that: https://passbook.co

You mean support for merging multiple lense recordings, or support for merging many clips together in post prod?

eonist avatar Jun 21 '20 05:06 eonist

That's awesome. Just checked out the website. It's a pretty cool idea to use the kinetic movement :D I am not sure I understand correctly cause they sound like the same to me. What I would suggest:

  1. User starts pressing recordbutton: Audio is recorded (separately) and the video using the current device input (say back/rear camera)
  2. If the user stops -> merge audio and video and we have a normal clip like now
  3. If the user wants to switch the camera while recording, though, we continue recording the audio (since it's separate) but stop recording the video. Then we quickly switch the device input (in this case to the front camera) and start recording the next part of the video with the front camera.
  4. This could go back and forth indefinitely now.
  5. Once the user lifts his thumb from the record button both audio and current video stop recording.
  6. All file names should be kept in an array.

After that, I use the duration of the audio and each video to merge them such that there should be no lag. If we suppose that changing the camera always takes the same time on the same device, we can do the following:

  • audio duration - (video1.duration + video2.duration + ...) = total duration of camera flipping
  • divide this by (the number of videos - 1) = duration of one camera flip (on average)
  • merge such that clips always "one flip duration" apart).

What would you think of this?

blurtime avatar Jun 21 '20 12:06 blurtime

And I keep seeing this sample buffer function when doing research on this topic: https://stackoverflow.com/questions/30216976/why-does-switching-cameras-stop-my-avcapturesession-to-moviefileoutput

blurtime avatar Jun 21 '20 12:06 blurtime

I think.

  1. start recording rear cam
  2. switch to front cam, start record front cam (when initiated stop back-cam)
  3. store clips in a folder with date as name then merge chronologically

If this doesn't work? please fill me in 🙏

eonist avatar Jun 21 '20 18:06 eonist

Hi @eonist, hope you're enjoying summer! Unfortunately, something happened in June and I didn't have time to finish my idea. However, I managed to do it now, and at least the video saving and merging works. Although I am not sure how useful it will be for this library since I had to rewrite a whole bunch of code and I am using another library to deal with the file stuff. It wasn't easy but it's definitely doable. I don't have to lift my finger and get a merged video! :D Now only audio is missing but that hopefully won't be too much of a bother. I'll see if I can maybe give you a usable version of the video merger since I have learned quite a bit about it and maybe also how I rewrote a bunch of stuff in the CamView files soon. Just wanted to keep you posted :)

EDIT: Another idea that would be pretty cool for sure would be filters. Any experience coding something along those lines?

blurtime avatar Aug 06 '20 18:08 blurtime

  • Has a bunch of stuff on merging video: https://www.raywenderlich.com/10857372-how-to-play-record-and-merge-videos-in-ios-and-swift#toc-anchor-005
  • I'm working on a VideoProcessor ATM for my startup. Basically turn an mp4 file into images, and images into mp4. (Will open-source tomorrow)
  • On filters: Depends how far you want to take it. You can do live filter preview. or post filter. the later would be easier. the former often involves metal etc. But there are a bunch of tutorials on it so you don't have to re-invent the wheel to add it etc.
  • What I suggest is that you make your video-merger-module open source. and then we can link to it from the HybridCam repo or something?

eonist avatar Aug 06 '20 19:08 eonist

Thank you for your resources, I'll look into them ASAP. Sounds like an exciting project, I'll check if I might find use in it for my project :) The most important thing is essentially the answer on SO to the question I posed myself. But sure, I can do that :D

blurtime avatar Aug 06 '20 20:08 blurtime

If you open source the module, you can get feedback from other peers on it etc. Sometimes feedback can unlock big performance gains etc. Its easy to miss small details when you go into lower level coding. closer to c, c++ etc

eonist avatar Aug 07 '20 11:08 eonist