Search code examples
c#ffmpeguwph.264mediaelement

Media Element Display H264 bitstream [UWP]


I am developing an application that should play streaming video

I am trying to play h264 streaming video in MediaElement, but MediaElement remains empty

I use FFmpeg as the video source

ffmpeg -r 20   -f gdigrab   -i desktop   -f mpegts  -vcodec libx264 udp://127.0.0.1:5555 

On the client-side (UWP) I use the FFmpegInterop library The codec and resolution of the video are detected correctly, but the MediaElement does not play anything

I've also tried using MJPEG, for example

ffmpeg -r 20 -f gdigrab -i desktop -f mjpeg -vcodec mjpeg udp://127.0.0.1:5555

Everything works correctly. RTSP stream also works, for example from OBS studio, and in this case, the codec is defined as h264

It turns out that the problem can only be on the transmitting side? Is it possible to use only the UDP protocol for this purpose? Maybe I missed some FFmpeg settings?

 private async void MediaPlayer_Loaded(object sender, RoutedEventArgs e)
    {
            MediaPlayer.Loaded -= MediaPlayer_Loaded;

            FFmpegInteropLogging.SetDefaultLogProvider();
            FFmpegInteropConfig options = new FFmpegInteropConfig();
            options.PassthroughVideoH264 = true;
            options.SkipErrors = 1000;
            options.PassthroughVideoHEVC = true;
            options.PassthroughVideoH264Hi10P = true;
           decoder = awaitFFmpegInteropMSS.CreateFromUriAsync("udp://127.0.0.1:5555",options);

            var mediaStreamSource = decoder.GetMediaStreamSource();
            mediaStreamSource.BufferTime = TimeSpan.FromSeconds(0);
            Debug.WriteLine(decoder.VideoStream.CodecName);

            MediaPlayer.MediaFailed += MediaPlayer_MediaFailed;
            MediaPlayer.SetMediaStreamSource(mediaStreamSource);
            MediaPlayer.Play();
}

Solution

  • Setting the property VideoDecoderMode = VideoDecoderMode.ForceFFmpegSoftwareDecoder solved the problem.