unosquare/ffmediaelement

Cannot initialize with ffmpeg options set in MediaInitialization event

Videstra opened this issue · 2 comments

e.Configuration.PrivateOptions("rtsp_transport") = "tcp" (and other options) generate Generic.KeyNotFoundException

Note: I am using Visual Studio 2015 with vb.net and .net 4.6.1

I need to reduce latency and can confirm with ffmpeg dll build I am using that the following options do reduce latency considerably.
(confirmed with ffplay)

ffplay -fflags nobuffer -flags low_delay -framedrop -rtsp_transport tcp <rtsp url>

Trying to use the PrivateOptions in the mediaelement only generates
e.Configuration.PrivateOptions("rtsp_transport") = "tcp" 'e.Configuration.PrivateOptions("rtsp_transport") = "tcp"' threw an exception of type 'System.Collections.Generic.KeyNotFoundException' Boolean {System.Collections.Generic.KeyNotFoundException}
This code comes directly from the sample provided from the github download.

if (e.MediaSource.StartsWith("rtsp://", StringComparison.OrdinalIgnoreCase))
            {
                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";  //generates the KeyNotFoundException
                e.Configuration.GlobalOptions.FlagNoBuffer = true;         //does not generate an error

                // You can change the open/read timeout before the packet reading
                // operation fails. Reaching a tiemout limit will fire the MediaFailed event
                // with a TiemoutException
                e.Configuration.ReadTimeout = TimeSpan.FromSeconds(10);
            }

I have refactored this to vb.net (sorry gang) and tried setting other privateoptions - all resulting in the KeyNotFoundException in the debugger. It does NOT throw an exception when executing, but does show the keynotfound exception in the debugger.

    Private Sub OnMediaInitializing(sender As Object, e As Unosquare.FFME.Common.MediaInitializingEventArgs) Handles Media.MediaInitializing
        'calls as an attempt to reduce latency on the video playback over rtsp.   
        Try
            If e.MediaSource.StartsWith("rtsp://", StringComparison.InvariantCultureIgnoreCase) Then
                e.Configuration.PrivateOptions("rtsp_transport") = "tcp"
                e.Configuration.PrivateOptions("flags") = "low_delay"
                e.Configuration.PrivateOptions("framedrop") = ""    'an attempt to set the parameterless -framedrop option (see ffplay command line)
               'the following three calls do appear to execute without an exception
                e.Configuration.GlobalOptions.FlagNoBuffer = True
                e.Configuration.GlobalOptions.MaxAnalyzeDuration = TimeSpan.Zero
                e.Configuration.GlobalOptions.ProbeSize = 32
            End If
        Catch ex As Exception

        End Try
    End Sub

Issue Categories

  • Bug
  • Feature Request
  • Question
  • Not sure

Version Information

  • NuGet Package 4.4.350
  • Build From Master branch, Commit Enter commit id. Example: 704c482
  • Build from Branch Name, Commit Enter commit id. Example: 704c482

XAML

<UserControl x:Class="BolinPTZWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Videstra"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Loaded="BolinWPFWindow_Loaded">
    <Grid>
        <Canvas x:Name="GlassCanvas" HorizontalAlignment="Left" Height="450" Margin="-5,-5,0,-5" VerticalAlignment="Top" Width="800">
            <ffme:MediaElement x:Name="Media" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" Height="450" Width="800" />
        </Canvas>
    </Grid>
</UserControl>

C#

                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
                e.Configuration.PrivateOptions["flags"] = "low_delay";
                e.Configuration.PrivateOptions["framedrop"] = "";    'an attempt to set the parameterless -framedrop option

Command line ffplay

**ffplay -fflags nobuffer -flags low_delay -framedrop -rtsp_transport tcp <rtsp url>**

Closed the issue. Discovered the property is a dictionary and I was looking at in the the debugger before it was set. This is still not resulting in lowered latency, but that is likely a different issue. The admin can delete the above issue if so desired.

+1 even when setting flags you cannot get low latency...