Search code examples
pythonpathvlcpopen

How to add videos to subprocess infinitively


I know the title is not very clear. But I could not find a way to express my problem properly. Let me explain: The code below can play videos from a directory perfectly. However, my problem is, The videos in the directory has names like this : 0.avi , 1.avi , 2.avi and so on... As you see in the code, the n value(which represents the video names) is increasing and the "videofilesi" is increasing too. I need to write this code infinitely if I cannot find a solution. Can somebody help me?

import definingName
import numpy as np
import cv2
import time
import os
import random
import sys
import subprocess
import os.path
import glob
import vlc
from subprocess import Popen
n=0
c = 'c'
name = definingName.defName(c)
name = os.path.join(os.getcwd(), str(name))

videofilesi = os.path.join('file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib',name,str(n)+".avi")
videofilesi2 = os.path.join('file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib',name,str(n+1)+".avi")
videofilesi3 = os.path.join('file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib',name,str(n+2)+".avi")
videofilesi4 = os.path.join('file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib',name,str(n+3)+".avi")
videofilesi5 = os.path.join('file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib',name,str(n+4)+".avi")
p = Popen(["C:/Program Files/VideoLAN/VLC/vlc.exe", videofilesi,videofilesi2,videofilesi3,videofilesi4,videofilesi5])

Solution

  • Build a list.

    base = 'file:///C:/Users/gulbe/PycharmProjects/untitled/venv/Lib'
    files = [os.path.join(base, name, f"{n}.avi") for n in range(10)]
    p = Popen(["C:/Program Files/VideoLAN/VLC/vlc.exe"] + files)