One of the most important functionality in library is handling RTSP. Using online streams or saving video from your web cam is as easy as handling local streams. It works the best with SetInputTime to limit recording to a limited time.
string output = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + FileExtensions.Mp4);
var mediaInfo = await FFmpeg.GetMediaInfo("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
var conversionResult = await FFmpeg.Conversions.New()
.AddStream(mediaInfo.Streams)
.SetInputTime(TimeSpan.FromSeconds(3))
.SetOutput(output)
.Start();
CancellationToken is another option to stop capturing.
string output = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + FileExtensions.Mp4);
var mediaInfo = await FFmpeg.GetMediaInfo("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
FFmpeg.Conversions.New()
.AddStream(mediaInfo.Streams)
.SetOutput(output)
.Start(cancellationTokenSource.Token);
await Task.Delay(5000);
cancellationTokenSource.Cancel();
For more advanced usage it is possible to input stream. Example below shows how to rotate it. A lot of others methods can be used instead of Rotate.
string output = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + FileExtensions.Mp4);
var mediaInfo = await FFmpeg.GetMediaInfo("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
var videoStream = mediaInfo.VideoStreams.First();
videoStream.Rotate(RotateDegrees.Clockwise);
var conversionResult = await FFmpeg.Conversions.New()
.AddStream(videoStream)
.SetOutput(output)
.Start();
In the contrary sometimes we need to send some data to remote server. There are two snippets that can help. SendToRtspServer() and SendDesktopToRtspServer.
/// <summary>
/// Loop file infinitely to rtsp streams with some default parameters like: -re, -preset ultrafast
/// </summary>
/// <param name="inputFilePath">Path to file</param>
/// <param name="rtspServerUri">Uri of RTSP Server in format: rtsp://127.0.0.1:8554/name</param>
/// <returns>IConversion object</returns>
Task<IConversion> SendToRtspServer(string inputFilePath, Uri rtspServerUri);
/// <summary>
/// Send desktop infinitely to rtsp streams with some default parameters like: -re, -preset ultrafast
/// </summary>
/// <param name="rtspServerUri">Uri of RTSP Server in format: rtsp://127.0.0.1:8554/name</param>
/// <returns>IConversion object</returns>
Task<IConversion> SendDesktopToRtspServer(Uri rtspServerUri);
Some parameters are set with default values. Every stream is changed to use stream loop, native input stream and bitrate to 1024000. Framerate is set to 23.976 and libx264 and aac are used as codecs. Except that pixel format is changed to yuv420p and preset UltraFast is enabled.