项目作者: kingslay

项目描述 :
iOS/macOS/tvOS video player
高级语言: Swift
项目地址: git://github.com/kingslay/KSPlayer.git
创建时间: 2018-05-23T08:21:06Z
项目社区:https://github.com/kingslay/KSPlayer

开源协议:GNU Lesser General Public License v2.1

下载


Build Status
Platform
License

KSPlayer

KSPlayer is a powerful media play framework for iOS, tvOS, macOS, xrOS, visionOS, Mac Catalyst, SwiftUI, Apple Silicon M1 .

English | 简体中文

Features

Functional differences between GPL version and LGPL version
Feature | LGPL | GPL |
| —————- | —————- | —————- |
|Dolby AC-4|✅|❌|
|AV1 hardware decoding|✅|❌|
|All demuxers, All decoders|✅|❌|
|Record video clips at any time|✅|❌|
|Smoothly Play 8K or 120 FPS Video|✅|❌|
|Dovi P5 displays HDR (not overheating)|✅|❌|
|Live streaming supports rewind viewing|✅|❌|
|Picture in Picture supports subtitle display|✅|❌|
|Annex-B async hardware decoding(Live Stream)|✅|❌|
|Use the fonts in the video to render subtitles|✅|❌|
|ISO Blu-ray disc playback on all Apple platforms|✅|❌|
|Use memory cache for fast seek in short time range|✅|❌|
|Cache data to Hard Drive,Preload data to Hard Drive|✅|❌|
|Offline AI real-time subtitle generation and translation|✅|❌|
|Full display of ass subtitles effect(Render as image using libass)|✅|❌|
|Play videos in a small window in the App (resumable, supports tvos and ios)|✅|❌|
|FFmpeg version|7.0.2|6.1.0|
|Record video|✅|✅|
|360° panorama video|✅|✅|
|Picture in Picture|✅|✅|
|Hardware accelerator|✅|✅|
|Seamless loop playback|✅|✅|
|De-interlace auto detect|✅|✅|
|4k/HDR/HDR10/HDR10+/Dolby Vision|✅|✅|
|Custom url protocols such as nfs/smb/UPnP |✅|✅|
|Multichannel Audio/Spatial Audio|✅|✅|
|Text subtitle/Image subtitle/Closed Captions|✅|✅|
|Search Online Subtitles(shooter/assrt/opensubtitles)|✅|✅|
|Low latency 4K live video streaming (less than 200ms on LAN)|✅|✅|
|Automatically switch to multi-bitrate streams based on network|✅|✅|

The list of App using this SDK

App Store Link| Logo |
| —————- | —————- |
|Alplayer||
|APTV||
|homeTV IPTV Player||
|IPTV +||
|LillyPlayer Video Player||
|SenPlayer||
|Smart IPTV||
|Snappier IPTV||
|Spatial Video Studio||
|SWIPTV - IPTV Smart Player||
|TracyPlayer||
|UHF - Love your IPTV|logo|
|Zen IPTV||

License

KSPlayer defaults to the GPL license (requires open-sourcing your own project code), and we hope everyone will consciously respect the licensing agreement of the KSPlayer project. Additionally, there is a paid version that adopts the LGPL license (contact us).

If due to commercial reasons, you prefer not to adhere to the GPL license or the LGPL license, you can contact us. Through our authorization, you can obtain a more flexible licensing agreement. Email: kingslay@icloud.com

Requirements

  • iOS 13+, macOS 10.15+, tvOS 13+, xrOS 1+

Demo

  1. cd Demo
  2. pod install
  • Open Demo/Demo.xcworkspace with Xcode.

Quick Start

CocoaPods

Make sure to use the latest version cocoapods 1.10.1+, which can be installed using the command brew install cocoapods

  1. target 'ProjectName' do
  2. use_frameworks!
  3. pod 'KSPlayer',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'main'
  4. pod 'DisplayCriteria',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'main'
  5. pod 'FFmpegKit',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
  6. pod 'Libass',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
  7. end

Swift Package Manager

  1. dependencies: [
  2. .package(url: "https://github.com/kingslay/KSPlayer.git", .branch("main"))
  3. ]

Usage

Initialization

  1. KSOptions.secondPlayerType = KSMEPlayer.self
  2. playerView = IOSVideoPlayerView()
  3. view.addSubview(playerView)
  4. playerView.translatesAutoresizingMaskIntoConstraints = false
  5. NSLayoutConstraint.activate([
  6. playerView.topAnchor.constraint(equalTo: view.readableContentGuide.topAnchor),
  7. playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
  8. playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
  9. playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  10. ])
  11. playerView.backBlock = { [unowned self] in
  12. if UIApplication.shared.statusBarOrientation.isLandscape {
  13. self.playerView.updateUI(isLandscape: false)
  14. } else {
  15. self.navigationController?.popViewController(animated: true)
  16. }
  17. }

Setting up a regular video

  1. playerView.set(url:URL(string: "http://baobab.wdjcdn.com/14525705791193.mp4")!)
  2. playerView.set(resource: KSPlayerResource(url: url, name: name!, cover: URL(string: "http://img.wdjimg.com/image/video/447f973848167ee5e44b67c8d4df9839_0_0.jpeg"), subtitleURL: URL(string: "http://example.ksplay.subtitle")))

Multi-definition, with cover video

  1. let res0 = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
  2. definition: "高清")
  3. let res1 = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
  4. definition: "标清")
  5. let asset = KSPlayerResource(name: "Big Buck Bunny",
  6. definitions: [res0, res1],
  7. cover: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Big_buck_bunny_poster_big.jpg/848px-Big_buck_bunny_poster_big.jpg"))
  8. playerView.set(resource: asset)

Setting up an HTTP header

  1. let options = KSOptions()
  2. options.appendHeader(["Referer":"https:www.xxx.com"])
  3. let definition = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
  4. definition: "高清",
  5. options: options)
  6. let asset = KSPlayerResource(name: "Video Name",
  7. definitions: [definition])
  8. playerView.set(resource: asset)

Listening status change

  1. // Listen to play time change
  2. playerView.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
  3. print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")
  4. }
  5. // Delegates
  6. public protocol PlayerControllerDelegate: class {
  7. func playerController(state: KSPlayerState)
  8. func playerController(currentTime: TimeInterval, totalTime: TimeInterval)
  9. func playerController(finish error: Error?)
  10. func playerController(maskShow: Bool)
  11. func playerController(action: PlayerButtonType)
  12. // `bufferedCount: 0` indicates first time loading
  13. func playerController(bufferedCount: Int, consumeTime: TimeInterval)
  14. }

Advanced Usage

  • Inherits PlayerView’s custom play logic and UI.

    1. class CustomVideoPlayerView: IOSVideoPlayerView {
    2. override func updateUI(isLandscape: Bool) {
    3. super.updateUI(isLandscape: isLandscape)
    4. toolBar.playbackRateButton.isHidden = true
    5. }
    6. override func onButtonPressed(type: PlayerButtonType, button: UIButton) {
    7. if type == .landscape {
    8. // Your own button press behaviour here
    9. } else {
    10. super.onButtonPressed(type: type, button: button)
    11. }
    12. }
    13. }
  • Selecting Tracks

    1. override open func player(layer: KSPlayerLayer, state: KSPlayerState) {
    2. super.player(layer: layer, state: state)
    3. if state == .readyToPlay, let player = layer.player {
    4. let tracks = player.tracks(mediaType: .audio)
    5. let track = tracks[1]
    6. /// the name of the track
    7. let name = track.name
    8. /// the language of the track
    9. let language = track.language
    10. /// selecting the one
    11. player.select(track: track)
    12. }
    13. }
  • Set the properties in KSOptions

    1. open class KSOptions {
    2. /// 最低缓存视频时间
    3. @Published
    4. public var preferredForwardBufferDuration = KSOptions.preferredForwardBufferDuration
    5. /// 最大缓存视频时间
    6. public var maxBufferDuration = KSOptions.maxBufferDuration
    7. /// 是否开启秒开
    8. public var isSecondOpen = KSOptions.isSecondOpen
    9. /// 开启精确seek
    10. public var isAccurateSeek = KSOptions.isAccurateSeek
    11. /// Applies to short videos only
    12. public var isLoopPlay = KSOptions.isLoopPlay
    13. /// 是否自动播放,默认false
    14. public var isAutoPlay = KSOptions.isAutoPlay
    15. /// seek完是否自动播放
    16. public var isSeekedAutoPlay = KSOptions.isSeekedAutoPlay
    17. /*
    18. AVSEEK_FLAG_BACKWARD: 1
    19. AVSEEK_FLAG_BYTE: 2
    20. AVSEEK_FLAG_ANY: 4
    21. AVSEEK_FLAG_FRAME: 8
    22. */
    23. public var seekFlags = Int32(0)
    24. // ffmpeg only cache http
    25. public var cache = false
    26. public var outputURL: URL?
    27. public var display = DisplayEnum.plane
    28. public var avOptions = [String: Any]()
    29. public var formatContextOptions = [String: Any]()
    30. public var decoderOptions = [String: Any]()
    31. public var probesize: Int64?
    32. public var maxAnalyzeDuration: Int64?
    33. public var lowres = UInt8(0)
    34. public var startPlayTime: TimeInterval = 0
    35. public var startPlayRate: Float = 1.0
    36. public var registerRemoteControll: Bool = true // 默认支持来自系统控制中心的控制
    37. public var referer: String?
    38. public var userAgent: String?
    39. // audio
    40. public var audioFilters = [String]()
    41. public var syncDecodeAudio = false
    42. // sutile
    43. public var autoSelectEmbedSubtitle = true
    44. public var subtitleDisable = false
    45. public var isSeekImageSubtitle = false
    46. // video
    47. public var videoDelay = 0.0 // s
    48. public var autoDeInterlace = false
    49. public var autoRotate = true
    50. public var destinationDynamicRange: DynamicRange?
    51. public var videoAdaptable = true
    52. public var videoFilters = [String]()
    53. public var syncDecodeVideo = false
    54. public var hardwareDecode = KSOptions.hardwareDecode
    55. public var asynchronousDecompression = true
    56. public var videoDisable = false
    57. public var canStartPictureInPictureAutomaticallyFromInline = true
    58. }

Effect

gif

Developments and Tests

Any contributing and pull requests are warmly welcome. However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. It would be appreciated if your pull requests could build and with all tests green. :)

Backers & Sponsors

Open-source projects cannot live long without your help. If you find KSPlayer to be useful, please consider supporting this
project by becoming a sponsor.

Become a sponsor through GitHub Sponsors. :heart:

Your user icon or company logo shows up this with a link to your home page.
Name| Logo |
| —————- | —————- |
|UnknownCoder807||
|skrew||
|Kimentanm||
|byMohamedali||
|nakiostudio|logo|
|CodingByJerez||
|andrefmsilva||
|romaingyh||
|FantasyKingdom||
|aart-rainey||
|nihalahmed||
|HatimDa||
|johnil||
|scorebreak||
|nsplay1990||

Thanks to nightfall708 for sponsoring a mac mini

Thanks to cdguy UnknownCoder807 skrew and LillyPlayer community for sponsoring a LG S95QR Sound Bar

Thanks to skrew and LillyPlayer community for sponsoring a 2022 Apple TV 4K

Communication

If you have a business cooperation project or want to initiate a paid consultation, you can contact me via email

1