20

I am working on a simple Python script that is supposed to do something, then play a video file, and then do some more stuff.

I am forced to do this on a Windows XP machine with Python 3.2.3 and VLC to play my video file.

I am currently using this code...

vlc_path = '\\path\\to\\vlc.exe'
video_path = '\\path\\to\\video\\file'
subprocess.call([vlc_path, video_path])

... to open VLC and play the video. It works nicely. However, the script waits for VLC to quit before it goes on. Which is good and I want to keep it that way.

My question is: Is there a way to quit VLC right after the video file has been played?

Thanks a lot for any help!

Florian
  • 579
  • 1
  • 10
  • 19

4 Answers4

44

Funnily enough, vlc has a command line option for this:

  --play-and-exit, --no-play-and-exit
                             Play and exit (default disabled)

So, just pass this option to vlc.

FatalError
  • 52,695
  • 14
  • 99
  • 116
  • 1
    Thank you, this worked perfectly. One thing that seemed to be important is that you set `shell=True`. This worked for me: `subprocess.call([vlc_path, video_path, '--play-and-exit', '--fullscreen'], shell=True)` – Florian Apr 24 '12 at 15:51
  • 1
    @Florian. Strange. For me `shell=False` worked, and `True` didn't. However, thanks for your implementation! – Mathias711 Dec 12 '14 at 13:49
  • This did not work for me running vlc on Windows 10. However adding the dummy item mentioned below did the trick. – Tobias Ramforth Oct 16 '15 at 13:08
  • remark: if loop playback is active, this won't work (makes sense though) – Alex M.M. Jun 14 '20 at 16:25
9

Another option would be to pass the dummy item vlc://quit, e.g.:

vlc audio1.mp3 audio2.mp3 vlc://quit

Source: https://wiki.videolan.org/Transcode/#Completely_non-interactive_transcoding

Glutanimate
  • 1,692
  • 20
  • 21
1

If nothing works try using the option --ignore-config at the beginning after vlc in addition to http://quit at the end

Amr
  • 411
  • 6
  • 21
0

Best way I can think of is killing the process by a separate thread after video length has passed, if you know the length of the video in Python. Elsewhere, it depends on VLC-s command line options. Maybe you can tell him to close after playing the movie.

Mihnea Simian
  • 1,093
  • 1
  • 7
  • 13
  • 2
    It would be better to use the command line option here rather than uncleanly terminate the process. – logain Apr 14 '14 at 22:29