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
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
let cameraSource = CameraSource(position: .front)
let microphoneSource = MicrophoneSource()
/// add options
let ffLiveKit = FFLiveKit(options: [.outputVideoSize((360, 640)), .outputVideoBitrate("400k")])
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")
try! ffLiveKit.connect(connection: rtmpConnection)
ffLiveKit.addSources(sources: [cameraSource, microphoneSource])
cameraSource.startPreview(previewView: self.view)
ffLiveKit.prepare(delegate: self)
if !isRecording {
try? ffLiveKit.publish()
} else {
ffLiveKit.stop()
}
func _FFLiveKit(didChange status: RecordingState)
func _FFLiveKit(onStats stats: FFStat)
func _FFLiveKit(onError error: String)
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?)
}
out.mp4
Please find the research on https://github.com/sxudan/FFLivekit/blob/research/README.md