Search code examples
pythonvlc

control vlc with python


I would need two things in vlc that I want to control from a Python script. First is to open a network stream, add the stream address as a url in it and play it. (This might be skippable)

The second thing is to take a snapshot at a specific time and use that picture. As I saw the different kind of libraries and modules, they can only things like play, pause, rewind a video.

Can anybody help me with this one?

Thanks in advance!


Solution

  • You can use os.chdir(path) and os.system(command)

    Find where your vlc executable (.exe) is, and store the path in a variable. Then you can use os.system to execute a given command.

    Here you see a list of possible command-line options for VLC

    Example code:

    import os
    
    vlc_path = "C:\path\to\vlc"
    net_stream = "http://host[:port]/file" # You can use other protocols too
    
    os.chdir(vlc_path)
    os.system(f"vlc {net_stream}")