Quantcast
Viewing all articles
Browse latest Browse all 4824

Graphics, sound and multimedia • Attempting to synchronise LED flashing routine with video playback using python

I am trying to synchronise neopixel LEDs flashing with a video being played using a Raspberry Pi 3B+ and the Python wrappers for libVLC (VLC player). For example, I want the LED to flash red at exactly 2000ms of video playback and green at 5500ms etc.

I can get the timings in-between the LED flashes accurate enough in Python (to within a few ms) but I cannot seem to synchronise the start of the video playback with the start of the timing for the LEDs. I want the video playback and the LED routine to start within a few milliseconds of each other so that the LED timings line up correctly with the video.

I have already tried a few things

1) Initialise the video player, load the media, sleep in the script a few seconds to let the player start and load the media. Call play() and immediately start the LED timings.
-- The playback is always delayed after play is called for 100+ms it seems causing the LEDs to trigger earlier than wanted

2) Query for State.Playing using player.get_state() in a while True loop and starting the LEDs immediately after detection
-- The state change seems to be delayed by 100+ms despite the getState being called in a busy loop, this causes the LED routine to start late

3) Adding a few seconds of black screen to the start of the video, calling player.get_time() after a second or so and sleeping for the duration until the 'start' of the real part of the video
get_time() doesn't seem to give accurate timings, it appears to only update itself every 300ms or so giving it a large window where it is off the actual video progress.

I feel like I am running into a brick wall here with VLC and am unsure how to get it to reliable start playing at a certain time. Are there any alternatives I should be considering here? Any way to get more accurate timing for when to start the LED routine? I preferably want the delay to be less than 30ms so that the difference is mostly imperceptible to the eye whilst the video playback technique not being so intensive as to affect the running of the LED routine which is updating at an (almost) perfect 60fps.

Statistics: Posted by jkh13 — Tue Jul 09, 2024 10:40 am



Viewing all articles
Browse latest Browse all 4824

Trending Articles