0

I embedded libvlcsharp (using GtkDrawingArea) into my GtkSharp (GTK 3) app and I want to show transparent overlays (Labels and Images) on top of a transparent video (using GtkOverlay).

I ran into two issues doing that:

  • Opacity is not applied to the video view
  • Overlays like a label are not transparent on top of the video

The example works fine with a webview (webkit2). Are transparent video views with transparent overlays even possible with vlclib?

video with overlay text

Program.cs:

        [STAThread]
        public static void Main(string[] args)
        {
            Core.Initialize();
            Application.Init();
            var app = new Application("org.GtkTest4.GtkTest4", GLib.ApplicationFlags.None);
            app.Register(GLib.Cancellable.Current);

            using (var libvlc = new LibVLC())
            using (var mediaPlayer = new MediaPlayer(libvlc))
            {
                var window = CreateWindow();
                app.AddWindow(window);
                window.StyleContext.AddProvider(Styles.GetProvider(), UInt32.MaxValue);
                window.StyleContext.AddClass("red-background");

                var videoView = new VideoView() { MediaPlayer = mediaPlayer, Valign = Align.Center, Halign = Align.Center };
                var label = new Label { Text = "Lorem Ipsum Dolor", Valign = Align.Center, Halign = Align.Fill };
                var overlay = new Overlay { Valign = Align.Fill, Halign = Align.Fill };

                videoView.SetSizeRequest(500, 400);
                videoView.Opacity = 0.5;

                overlay.Add(videoView);
                overlay.AddOverlay(label);

                window.Add(overlay);
                window.ShowAll();

                videoView.MediaPlayer.Play(new Media(libvlc, "video.mp4"));
                Application.Run();
            }
        }

VideoView.cs:

    public class VideoView : DrawingArea, IVideoView
    {
        private MediaPlayer _mediaPlayer;

        public VideoView()
        {
            Realized += (s, e) => Attach();
        }

        [DllImport("libgdk-3.so.0", CallingConvention = CallingConvention.Cdecl)]
        internal static extern uint gdk_x11_window_get_xid(IntPtr gdkWindow);

        public MediaPlayer MediaPlayer
        {
            get => _mediaPlayer;
            set
            {
                _mediaPlayer = value;
                Attach();
            }
        }

        void Attach()
        {
            if (!IsRealized || _mediaPlayer == null)
            {
                return;
            }

            MediaPlayer.XWindow = gdk_x11_window_get_xid(Window.Handle);
        }

        void Detach()
        {
            if (!IsRealized || _mediaPlayer == null)
            {
                return;
            }

            MediaPlayer.XWindow = 0;
        }

        public void Dispose()
        {
            Detach();
            base.Dispose();
        }
    }

vlclib console output:

libEGL warning: DRI2: failed to authenticate
Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory

Used tools:

  • .NET Core 3.0.100
  • GtkSharp 3.22.24
  • LibVLCSharp 3.2.3

OS:

  • Ubuntu 18.04.3 LTS
domsch
  • 118
  • 2
  • 6
  • 1
    I don't think that GTK3 is officially supported. I might be able to try in the next few days, but no promises... – cube45 Oct 15 '19 at 05:31
  • 1
    There is an official GTK2 sample for libvlc https://github.com/videolan/vlc/blob/master/doc/libvlc/gtk_player.c but not sure that helps... – mfkl Oct 15 '19 at 07:53
  • thanks for your answers, @cube45 GTK3 is not officially supported by libvlc? – domsch Oct 18 '19 at 11:45
  • 1
    LibVLCSharp has an implementation for GTK# 2, but not for GTK# 3 as far as I know. This has nothing to do with libvlc, since libvlc only knows about X identifiers. I'm not saying that it would work better in GTK#2, I'm just saying that we never tried it, and we never tried putting overlays on any GTK# implementation. – cube45 Oct 18 '19 at 13:42
  • Then I guess my issue is related to libvlc only. In my example (VideoView.cs) I pass the xid of the DrawingArea to MediaPlayer.XWindow. vlclib creates a native window and for some reason, it's not possible to use these windows as overlays or set the opacity. – domsch Oct 18 '19 at 14:15
  • You have a few roads to investigate further I guess: 1. Try with gtk2 to see if the issue is related to the gtk version. 2. Check if/how similar project support custom view embedding with GTK (gstreamer, mpv) 3. Try adding your own transparent Window on top (similar to how we do with WPF) – mfkl Oct 21 '19 at 08:24

0 Answers0