Skip to content

irons163/IRPlayer-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Platform

IRPlayer-swift

IRPlayer-swift is a powerful video player framework for iOS.

  • Use IRPlayer to play video.
    • See demo.
  • Use IRPlayer to make video player with custom UI.
  • Use IRPlayer to play IP Camera stream.
  • Use IRPlayer to make Screen Recoder.
  • Use IRPlayer to make RTMP streaming.
  • Use IRPlayer to make video player with effects .
  • Real Live player App.

Features

  • Support Normal video mode.
  • Support VR mode.
  • Support VR Box mode.
  • Support Fisheye mode.
    • Support Normal Fisheye mode.
    • Support Fisheye to Panorama mode.
    • Support Fisheye to Perspective mode.
  • Support multi windows.
  • Support multi modes selection.
  • Support set the specific renders to each mode.
  • Support custom video input(IRFFVideoInput). See what it works in IRIPCamera.
  • Support custom display view(inherit IRGLView). See what it works in IREffectPlayer.
  • Support SPM.

Install

SPM

Usage

The following two ways could let you get started quickly without any build errors.

  1. Run the SPMDemo which inside this project. OR
  2. Run this simplest implement to valid IRPlayer-swift.
import UIKit
import IRPlayerSwift

class ViewController: UIViewController {

    var player = IRPlayerImp.player()

    override func viewDidLoad() {
        super.viewDidLoad()

        if let view = player.view {
            self.view.addSubview(view)
        }
        player.replaceVideoWithURL(contentURL: NSURL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
        player.play()
    }
}

Basic

Regiser actions

lazy var player: IRPlayerImp = {
    return IRPlayerImp.player()
}()
    
self.player.registerPlayerNotification(target: self,
                                       stateAction: #selector(stateAction(_:)),
                                       progressAction: #selector(progressAction(_:)),
                                       playableAction: #selector(playableAction(_:)),
                                       errorAction: #selector(errorAction(_:)))
self.player.viewTapAction = { (player, view) in
    print("player display view did click!")
}
if let playerView = self.player.view {
    self.mainView.insertSubview(playerView, at: 0)
}

Set mode and video source

switch self.demoType {
case .avPlayerNormal:
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.normalVideo as NSURL)
case .avPlayerVR:
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.vrVideo as NSURL)
case .avPlayerVRBox:
    self.player.displayMode = .box
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.vrVideo as NSURL)
case .ffmpegNormal:
    self.player.decoder.mpeg4Format = .ffmpeg
    self.player.decoder.ffmpegHardwareDecoderEnable = false
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.normalVideo as NSURL)
case .ffmpegNormalHardware:
    self.player.decoder = IRPlayerDecoder.FFmpegDecoder()
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.normalVideo as NSURL)
case .ffmpegFisheyeHardware:
    self.player.decoder = IRPlayerDecoder.FFmpegDecoder()
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.fisheyeVideo as NSURL)
case .ffmpegPanoramaHardware:
    self.player.decoder = IRPlayerDecoder.FFmpegDecoder()
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.fisheyeVideo as NSURL)
case .ffmpegMultiModesHardwareModesSelection:
    self.player.decoder = IRPlayerDecoder.FFmpegDecoder()
    modes = self.createFisheyeModes(with: nil)
    let sharedRender = IRGLRenderNV12()
    for mode in modes ?? [] {
        mode.renderer = sharedRender;
    }
    self.player.renderModes = modes
    self.player.replaceVideoWithURL(contentURL: PlayerViewController.fisheyeVideo as NSURL)
    self.modesButton.isHidden = false
}

Set custom video frames source

  • Send video frames directly.
let input = IRFFVideoInput()
self.player.replaceVideoWithInput(input, videoType: .normal)

......

var yuvFrame = IRFFAVYUVVideoFrame()
/*
setup the yuvFrame.
*/
input.send(videoFrame: yuvFrame)
  • Send video frames by your own decode implement.
  • See how it works in IRIPCamera-swift.
class MyIRFFVideoInput: IRFFVideoInput {

    override func videoDecoder(_ videoDecoder: IRFFVideoDecoderInfo, decodeFrame packet: AVPacket) -> IRFFVideoFrame? {

        asyncHWDecode()

        return nil // if it is sync decode instead, return videoFrame from here.
    }
    
    func asyncHWDecode() {
        Task {
            // let videoFrame = ......
            self.videoOutput?.send?(videoFrame: videoFrame)
        }
    }
}

Advanced settings

NSArray *modes = [self createFisheyeModesWithParameter:nil];
self.player.renderModes = modes;
[self.player replaceVideoWithURL:fisheyeVideo videoType:IRVideoTypeCustom];


func createFisheyeModes(with parameter: IRMediaParameter?) -> [IRGLRenderMode] {
    let normal = IRGLRenderMode2D()
    let fisheye2Pano = IRGLRenderMode2DFisheye2Pano()
    let fisheye = IRGLRenderMode3DFisheye()
    let fisheye4P = IRGLRenderModeMulti4P()
    let modes = [
        fisheye2Pano,
        fisheye,
        fisheye4P,
        normal
    ]

    normal.shiftController.enabled = false
    fisheye2Pano.contentMode = .scaleAspectFill
    fisheye2Pano.wideDegreeX = 360
    fisheye2Pano.wideDegreeY = 20
    fisheye4P.parameter = IRFisheyeParameter(width: 0, height: 0, up: false, rx: 0, ry: 0, cx: 0, cy: 0, latmax: 80)
    fisheye.parameter = fisheye4P.parameter
    fisheye4P.aspect = 16.0 / 9.0
    fisheye.aspect = fisheye4P.aspect

    normal.name = "Rawdata"
    fisheye2Pano.name = "Panorama"
    fisheye.name = "Onelen"
    fisheye4P.name = "Fourlens"

    return modes
}

Screenshots

Normal VR VR Box Fisheye 360
Normal VR VR Box Fisheye 360
Panorama Modes Selection Multi Windows
Panorama Modes Selection Multi Windows
Mac Player 1 Mac Player 2
Mac Player 1 Mac Player 2

Credit

This project has some basic codes from SGPlayer.
FFMpeg xcframeworks are from ffmpeg-kit.

About

IRPlayer is a powerful video player framework for iOS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages