'Open Video file in VLC through Python
import subprocess
import os
print os.path.exists("C:/Users/Dhruv/Desktop/Motivation/RiseShine.mp4")
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","C:/Users/Dhruv/Desktop/Motivation/RiseShine.mp4"])
The code above is to open a video file in VLC player using python. The VLC player opens up, but does not run the video. I have checked the video location, it is correct. Can somebody tell me how to make this work?
Solution 1:[1]
This worked for me (Python 3.4):
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","\\E:\Movies\\" + title + '.mp4'])
The video tested was definitely in mp4 format, btw.
Solution 2:[2]
According to https://wiki.videolan.org/VLC_command-line_help, you should specify a file stream as follows:
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","file:\\\Users\Dhruv\Desktop\Motivation\RiseShine.mp4"])
Solution 3:[3]
subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","C:\\Users\\USERNAME\\Desktop\\videos\\example.mp4"])
The difference is in the way to put the: ' \ ' , ' // '
Solution 4:[4]
Raw Strings and Back Slashes are your friend here:
path = r"C:\Users\Dhruv\Desktop\Motivation\RiseShine.mp4"
print(path)
Output, a correctly formatted for the command-line string:
'C:\\Users\\Dhruv\\Desktop\\Motivation\\RiseShine.mp4'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | xduckxman99x |
Solution 2 | jr-be |
Solution 3 | Eric Aya |
Solution 4 | BeRT2me |