videoffmpeggstreamerraspberry-pi3omxplayer

Fire events at specific timestamps during video playback


I'm using a Raspberry Pi 3 running Raspbian. I need to play a video file via HDMI, and I need events to be fired at specific timecodes during the playback of the video. The events are simple write operations to the GPIO. My problem is : what approach should I use to do this ?

My first approach was to use OpenCv (python) and VideoCapture(), but the raspberry pi is too slow, and my FPS is very low (I need at least 25 FPS @ 1080p).

So now I'm looking into other solutions : Gstreamer, FFMPEG, omxplayer, I read the documentations but I can't figure out which tool to use for this job.


Solution

  • I finally solved this easily with omxplayer thanks to python-omxplayer-wrapper (https://github.com/willprice/python-omxplayer-wrapper)

    *EDIT: this is what a basic example code would look like:

    from omxplayer import OMXPlayer
    from time import sleep
    
    /* Setup the player as shown in omxplayer-wrapper examples : */
    source = '../video/gray10sec.mp4'
    player = OMXPlayer(source, args=['--loop', '--no-osd', '--blank'])
    player.pause()
    sleep(5)
    player.play()
    
    /* Make a query to position() inside infinite loop : */
    while (1):
        position = player.position() * 1000
        /* Event timecodes values are stored in "events" */
        for event in events.values():
            if position - 20 <= event['tc'] and position + 20 >= event['tc']:
                /* Put your code here */
    
    player.quit()