Problems using marquee with python-vlc

97 Views Asked by At

A complete newbie here…

I’m currently trying to create a video player using python-vlc and PyQt5 (on a Mac) and it’s going pretty well…. My code is way to messy and embarrassing and filled with awkwardly named variables, so I’d have to clean it up thoroughly before I’d dare post it here (apologies for that). However, in the meantime, I’m struggling with a specific problem with which I hope someone can help me:

I’m trying to get some textual feedback on screen whenever stuff happens (skipping ahead, changing speed, volume, etc.). It seems to me that the simplest way would be to use Vlc’s builtin ‘marquee’ function, but I really can’t get it to work. I have searched everywhere for examples or docs on how to use it and found very few pages, most of which point to the humongous vlc.py file which comes with the ‘python-vlc’ distribution (iirc). Apparently, it’s way over my head because I can’t quite figure out what’s going on there or how to extract the information I need from it.

I wonder it anyone can provide or point me to a really simple example of using marquee with python-vlc. Something like play a video -> press a button -> marquee text appears. Many thanks!!!

Let me just quickly outline what I did try:

I tried to add the marquee option while creating the vlc instance with:

self.Instance = vlc.Instance("--sub-source marq") 

and:

self.Instance = vlc.Instance("--sub-filter=marq")

I also tried: self.instance = vlc.Instance("--video-title-show --video-title-timeout 1 --sub-source marq --verbose -1") #as suggested somewhere

Also tried to add the option while creating the media player with:

self.mediaplayer = self.instance.media_player_new("sub-filter=marq") #completely breaks video playback

and:

self.mediaplayer = self.instance.media_player_new(sys.argv[1], "sub-filter=marq") # IndexError: list index out of range

I tried each one separately as well as different combinations to no avail…

When I add the line (whether in the __init__ method or any other method):

self.mediaplayer.video_set_marquee_int(vlc.VideoMarqueeOption.Enable, 1)

No errors generated and nothing happens…

When I try to add another line containing the marquee option, such as:

self.mediaplayer.video_set_marquee_string(VideoMarqueeOption.Text, "Some Text")

I get NameError: name 'VideoMarqueeOption' is not defined

So I really don’t understand what’s going on here….

Any help with this will be greatly appreciated at this point (just please don’t refer me again to that vlc.py file…)

1

There are 1 best solutions below

0
Rolf of Saxony On

This is the simplest example I can think of.

import vlc
import time

instance = vlc.Instance('--no-xlib --quiet --sub-source=marq')
player = instance.media_player_new()
media = instance.media_new("/home/rolf/BBB.ogv")
player.set_media(media)
player.video_set_marquee_int(0, 1) #Enable
player.video_set_marquee_int(6, 48)  # size in pixels
player.video_set_marquee_int(4, 8) # position | bottom
player.video_set_marquee_int(7, 0) # timeout

#player.video_set_marquee_string(1, 'First marquee String') # using a fixed parameter
player.video_set_marquee_string(vlc.VideoMarqueeOption.Text, 'First marquee String') # using the vlc function

player.play()
for iter in range(45):
    if iter == 15:
        player.video_set_marquee_string(1, "Marquee Changes") # new text
    if iter == 30:
        player.video_set_marquee_string(1, "Final Marquee Change") # new text
    time.sleep(0.5)

I get NameError: name 'VideoMarqueeOption' is not defined

That is because VideoMarqueeOption is a function in vlc.py that converts a named option to a number.

You will have a similar problem with Position.

So either use the vlc function i.e. vlc.VideoMarqueeOption or a fixed parameter e.g. 1

At this point I dash your hopes and refer you to either the vlc documentation or vlc.py for a full list of the options and their number equivalents. :)