Skip to content

Instantly share code, notes, and snippets.

@schauveau
Last active January 21, 2024 12:30
Show Gist options
  • Save schauveau/cb3ec6a855d16f3982760d0b256f808c to your computer and use it in GitHub Desktop.
Save schauveau/cb3ec6a855d16f3982760d0b256f808c to your computer and use it in GitHub Desktop.
Workaround for the black preview bug in Flowblade

IMPORTANT: The trick described below is now obsolete. Use SDL12COMPAT_NO_QUIT_VIDEO=1 instead

The issue is described here jliljebl/flowblade#1134

I am using the Wayland compositor Sway and for me, the preview in Flowblade is always black even when using XWayland.

I found a way to move the preview to a separate window.

SIMPLY SPEAKING, THIS IS NOT A BUG FIX BUT AN UGLY HACK TO MAKE FLOWBLADE USABLE FOR PEOPLE AFFECTED BY ISSUE 1134!!!!

All changes are in the file mltplayer.py.

Step 1 : In create_sdl_consumer() change the line

       self.consumer = mlt.Consumer(self.profile, "sdl")

into

       self.consumer = mlt.Consumer(self.profile, "sdl2")

Step 2: In set_sdl_xwindow() comment or remove the line

       # os.putenv('SDL_WINDOWID', str(widget.get_window().get_xid()))

Remark: After that, it should be possible to start Flowblade as a pure Wayland application using GDK_BACKEND=wayland SDL_VIDEODRIVER=wayland. However, there are other issues such as the popup windows not opening properly so it is better to keep using x11 for now.

After those two steps, Flowblade should now open a separate preview window. The main issue is that this window has the size defined in the current project profile (so probably far too large to be useful unless you have a dual-screen system.)

I tried various ways to change the width and height of the consumer with various undesirable side effects.

My understanding is that the Consume stores his dimension in its profile which is problematic because it is created using the project profile which is also used for the final rendering.

For example, if the project profile is 1920x1080 and you set the preview window to 640x480 then the final rendering will be done using 640x80.

I found ways to change the dimensions of the player consumer without changing its profile but, sometimes, the preview window is resized or recreated using the full project dimensions. I could not figure out why. Very strange!

What works well is to create a dedicated profile for the player consumer.

Step 3 : in init_for_profile() replace

        self.profile = profile

by

        self.profile =  mlt.Profile()

        # The default profile created by mlt.Profile() has all the characteristics of
        # "DV/DVD PAL" so 720x576 at 25fps.
        #
        # Let's reuse some settings from the project profile.
        #
        # Remark: the width and height will be set in create_sdl_consumer
        #
        self.profile.set_sample_aspect( profile.sample_aspect_num(), profile.sample_aspect_den() )
        self.profile.set_display_aspect( profile.display_aspect_num(), profile.display_aspect_den() )
        self.profile.set_frame_rate( profile.frame_rate_num(), profile.frame_rate_den())        

Step 4: in create_sdl_consumer() add the following lines to set the dimensions of the preview window.

        # Set the width and height of the preview window to whatever you find acceptable.         
        # It is best to respect the display_aspect otherwise the dimensions will be adjusted
        # and the actual aspect ratio may be incorrect.
        # I do not really understand what is going on here!!!!!
        # The sample_aspect may also be important but so far I only tested with 1:1. MORE TESTS NEEDED
        w = 640 
        h = ( w * self.profile.display_aspect_den() ) // self.profile.display_aspect_num()
        self.consumer.set("width",  w )
        self.consumer.set("height", h )

After all those changes, Flowblade should now provide a usable preview window.

Known issues:

  • The preview window is recreated each and every time the main Flowblade window is resized and also when previewing an image or a video clip.
  • The preview window is resizable but its content is not.
  • The player window is still visible and is using a lot of screen space for nothing. You may want to overlay the preview window above it if possible.
  • Keyboard shortcuts do not work in the preview window. Instead, use the main window or the player window.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment