Coder Social home page Coder Social logo

swift-video-generator's Introduction

swift-video-generator-logo

Platform CocoaPods License Twitter URL Website

This library provides an easy way to combine images and audio into a video or merge multiple videos into one.

Features

  • create a video from a single image and audio file
  • create a video from multiple image/audio pairs
  • create a video from a single audio and multiple images
  • create a video from a single image (no audio)
  • create a video from multiple images (no audio)
  • merge multiple videos into one
  • reverse a video clip
  • split video in time range
  • merge single video with single audio

Supported video formats

  • mov (only when merging videos)
  • m4v
  • mp4 (only when merging videos)

Requirements

  • iOS 12.0 or later
  • Xcode 10 or later
  • Swift 4 or later

Communication

  • If you need help or want to ask a general question, you can find me @guardians_devil or @devlabsbg. Or tag #swift-video-generator on Twitter
  • If you found a bug, open an issue
  • If you have a feature request, open an issue
  • If you want to contribute, submit a pull request

Contributers

  • ibhavin - version 1.0.8 creating a video form a single audio and multiple images
  • SteliyanH - version 1.1.0 reversing the audio in a video clip

Installation

CocoaPods

CocoaPods is a dependancy manager for Xcode. You can install it by running the following command in the Terminal:

$ gem install cocoapods

To use Swift Video Generator in your Xcode project using CocoaPods, add it in the Podfile:

platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'SwiftVideoGenerator'
end

Swift Package Manager

To add the library as package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL [email protected]:dev-labs-bg/swift-video-generator.git

Manually

If you don't want to use a dependency manager, you can integrate SwiftVideoGenerator manually.

Download the following files:

Video Generator Classes

You need the VideoGenerator.swift and the files in the Error and Extensions folders.

Add files to project:
  • Open your project in Xcode
  • Add the files you downloaded to the Project Navigator. You can create your own folders or keep the files as they are.
  • And you're done. You're now ready to make some video magic.

Usage

If you used Cocoapods to install SwiftVideoGenerator, you need to import the module:

import SwiftVideoGenerator

For both the .single and .multiple types of video generation the output video file format is m4v.

Create a video from a single audio and image file

if let audioURL4 = Bundle.main.url(forResource: Audio4 , withExtension: Mp3Extension) {
  LoadingView.lockView()

  VideoGenerator.fileName = SingleMovieFileName
  VideoGenerator.shouldOptimiseImageForVideo = true

  VideoGenerator.current.generate(withImages: [#imageLiteral(resourceName: "image4")], andAudios: [audioURL4], andType: .single, { (progress) in
    print(progress)
  }, success: { (url) in
    LoadingView.unlockView()
    print(url)
    self.createAlertView(message: self.FinishedSingleTypeVideoGeneration)
  }, failure: { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  })
} else {
  self.createAlertView(message: MissingResourceFiles)
}

With the generator type .single you can create a video from a single pair of audio and an image.

If you leave the audio array empty and implement videoDurationInSeconds, the generated video contains only the image without audio.

Exmaple video - single type generation

The scaleWidth property scales the image to a desired size. Only used in a .single type of video.

The fileName property sets the output file's name.

The videoBackgroundColor property is used when scaling the image. When an image is scaled to a smaller frame then the video's it leaves empty spaces around the image. You can set the background color of that space with the videoBackgroundColor property. If you don't specify a scaleWidth the image is scaled (keeping the aspect ration) to fill the entire video frame.

The maxVideoLengthInSeconds property is used to set the video's maximum length. If the length of the moview exceeds this value, it's cut short at the specified time. (Note that this doesn't scale the audios in order to make them fit into the time.)

The shouldOptimiseImageForVideo property is used to optimize the images fed into the generators to a scale best fitted for video based on their orientation.

Set the videoDurationInSeconds for generated video without audio.

Create a video from multiple image/audio pairs

if let audioURL1 = Bundle.main.url(forResource: Audio1, withExtension: Mp3Extension), let audioURL2 = Bundle.main.url(forResource: Audio2, withExtension: Mp3Extension), let audioURL3 = Bundle.main.url(forResource: Audio3, withExtension: Mp3Extension) {
  LoadingView.lockView()

  VideoGenerator.fileName = MultipleMovieFileName
  VideoGenerator.videoBackgroundColor = .red
  VideoGenerator.videoImageWidthForMultipleVideoGeneration = 2000

  VideoGenerator.current.generate(withImages: [#imageLiteral(resourceName: "image1"), #imageLiteral(resourceName: "image2"), #imageLiteral(resourceName: "image3")], andAudios: [audioURL1, audioURL2, audioURL3], andType: .multiple, { (progress) in
    print(progress)
  }, success: { (url) in
    LoadingView.unlockView()
    print(url)
    self.createAlertView(message: self.FnishedMultipleVideoGeneration)
  }, failure: { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  })
} else {
  self.createAlertView(message: MissingAudioFiles)
}

With the type .multiple you can create a video that combines multiple image/audio pairs. The finished video will queue up multiple videos created by taking one image from the array and it's corresponding index element from the audio array, creating a video from it and then appending it to the finished video.

If you leave the audio array empty and implement videoDurationInSeconds, the generated video contains only the images without audio.

Then the next pair of audio and image will be made into a video and appended after the first one. This will continue untill all image/audio pairs have been appended. If the image/audio pairs are not the same count, the extra audio(s)/image(s) is not used.

The fileName and videoBackgroundColor properties are used in the same way as in the .single type.

The videoImageWidthForMultipleVideoGeneration property is used to set a custom width to which the images will be scaled before they are merged with the audio files and generated as a video. The default value is 800.

Exmaple video - multiple type generation video

Create a video from multiple images and a single audio

if let audioURL1 = Bundle.main.url(forResource: Audio1, withExtension: Mp3Extension) {
  LoadingView.lockView()

  VideoGenerator.fileName = MultipleSingleMovieFileName
  VideoGenerator.shouldOptimiseImageForVideo = true

  VideoGenerator.current.generate(withImages: [#imageLiteral(resourceName: "image1"), #imageLiteral(resourceName: "image2"), #imageLiteral(resourceName: "image3"), #imageLiteral(resourceName: "image4")], andAudios: [audioURL1], andType: .singleAudioMultipleImage, { (progress) in
    print(progress)
  }, success: { (url) in
    LoadingView.unlockView()
    print(url)
    self.createAlertView(message: self.FnishedMultipleVideoGeneration)
  }, failure: { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  })
} else {
  self.createAlertView(message: MissingAudioFiles)
}

With the type .singleAudioMultipleImage you can create a video that combines multiple images and a single audio. The finished video will space out the multiple images along the timeline of the single audio.

Exmaple video - multiple images/single audio generated video

Merging multiple videos into one

if let videoURL1 = Bundle.main.url(forResource: Video1, withExtension: MOVExtension), let videoURL2 = Bundle.main.url(forResource: PortraitVideo, withExtension: Mp4Extension) {
  LoadingView.lockView()
  VideoGenerator.presetName = AVAssetExportPresetPassthrough
  VideoGenerator.fileName = MergedMovieFileName
  
  VideoGenerator.mergeMovies(videoURLs: [videoURL1, videoURL2], success: { (videoURL) in
    LoadingView.unlockView()
    self.createAlertView(message: self.FinishedMergingVideos)
    print(videoURL)
  }) { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  }
} else {
  self.createAlertView(message: MissingVideoFiles)
}

You can provide URLs both for local resource files as well as those stored on the device (i.e. in the Documents folder).

As of right now the merged video keeps all of the preferredTransformations (like mirroring or orientation) of the last provided video asset. More to come in future feature implementations.

Exmaple video - merged video

Reversing a video clip

if let videoURL1 = Bundle.main.url(forResource: Video2, withExtension: MovExtension) {
  LoadingView.lockView()
  VideoGenerator.fileName = ReversedMovieFileName
  
  VideoGenerator.current.reverseVideo(fromVideo: videoURL1, success: { (videoURL) in
    LoadingView.unlockView()
    self.createAlertView(message: self.FinishReversingVideo)
    print(videoURL)
  }, failure: { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  })
} else {
  self.createAlertView(message: self.MissingVideoFiles)
}

You need to provide the file's URL and optionally a new name for the reversed video file. The finished reverse video is without audio.

Exmaple video - reversed video

Splitting a video clip

if let videoURL1 = Bundle.main.url(forResource: Video1, withExtension: MOVExtension) {
  LoadingView.lockView()

  VideoGenerator.fileName = SplitMovieFileName
  
  VideoGenerator.current.splitVideo(withURL: videoURL1, atStartTime: 10, andEndTime: 40, success: { (url) in
    LoadingView.unlockView()
    print(url)
    self.createAlertView(message: self.FinishSplittingVideo)
  }, failure: { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  })
} else {
  self.createAlertView(message: self.MissingVideoFiles)
}

You need to provide the file's URL and optionally a new name for the split video file. The atStartTime and andEndTime properties mark the start and end of the time range in seconds.

Exmaple video - split video

Merging a video clip with custom audio

if let videoURL2 = Bundle.main.url(forResource: Video2, withExtension: MOVExtension), let audioURL2 = Bundle.main.url(forResource: Audio2, withExtension: Mp3Extension) {
  LoadingView.lockView()

  VideoGenerator.fileName = NewAudioMovieFileName
  
  VideoGenerator.current.mergeVideoWithAudio(videoUrl: videoURL2, audioUrl: audioURL2, success: { (url) in
    LoadingView.unlockView()
    print(url)
    self.createAlertView(message: self.FinishMergingVideoWithAudio)
  }) { (error) in
    LoadingView.unlockView()
    print(error)
    self.createAlertView(message: error.localizedDescription)
  }
} else {
  self.createAlertView(message: self.MissingVideoFiles)
}

You need to provide the video and audio URLs and optionally a new name for the generated video file.

Exmaple video - merge video with new audio

Already in use in the following apps:

Credits

SwiftVideoGenerator was created and is maintaned by Dev Labs. You can find us @devlabsbg or devlabs.bg.

License

SwiftVideoGenerator is released under the MIT license. See LICENSE for details.

swift-video-generator's People

Contributors

danielcreagh avatar dsmailes avatar gregsadetsky avatar kaunteya avatar steliyanh avatar tgeorgieva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-video-generator's Issues

“test.m4v” couldn’t be moved to “D10F1915-39D3-4C6F-82B5-9DCB8A4B4731” because either the former doesn’t exist, or the folder containing the latter doesn’t exist.

Complete Log

file:///Users/peyman/Library/Developer/CoreSimulator/Devices/1A2CEDE0-AA2E-4E85-95AE-075162B55DA5/data/Containers/Data/Application/D10F1915-39D3-4C6F-82B5-9DCB8A4B4731/DocumentsSampleVideo1.m4v finished finished “test.m4v” couldn’t be moved to “D10F1915-39D3-4C6F-82B5-9DCB8A4B4731” because either the former doesn’t exist, or the folder containing the latter doesn’t exist. file:///Users/peyman/Library/Developer/CoreSimulator/Devices/1A2CEDE0-AA2E-4E85-95AE-075162B55DA5/data/Containers/Data/Application/D10F1915-39D3-4C6F-82B5-9DCB8A4B4731/DocumentsSampleVideo1.m4v “test.m4v” couldn’t be moved to “D10F1915-39D3-4C6F-82B5-9DCB8A4B4731” because either the former doesn’t exist, or the folder containing the latter doesn’t exist. file:///Users/peyman/Library/Developer/CoreSimulator/Devices/1A2CEDE0-AA2E-4E85-95AE-075162B55DA5/data/Containers/Data/Application/D10F1915-39D3-4C6F-82B5-9DCB8A4B4731/DocumentsSampleVideo1.m4v

Any Idea why it's coming like that ?
when I use sample code provided by you that works not in my project.

I tried using pods and even adding Files manually

//MARK: Merge Button Action
     @objc private func mergeVideoBtnAction(sender: UIButton) {
        /// Get Snapshot Image
         guard let snapShotImage = mapImgView.image else {
            return
         }
    
         /// Start Merging
         VideoGenerator.current.shouldOptimiseImageForVideo = true
         VideoGenerator.current.fileName = "SampleVideo1"
         VideoGenerator.current.generate(withImages: [#imageLiteral(resourceName: "placeholder")], andAudios: [], andType: .single, { (progress) in
        print(progress.fractionCompleted)
    }, success: { (successURL) in
        print(successURL)
    }) { (error) in
        print(error.localizedDescription)
    }
}`

I have to use that snapshot Image to be merged as video but I used static image for now

Exporting as .mov instead of .m4v

Not an issue so much as me just being a newbie coder. How can I get it to export video as .mov so I can save to the camera roll? Or is there a better way to save to camera?

Black frames at end of merged video

Hey there,

I'm trying to merge several video files that are around one second long. It works fine, but at the end of each merged video there is a couple black frames.

There's also an issue where if there is no audio track the VideoGenerator throws an error.

Thanks for your work on this project!

orientation change for recorded videos

i selected two videos for merging. one is portrait and second one is in landscape. after merging the two videos. portrait video orientation will be change.

Cannot merge a video created with .generate to other clips using .mergeMovies

Steps to reproduce

  1. Create a video using a no sound and an image using .generate

  2. Take the URL from output of above and append it to an array of video URLs. Use .mergeMovies function on the array of URLS

When i get the output merged video, the video created using Step 1 (from the image and no sound) does not properly merge and just shows a black screen for the duration i set using VideoGenerator.videoDurationInSeconds, the other URLS in the array show correctly though in the output merged video

If anyone can help that would be great! Thanks!

Gif support

Hi,

Great project. Thanks for sharing it!

i want to ask you if you've already tried to include the support to merge videos with GIFs? Especially with the gifs with a trasparent background. Because i already tried to do it but the iOS decoder doesn't support the alpha channels on videos, so when i convert a gif into a video i get the black background on the gif as result.

Just wondering if you could possibly have a solution on this.

Best and thanks again,
Paolo

android version

develop it for android also i am searching for android from almost two weeks but could not find any library like this for android

Convert UIView to Video

Hello, I found this project cool. I just have one question does this captures a UIView activity into a video?
Thanks

Reversing video orientation issue !!!

Hi,
I tried to build a boomerang effect.
I'm facing an issue when i reverse a captured video in portrait. The final video is stretched and wrong oriented (landscaspe instead portrait).
Have you already made a boomerang effect ?
It's possible to implement it on you amazing class ?

Regards

Trying to save video to camera roll but "Operation can't be completed"

I can see in my files that the image is being converted properly, but I just can't save it to camera roll. Any suggestions?

`VideoGenerator.fileName = "image"
VideoGenerator.shouldOptimiseImageForVideo = true
VideoGenerator.videoDurationInSeconds = 10

VideoGenerator.current.generate(withImages: [img], andAudios: [], andType: .single, { (progress) in
  print(progress)
}, success: { (url) in
  print(url)
  
  PHPhotoLibrary.shared().performChanges({
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)
  }, completionHandler: { success, error in
    if success {
      print("Successful")
    } else if let error = error {
      print("\(error.localizedDescription)")
    }
  })
}, failure: { (error) in
  print(error)
  let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
  alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil))
  self.present(alert, animated: true, completion: nil)
})`

Memory leak when shouldOptimiseImageForVideo = true

Tried to create video from single image with shouldOptimiseImageForVideo = true, and the memory went up to 280MB or so and stayed there. If I set shouldOptimiseImageForVideo = false the memory remains at around 64MB.

Make video from multiple image and single audio file

I have made video from single image and audio file successfully and its working great.
Now I want to make video from multiple image and single audio file. Can anyone tell me solution for this?

Like from this one:

VideoGenerator.current.fileName = "ABC"
VideoGenerator.current.videoBackgroundColor = .black
 VideoGenerator.current.generate(withImages: [receive_Image[0], receive_Image[1], receive_Image[2]], andAudios: [song_Url], andType: .multiple, { (progress) in
            print(progress)
        }, success: { (video_url) in
            
        }) { (error) in
           
        }

Issue with Generating video - Last black images is showing

Hi, I am creating the video from multiple images. So i am facing issue i.e. sometimes i found black frame in last seconds of video that progress of images is not completed. If you found any reference for reproducing this bug , please ping me here
Seeking for your positive response.

Blocking the main thread

Hello,

Thanks for this library.
I'm trying to make a video with multiple images. But when it come to generate the video, my application freeze. In fact it freeze before unlock and print progress.
Is there any way to do it without blocking the UI ?

Thanks

Unable to run this project in SWIFT 3

I had Downloaded this project but I am getting Following errors

screen shot 2018-11-23 at 10 32 24 am

and I had also tried to install pod but I am getting Following Errors

screen shot 2018-11-23 at 10 33 46 am

How can I use this project in swift 3

Please Help!
Thanks

Uppercase extensions do not match when filtering movie formats

Honestly I'm not sure if this is the reason why it doesnt work for me but it seems if the file extension is MOV instead of mov the file gets skipped.

I ended up writing my own code for merging since that was the only reason I wanted the library, you may want to have a look

Animation

I think should be animate from one clip to another clip.

MergeMultipleVideo not works

Hello There

Thanks for providing such a wonderful library

I am working on videoEditingApp and your library provide such a great help..:)

I want to integrate the video merge feature into my app but the code which is written in class not works , it just result me the first video

I also checked in your demo it also not work there.

Will you please check and update the code please

Thanks :)

add text

I want to create a video from images audio and text

Request for custom image durations

It would be nice to be able to pass in an array of integer durations parallel to the image array.

This would allow each image to have a custom duration.

This media format is not supported

When trying to merge videos in my documents directory it throws this error, both are in mp4 format.

Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo={NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x28323e130 {Error Domain=NSOSStatusErrorDomain Code=-16976 "(null)"}}

Merge video with audio

Hi,
Thank you for this project, I really like it. Is there a possibility to add this feature to the project:
Merging one Video with one Audio without any images.

This can be used to:
1- Replace an audio of a certain video with a new audio.
2- Add an audio to a muted video.

I would love for this feature to be added.

Multi orientation videos

Hi, I really like your project, thanks for sharing. Im working on a private project where I would like to make the videocomposition landscape for all videos if just one of the videos selected for merge is landscape. and then rotate the rest of the portrait oriented videos accordingly while having black spaces on each side. Will you please point me in the right direction in regards of makeing an addition to you great project. I think this particually part is missing in most video merge projects I've seen...

Last video in array of multiple videos dicatates whether previous videos are mirrored

I am using an iPhone 6 (I know its quite old) with the newest iOS and the newest Swift in my Xcode and noticed something odd when I used the pod. Namely, when I recorded several videos and merged them in my project app using the URLs, the last video I added to the array invariably decided how the videos were mirrored. All of my videos are recorded in portrait orientation. I just want them to be merged the way they are, i.e. no (further) mirroring (as front camera videos are already mirrored), no change in orientation.

Here a couple of small examples of what I mean (f denotes a video recorded with the front camera, r with the rear camera):

  • [f, f, f] --> merged video stayed correctly mirrored
  • [f, r, f] --> merged video stayed correctly mirrored for the f parts of the video but falsely mirrored for the r part (which shouldn't be mirrored at all and wasn't mirrored before)
  • [f, f, r, f, r] --> merged video stayed correctly _un_mirrored for the r parts of the video but falsely _un_mirrored for the f parts, too (and since the f parts used to be mirrored it appears they have been "mirrored back" to unmirrored)

I guess this is somewhat related to issue #1 but thought it was quite old and it didn't seem to capture these observations so I hope it is ok that I open this issue. I love the pod so far but this has been really bugging me somehow... Is this issue already known? If not, is there a workaround? I'm not very familiar with AVFoundation but if there is no other solution, couldn't one check if the last video is "f" or "r" and adjust the other videos' mirroring accordingly?

I would really appreciate some help! Please let me know if anything remains unclear. I'll provide as much information as I can.

How to split video inside for loop?

            for chunk in chunks {
                VideoGenerator.current.splitVideo(withURL: url!, atStartTime: Double(chunk[0]), andEndTime: Double(chunk[1]), success: { (url) in
                    self.videoArray.append(url)
                    print("chunk: videoArray: \(self.videoArray)")
                    print("chunk: videoArray count: \(self.videoArray.count)")
                }) { (err) in
                    print("Error: \(err)")
                }
            }

Modify playtime of images

We want the generator to play the images with duration of 1 second. Which parameters do we have to change?

When we set 'maxVideoLenght' to nofImages * 1 second, the images play 3 seconds instead and the video is cut.

memory issue

Dear developer
when i generate images to video with type singleAudioMultipleImage.It cause high memory and high cpu. I add about 350 images and average image size is 250k.

Getting Code=-11800 when merging videos

So I am getting this error:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16364), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x600000d45a10 {Error Domain=NSOSStatusErrorDomain Code=-16364 "(null)"}}

when merging videos. Couple of notes:

  1. video urls are in tmp directory as it is not needed in the future.
  2. File is in mp4 format(sample filename: vlc-record-2019-07-13-06h23m44s-rtsp___wowzaec2demo.streamlock.net_vod_mp4_BigBuckBunny_115k.mov-.mp4)
  3. the video was generated by VLC
  4. When added a 10 second delay, videos can be merge successfully.

Any tips are appreciated!

Video orientation issue while merging.

Hello team,
Thanks for this amazing library.

While using your library I found an issue, when I am merging two landscape recorded videos (1st from back camera and 2nd from the front camera in iPhone 7) the 1st video gets wrong orientation in my case flipped upside down.

It will be really helpful if you solve this issue as soon as possible.

again thanks for your contribution to the community.

Cannot access output video from Albums

It seems that the generated videos have been saving to
file:///var/mobile/Containers/Data/Application/2E99B180-8C77-4853-BB21-EC0228800FE3/Documents/singleMovie.m4v
I cannot access the output video from Albums. How can I acces the output video from Albums?

Issue in creating video from multiple frames

Hi Team ,

Please find attached code and video where we are creating the video from multiple frames.

So we are using your code to create video from multiple frames. So you can see in video that we are getting 52 frames and we would need 60 frames to make the complete video. It happens most of times but not always. So I am sharing the sample as well. Please suggest what I am doing wrong. I am creating video from front camera not back camera.

Video Link :- https://tinyurl.com/y5z7352t

Code Link :- https://tinyurl.com/yxmo9d5s

Please let me know if you need any reference.

Change the time of fps for video.

I didn't any way to change the duration of one image or frame in your library. I suppose it's possible to add this functionality ))

This media format is not supported

Hello, I'm using the generate(withImages) func to generate a 5 second audio-less video file using an image and then using that video in a merge command. However, when attempting to use the new video generated from an image I keep getting an error saying: "Cannot Open" "This media format is not supported". However, when I pull the video file from phone I can see that it generated correctly and plays without audio just fine on my mac. Here's the code I'm using to generate the audio-less video file from the image:

`
VideoGenerator.current.fileName = selectedStoryboardItem.name
VideoGenerator.current.maxVideoLengthInSeconds = 5
VideoGenerator.current.videoBackgroundColor = .black
VideoGenerator.current.shouldOptimiseImageForVideo = true

VideoGenerator.current.generate(withImages: [image], andAudios: [], andType: .single, { (progress) in

                }, success: { (videoURL) in
                    print("finished with url: \(videoURL)")
                    print("Docs Dir: \(self.documentsDirectory())")
                    DispatchQueue.main.async {
                        selectedStoryboardItem.vidoeURL = videoURL
                        
                        self.updateStoryboardItems(with: selectedStoryboardItem)
                    }
                }) { (error) in
                    print("Failed to generate video from image with error: \(error)")
                }

`

And here's the code I'm using to generate the merge video:

`
VideoGenerator.mergeMovies(videoURLs: urls, andFileName: videoName, success: { (videoURL) in
DispatchQueue.main.async {
loadingView.removeFromSuperview()

            self.player.url = videoURL
        }
    }) { (error) in
        DispatchQueue.main.async {
            loadingView.removeFromSuperview()
            print("Failed to generate video with error: \(error)")
            
            let alert = UIAlertController(title: "Oops", message: error.localizedDescription, preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }

`

Here's the error I'm getting from the merge func while using the video generated from an image:

Failed to generate video with error: Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo={NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x6000004109c0 {Error Domain=NSOSStatusErrorDomain Code=-16976 "(null)"}}

Split Video

Hi I'm trying to split the video with the time frame but it's not working as I have also checked in the example split video not working I didn't find any video on the URL which I get after splitting the video

Video corruption after merge

Hello,

I'm encoutering an issue when I'm trying to merge two .mov video. After merging them, the resulting video appear to be corrupted on other OS (Windows, Ubuntu) or browser (Firefox, Chrome), but working well with QuickTime on MacOS.

Here is the code :

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
        
    guard let firstVideoUrl = Bundle.main.url(forResource: "part1", withExtension: "mov"),
        let secondVideoUrl = Bundle.main.url(forResource: "part2", withExtension: "mov") else {
            assertionFailure("Can't get videos url.")
            return
    }
        
    VideoGenerator.fileName = "mergedVideo"
    VideoGenerator.mergeMovies(videoURLs: [secondVideoUrl, firstVideoUrl], success: { (videoURL) in
        self.share(url: videoURL)
    }) { (error) in
        print(error)
    }
}

You can reproduce this issue with this sample project : https://github.com/floriangbh/video-merge-issue-demo
The result video of the merge is available on this link : https://firebasestorage.googleapis.com/v0/b/speedtest-dev/o/mergedVideo.m4v?alt=media&token=c917f475-49a8-40e6-a5de-2bfdba8501fe (you can open it with Firefox or Chrome to see the corruption).

Have you any idea how to fix it ?

Thanks,
Florian

Setup parameter for specific picture view duration!

Hi,

many thanks for this awesome code.

I was wondering if its possible to setup a specific duration between each image?

First example:

100 images and I want to generate a movie which shows every image for 2 seconds.

Second example:

2.500 images and I want to generate a movie which shows every image for 0,2 seconds ( in other words: 3 images per second ).

Is it possible to add a imageViewDuration param or do you have any suggestions how I can modify/ enhance the code?

Many Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.