1

I'm working on a project and I'd like to know if it's possible to determine whether a video is a boomerang video or not. Boomerang videos generally are about 4 seconds long or slightly shorter.

What I've thought about doing so far is filtering the array I receive from the users camera roll to only display videos which are 4 seconds, but is there a better way?

Any pointers or advice will be greatly appreciated.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Fuad Adetoro
  • 137
  • 1
  • 9

2 Answers2

4

This is not an exact answer, but rather one perspective of how to approach this.

From my understanding Boomerang works by taking a super short, super fast burst of photos and stitching them together into a mini video that plays forward and backward and forward and backward. So that means there is chance for the first frame of the video to appear again. So what I suggest is convert each frames of the video into an array of UIImages. Then take the first image of that array and find out if that image is present in the rest of the array.

To make the video into array of images, you can refer Update for Swift 4.2 part of this answer :- https://stackoverflow.com/a/45153948/4637057

From that you will get frames which is an array of UIImages. Now create another array by taking out the first image from that array using frames.remove(at: 0). But before that create image1, which is frames[0]. Then loop through this new array, consider each image as image2 and apply this logic to determine if the first frame is repeating :- https://stackoverflow.com/a/6488838/4637057

Vincent Joy
  • 2,598
  • 15
  • 25
  • Thanks for your response, the thing is I'm not trying to create boomerang videos. What I'm currently doing is searching through the users camera roll, filtering so that only videos are brought back to me, next what I want to do is detect if the video is a boomerang or a 4 second video. – Fuad Adetoro Oct 02 '18 at 09:46
  • 1
    I think you need to analyse each video (using my process or some other process). Because boomerang video also saves inside the iPhone as .mp4 format. Without analysing the content I don't think you can exactly pinpoint whether that is a boomerang or not, by just filtering the 4 second videos. – Vincent Joy Oct 02 '18 at 13:55
  • I see! I was actually speaking to someone earlier and he said boomerang's file format is .mp4. Do you know if .mp4 format is rare and only used in cases like this? – Fuad Adetoro Oct 02 '18 at 13:58
  • 1
    No it is not at all rare. The videos we shoot in iPhone and videos coming from popular apps like instagram, whatsapp are all .mp4 format. So users gallery will be filled with a lots of .mp4 format videos. – Vincent Joy Oct 02 '18 at 15:28
3

The only help i can give you here, is to refer playbackStyle of PHAsset object, if you're using Photos.framework. More information can be found in PhotoKit documentation here

fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
  • 1
    `loopingVideo` is probably the value you're looking for. You can filter `PHAssets` using predicates. I can't find `bounceVideo` in documentation though. – fewlinesofcode Oct 02 '18 at 11:15
  • So if I use loopingVideo on the assets in the array it will only show videos which it believes loop? – Fuad Adetoro Oct 02 '18 at 11:33
  • 1
    @FuadAdetoro documentation says exactly the following: `PHAsset.PlaybackStyle.videoLooping - An enumeration indicating that the asset should be displayed as a looping video.`. So the answer is yes for looping video. But the thing is, that Boomerang is not exactly a looping video. It's "Bounce" video. I'm not sure, if you can detect exactly a boomerang. But i would start to dig from the perspective of `loopingVideo` – fewlinesofcode Oct 02 '18 at 11:37
  • Sadly that didn't work, thank you for your help though. – Fuad Adetoro Oct 02 '18 at 15:42