A high-performance, flexible, and easy-to-use Video compressor library written by Swift.

Overview

FYVideoCompressor

A high-performance, flexible and easy to use Video compressor library written by Swift. Using hardware-accelerator APIs in AVFoundation.

Version License Platform

Usage

Compress with quality param

public enum VideoQuality: Equatable {
        /// Scale video size proportionally, not large than 224p and
        /// reduce fps and bit rate if need.
        case lowQuality
        
        /// Scale video size proportionally, not large than 480p and
        /// reduce fps and bit rate if need.
        case mediumQuality
        
        /// Scale video size proportionally, not large than 1080p and
        /// reduce fps and bit rate if need.
        case highQuality
        
        /// reduce fps and bit rate if need.
        /// Scale video size with specified `scale`.
        case custom(fps: Float, bitrate: Int, scale: CGSize)
}

Set VideoQuality to get different quality of video, beside, you can set custom fps, bitrate and scale:

FYVideoCompressor.shared.compressVideo(yourVideoPath, quality: .lowQuality) { result in
            switch result {
            case .success(let compressedVideoURL):
            case .failure(let error):
            }
 }

Compress with more customized configuration param

public struct CompressionConfig {
        // video
        let videoBitrate: Int // bitrate use 1000 for 1kbps.https://en.wikipedia.org/wiki/Bit_rate
        
        let videomaxKeyFrameInterval: Int // A key to access the maximum interval between keyframes. 1 means key frames only, H.264 only
        
        let fps: Float // If video's fps less than this value, this value will be ignored.
        
        // audio
        let audioSampleRate: Int
        
        let audioBitrate: Int
        
        let fileType: AVFileType
        
        /// Scale (resize) the input video
        /// 1. If you need to simply resize your video to a specific size (e.g 320×240), you can use the scale: CGSize(width: 320, height: 240)
        /// 2. If you want to keep the aspect ratio, you need to specify only one component, either width or height, and set the other component to -1
        ///    e.g CGSize(width: 320, height: -1)
        let scale: CGSize?
    }

Configure your configuration, then compress your video:

let config = FYVideoCompressor.CompressionConfig(videoBitrate: 1000_000,
                                                                                        videomaxKeyFrameInterval: 10,
                                                                                        fps: 24,
                                                                                        audioSampleRate: 44100,
                                                                                        audioBitrate: 128_000,
                                                                                        fileType: .mp4,
                                                                                        scale: CGSize(width: 640, height: 480))
FYVideoCompressor.shared.compressVideo(yourVideoPath, config: config) { result in
            switch result {
            case .success(let compressedVideoURL):
            case .failure(let error):
            }
 }
You might also like...
A SwiftUI framework which makes it easy to integrate Video Call and Chat within a few lines of code.

Welcome to iStream! This SwiftUI Framework allows you to add Video Call and Chat to your project within a few lines of code. To use this Framework, yo

A video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding.

ffavc ffavc is a video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding. Build ffmpeg First, make s

360 video player for iOS written in swift - a subset of SceneKit that works
360 video player for iOS written in swift - a subset of SceneKit that works

DDDKit An open source library to support 360 videos and pictures. It's designed as a generic 3D library that you can use for much more! Example of use

Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey
Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey

Video player with support for Invidious and Piped instances built for iOS 15, tvOS 15 and macOS Monterey.

Yattee: video player for Invidious and Piped built for iOS, tvOS and macOS
Yattee: video player for Invidious and Piped built for iOS, tvOS and macOS

Video player for Invidious and Piped instances built for iOS, tvOS and macOS. Features Native user interface built with SwiftUI Multiple instances and

▶️ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

Swift Package used for video where I demonstrate how to extract a package to a local framework and modify it.
Swift Package used for video where I demonstrate how to extract a package to a local framework and modify it.

SegmentedPicker NOTE: This sample code is taken from the article by Frank Jia in his article titled Build a Custom iOS Segmented Control With SwiftUI

A set of tools to trim, crop and select frames inside a video

PryntTrimmerView A set of tools written in swift to crop and trim videos. Example To run the example project, clone the repo, and run pod install from

Repository with base samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Includes steps for encoding and packaging your own test content.

Video Everything Repository with minimal samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Content and License All t

Comments
  • Crashed when compressing two videos

    Crashed when compressing two videos

    error msg:

    [AVAssetReaderTrackOutput copyNextSampleBuffer] cannot copy next sample buffer before adding this output to an instance of AVAssetReader (using -addOutput:) and calling -startReading on that asset reader"
    
    bug 
    opened by fakerlogic 6
  • Crashed when setting one of the scale size component to -1

    Crashed when setting one of the scale size component to -1

    FYVideoCompressor.shared.compressVideo(
                            mediaURL,
                            quality: .custom(
                                ...
                                scale: CGSize(width: -1, height: 720)
                            )
                        )
    

    Error: [AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:] AVVideoSettings dictionary must specify a positive width"

    opened by Wsewlad 1
  • Crash on older device when app enters background while converting

    Crash on older device when app enters background while converting

    The lib crashed at self.group.leave() in the code block

    outputVideoData(videoInput, videoOutput: videoOutput, duration: duration, progressHandler: progressHandler) {
          self.group.leave()
      }
    

    I tested on an iphone 6 ios 12 with a video of size 200mb and after 5 seconds since the conversion started, I minimize the app for 3 seconds and go back to active state. Crash doesnt happen on iphone x with similar reproduction steps. I guess there may be an unparalleled match between group.enter() and group.leave() in the block. Please advise any possible improvement.

    opened by tapgitk 0
  • Can't complete when doing batch convert

    Can't complete when doing batch convert

    I tried batch convert with outputVideoDataByReducingFPS . Compression completed successfully when there are 2 instances of FYVideoCompressor or less, when there are 3 or more instances, at least one instance couldn't go to completion block writer.finishWriting. The failed time as I logged at let cmTime = CMSampleBufferGetPresentationTimeStamp(newSamplePointee) almost reached the end time of the uncompleted video.

    Please advise, thanks for your great work.

    opened by tapgitk 1
Releases(0.0.8)
Owner
null
Hide the "Latest Video Performance" tab in YouTube Studio

Hide Latest Video Performance - YT Studio Extension that hides the stupid YouTube Studio "Latest Video Performance" / "Latest YouTube Short Performanc

Taranasus 2 Jul 22, 2022
High-quality Interactive Audio/Video Unity SDK

简体中文 | English TRTC Unity SDK Overview Leveraging Tencent's many years of experience in network and audio/video technologies, Tencent Real-Time Commun

LiteAVSDK 3 May 10, 2022
A Swift library to upload video files to api.video platform.

api.video IOS video uploader api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and manag

api.video 7 Jan 10, 2022
A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.

A high-level video composition framework build on top of AVFoundation. It's simple to use and easy to extend. Use it and make life easier if you are implementing video composition feature.

VideoFlint 1.4k Sep 26, 2022
YHPlayer - An easy-to-use video player based on swift language

YHPlayer An easy-to-use video player based on swift language Features Plays loca

null 8 Feb 21, 2022
Video mp4 record save display - How to Take , Save and Display a .mp4 Video

Technicalisto How to Take , Save and Display a .mp4 Video Add your design with v

Aya Baghdadi 2 Aug 7, 2022
A fully functional short video app project.Record a six secends video while playing prank sounds.

prankPro A fully functional short video app project How to Install 1. use coconapod to init your xcode environment. 2. change the app-keys in `applica

huijimuhe 258 Jun 19, 2022
JDVideoKit - You can easily transfer your video into Three common video type.

JDVideoKit Introduction You can easily transfer your video into Three common video type. You can use set up camera easily. Installation pod 'JDVideoK

郭介騵 24 Sep 9, 2021
api.video is the video infrastructure for product builders

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

api.video 4 Jun 27, 2022
PiPifier - a macOS and iOS Safari extension that lets you use every HTML5 video in Picture in Picture mode

PiPifier is a macOS 10.12 and iOS Safari (action) extension that lets you use every HTML5 video in Picture in Picture mode macOS Download It'

Arno Appenzeller 706 Sep 19, 2022