Using Python to execute a command on every file in a folder

前端 未结 6 1077
旧时难觅i
旧时难觅i 2020-12-01 01:44

I\'m trying to create a Python script that would :

  1. Look into the folder \"/input\"
  2. For each video in that folder, run a mencoder command (to transcode
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 02:27

    AVI to MPG (pick your extensions):

    files = os.listdir('/input')
    for sourceVideo in files:
        if sourceVideo[-4:] != ".avi"
            continue
        destinationVideo = sourceVideo[:-4] + ".mpg"
        cmdLine = ['mencoder', sourceVideo, '-ovc', 'copy', '-oac', 'copy', '-ss',
            '00:02:54', '-endpos', '00:00:54', '-o', destinationVideo]
        output1 = Popen(cmdLine, stdout=PIPE).communicate()[0]
        print output1
        output2 = Popen(['del', sourceVideo], stdout=PIPE).communicate()[0]
        print output2
    

提交回复
热议问题