Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Python to execute a command on every file in a folder
    primarykey
    data
    text
    <p>I'm trying to create a Python script that would :</p> <ol> <li>Look into the folder "/input"</li> <li>For each video in that folder, run a mencoder command (to transcode them to something playable on my phone)</li> <li>Once mencoder has finished his run, delete the original video.</li> </ol> <p>That doesn't seem too hard, but I suck at python :)</p> <p>Any ideas on what the script should look like ?</p> <p>Bonus question : Should I use</p> <blockquote> <p>os.system</p> </blockquote> <p>or</p> <blockquote> <p>subprocess.call</p> </blockquote> <p>?</p> <p>Subprocess.call seems to allow for a more readable script, since I can write the command like this :</p> <blockquote> <p>cmdLine = ['mencoder', sourceVideo, '-ovc', 'copy', '-oac', 'copy', '-ss', '00:02:54', '-endpos', '00:00:54', '-o', destinationVideo]</p> </blockquote> <p>EDIT : Ok, that works :</p> <pre><code>import os, subprocess bitrate = '100' mencoder = 'C:\\Program Files\\_utilitaires\\MPlayer-1.0rc2\\mencoder.exe' inputdir = 'C:\\Documents and Settings\\Administrator\\Desktop\\input' outputdir = 'C:\\Documents and Settings\\Administrator\\Desktop\\output' for fichier in os.listdir(inputdir): print 'fichier :' + fichier sourceVideo = inputdir + '\\' + fichier destinationVideo = outputdir + '\\' + fichier[:-4] + ".mp4" commande = [mencoder, '-of', 'lavf', [...] '-mc', '0', sourceVideo, '-o', destinationVideo] subprocess.call(commande) os.remove(sourceVideo) raw_input('Press Enter to exit') </code></pre> <p>I've removed the mencoder command, for clarity and because I'm still working on it.</p> <p>Thanks to everyone for your input.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload