Skip to content

Latest commit

 

History

History
154 lines (109 loc) · 5.22 KB

File metadata and controls

154 lines (109 loc) · 5.22 KB

SIPSorceryMedia.FFmpeg

NuGet NuGet downloads

Cross-platform audio and video media end-points for the SIPSorcery real-time communications library, built on top of native FFmpeg libraries via FFmpeg.AutoGen.

Tested on Windows, macOS, and Linux.

Licence note. Unlike the rest of the SIPSorcery family this package is licensed under LGPL-2.1-only (because it links FFmpeg at runtime, and FFmpeg's default build is LGPL). Make sure that's acceptable for your application before depending on it.

Installation

dotnet add package SIPSorcery
dotnet add package SIPSorceryMedia.FFmpeg

You also need the FFmpeg shared libraries installed on the target machine -- this NuGet package wraps FFmpeg, it doesn't ship the binaries. See Installing FFmpeg below.

What is in here

Codecs

  • Video: VP8, H.264, H.265, MJPEG.
  • Audio: PCMU (G.711), PCMA (G.711), G.722, G.729, Opus.

Sources

Class Source kind
FFmpegFileSource Local files or remote URIs (HTTP, RTSP, ...) -- audio + video.
FFmpegCameraSource Local webcam capture -- video.
FFmpegScreenSource Screen / monitor capture -- video.
FFmpegMicrophoneSource Microphone capture -- audio.

You can mix any video source (or none) with any audio source (or none) when assembling a media session.

Encoders / decoders

Class Purpose
FFmpegVideoEncoder IVideoEncoder -- VP8 / H.264 / H.265 / MJPEG encode + decode.
FFmpegAudioEncoder IAudioEncoder -- audio codec encode + decode for the codecs above.
FFmpegVideoEndPoint Convenience pairing of source + encoder + sink.

Limitations

  • No audio output. This package does not provide a speaker / playback end-point. For audio playback pair it with a platform end-point such as SIPSorceryMedia.Windows on Windows or SIPSorcery.SDL2 on other platforms.

Installing FFmpeg

The shared libraries this package binds to must be discoverable on the target machine's library load path. Typical setups:

Windows

The simplest path is winget:

winget install "FFmpeg (Shared)" --version 8.1

That puts the DLLs somewhere SIPSorceryMedia.FFmpeg can find them.

Alternative -- download a "shared" build from gyan.dev/ffmpeg/builds/#release-builds or use the binaries shipped with FFmpeg.AutoGen, and add them to your PATH.

Linux

sudo apt install ffmpeg

(Equivalent for dnf, pacman, etc. on other distributions.)

macOS

brew install ffmpeg
brew install mono-libgdiplus    # for the test apps that draw bitmaps

FFmpeg version compatibility

This package targets the FFmpeg 8.1 ABI via FFmpeg.AutoGen 8.1.0. Older or much newer FFmpeg installations may load with PInvoke errors. If you see EntryPointNotFoundException or DllNotFoundException at startup, the most common cause is an FFmpeg version mismatch.

Quickstart -- WebRTC video to a browser

The WebRTCTestPatternServer example shows the minimal end-to-end path: a video test-pattern source, encoded with FFmpeg's H.264 encoder, sent over WebRTC to a browser.

Sketch:

using SIPSorcery.Media;
using SIPSorcery.Net;
using SIPSorceryMedia.FFmpeg;

FFmpegInit.Initialise();   // load the shared libs on whatever PATH is configured

var pc = new RTCPeerConnection(null);
var source = new VideoTestPatternSource(new FFmpegVideoEncoder());

var track = new MediaStreamTrack(source.GetVideoSourceFormats(), MediaStreamStatusEnum.SendOnly);
pc.addTrack(track);

source.OnVideoSourceEncodedSample += pc.SendVideo;
pc.OnVideoFormatsNegotiated += formats => source.SetVideoSourceFormat(formats.First());

Testing

The repo includes a console test harness at test/FFmpegFileAndDevicesTest that exercises file, camera, and screen sources end-to-end.

Related packages

License

LGPL-2.1-only. The rest of the SIPSorcery family is BSD-3-Clause; this package is the exception because of FFmpeg's licensing.