Skip to content

Latest commit

 

History

History
121 lines (85 loc) · 3.47 KB

README.md

File metadata and controls

121 lines (85 loc) · 3.47 KB

Overview:

This is just a research to dig up the power of FFmpegKit to enable live streaming from the device's camera to RTMP or RTSP servers. FFmpegKit provides a convenient wrapper around FFmpeg, making it easy to capture, encode, and transmit audio and video streams.

This is also to to check how well it does against the existing live streaming packages like Haishinkit

Features:

Inputs

  • Camera
  • Microphone
  • File

RTMP

  • Ingest to RTMP server
  • Playback (Todo)

RTSP

  • Ingest to RTSP server
  • Playbakc (Todo)

SRT

  • Ingest to SRT server

HLS

  • Playback (Todo)

UDP Support

  • Ingest using UDP protocol

Others minor features

  • Toggle Torch
  • Switch Camera
  • Background Publishing

Usage

Initialize the Source and FFLiveKit

let cameraSource = CameraSource(position: .front)
let microphoneSource = MicrophoneSource()
/// add options
let ffLiveKit = FFLiveKit(options: [.outputVideoSize((360, 640)), .outputVideoBitrate("400k")])

Initialize the connections according to your need

let srtConnection = try! SRTConnection(baseUrl: "srt://192.168.1.100:8890?streamid=publish:mystream&pkt_size=1316")
let rtmpConnection = try! RTMPConnection(baseUrl: "rtmp://192.168.1.100:1935/mystream")
let rtspConnection = try! RTSPConnection(baseUrl: "rtsp://192.168.1.100:8554/mystream")
let udpConnection = try! UDPConnection(baseUrl: "udp://192.168.1.100:1234?pkt_size=1316")

Connect

try! ffLiveKit.connect(connection: rtmpConnection)

Add source

ffLiveKit.addSources(sources: [cameraSource, microphoneSource])
cameraSource.startPreview(previewView: self.view)
ffLiveKit.prepare(delegate: self)

Start or Stop

if !isRecording {
    try? ffLiveKit.publish()
} else {
    ffLiveKit.stop()
}

Delegates

func _FFLiveKit(didChange status: RecordingState)
func _FFLiveKit(onStats stats: FFStat)
func _FFLiveKit(onError error: String)

Options

public enum FFLivekitSettings {
    case outputVideoFramerate(Int)
    case outputVideoPixelFormat(String)
    case outputVideoSize((Int, Int))
    /// example "500k" or "2M"
    case outputVideoBitrate(String)
    /// example "128k"
    case outputAudioBitrate(String)

    /// nil to no transpose
    /// 0 - Rotate 90 degrees counterclockwise and flip vertically.
    ///1 - Rotate 90 degrees clockwise.
    /// 2 - Rotate 90 degrees counterclockwise.
    /// 3 - Rotate 90 degrees clockwise and flip vertically.
    case outputVideoTranspose(Int?)
}

Demo

out.mp4

Research

Please find the research on https://github.com/sxudan/FFLivekit/blob/research/README.md