Vlc python - help please with displaying a dynamic Twitter hashtag overlay

This forum is about all development around libVLC.
jason6565
New Cone
New Cone
Posts: 4
Joined: 11 Sep 2018 23:12

Vlc python - help please with displaying a dynamic Twitter hashtag overlay

Postby jason6565 » 13 Sep 2018 15:25

Hello all

I’m trying to create a python script to do the following:
  • Generate a unique hashtag
    Play an ‘idle/Call to Action’ video on loop in fullscreen. The video will contain a message encouraging the user to interact with the screen by sending a tweet to a pre-defined twitter account.
    VLC then displays a dynamic text overlay, preferably in the bottom right area of the screen. The text will include the unique hashtag created in the first step.
    The Python script then scans the Twitter streaming api looking to see if the dynamic hashtag has been tweeted. On success, VLC then plays a ‘Tweet received video’ (the python script will also send some commands to some Arduinos to do some other stuff like flash some LEDs/operate some 24v motors/launch a missile strike against North Korea/and so on)
    After TweetReceived.mp4 has played out (duration 30 seconds) the python script then loops back to the beginning and starts again (creates a new hashtag which is overlayed on top of the Call to Action video
Below is a sample of the code that I have cobbled together so far. This almost achieves the user journey outlined above but it’s a bit clunky, especially the transition from Call_To_Action.mp4 to TweetReceived.mp4 and back again (the transition looks a better if the desktop (explorer.exe) is disabled)

As you can see I’m launching two instances of VLC, one to play the CallToAction.mp4 with hashtag, and the second instance to play TweetReceived.mp4 video with no hashtag. I’m a newbie to python and VLC player so I have no doubt there is probably a better and more efficient way of achieving all of this. I’m not even sure if I’ve initialised the VLC instances in the correct sequence and manner.

I’m using the –sub-source=marq(marquee= to write the dynamic hashtag. Is it possible to use subtitles instead? I’ve tried searching the internet and studying the LibVLC documentation pages for examples on how to use subtitles with VLC-python but if I’m perfectly honest I couldn’t understand the documentation. As I said earlier I’m a newbie to all of this and the LibVLC documentation is clearly written with advanced users in mind and not learners.

So to recap, is it possible to use a single instance of VLC to achieve the user-journey above and subtitles to display the dynamic hashtag?

Any help and/or suggestions will be gratefully received.

Cheers - Jason

p.s. the platform I'm using is:
Windows 7 64 bit
Python 3.7
VLC 2.2.6

Code: Select all

import vlc import random import time from twython import Twython, TwythonStreamer, TwythonError def create_Hashtag(): #create random hashtag code between 1000-9999 rand_code=random.randint(9000,9999) rand_code=str(rand_code) hashtag = ("#nameOfEvent" + rand_code) return hashtag def search_TwitterStream(hashtag): # this function scans twitter stream to check for hashtag being tweeted # On success returns true. For brevity of forum post, actual code not included, available on request time.sleep(15) # simulate time it takes for someone to read the hashtag and send tweet on their phone return True def main(CTA_video, TweetReceived_video): while True: hashtag = create_Hashtag() #setup Player1 instance dynamicHashtag= ' --mouse-hide-timeout=0 ', '--sub-source=marq{marquee=%s @eventHandle ,position=10, size=60, color=16777215 } ' % hashtag vlc_instance = vlc.Instance(dynamicHashtag) media1 = vlc_instance.media_new(CTA_video) player1 = vlc_instance.media_player_new() player1.set_media(media1) medialist = vlc.MediaList(CTA_video) CTA_playlist = vlc.MediaListPlayer() CTA_playlist.set_media_player(player1) CTA_playlist.set_media_list(medialist) player1.set_fullscreen(True) CTA_playlist.set_playback_mode(vlc.PlaybackMode.loop) player1.play() search_TwitterStream(hashtag) # call function to check if hashtag has been tweeted #matching tweet has been received blankHashtag= ' --mouse-hide-timeout=0 ', '--sub-source=marq{marquee= ,position=10, size=60, color=16777215 } ' vlc_instance2 = vlc.Instance(blankHashtag) media2 = vlc_instance2.media_new(TweetReceived_video) player2 = vlc_instance2.media_player_new() player2.set_media(media2) medialist2 = vlc.MediaList(TweetReceived_video) Tweet_playlist = vlc.MediaListPlayer() Tweet_playlist.set_media_player(player2) Tweet_playlist.set_media_list(medialist2) player2.set_fullscreen(True) player2.play() #play tweetreceived.mp4 over CallToAction.mp4 #call function to send commands to arduinos to their stuff time.sleep(5) player1.stop() time.sleep(30 - 5) # duration of tweetReceived.mp4 is 30 seconds player2.stop() #loop to start of main() #startup CTA_video = "C:/someFolder/media/CallToAction.mp4" TweetReceived_video = "C:/someFolder/media/tweetReceived.mp4" main(CTA_video, TweetReceived_video)

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Vlc python - help please with displaying a dynamic Twitter hashtag overlay

Postby mfkl » 18 Sep 2018 16:43

Is it possible to use subtitles instead?
I'd assume so. Have you tried creating a subtitle file and putting it next to the video file and renaming it to the same name of the video?
is it possible to use a single instance of VLC to achieve the user-journey above [...] ?
What's preventing you from using a single instance? Why did you use two instances in the first place?
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: m1adow and 27 guests