Python中文
首页
教程
问答
标签
搜索
登录
注册
使用Python对fold中的每个文件执行命令
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试创建一个Python脚本,它将:</p> <ol> <li>查看文件夹“/input”</li> <li>对于该文件夹中的每个视频,运行mencoder命令(将它们转换为可在手机上播放的内容)</li> <li>一旦mencoder完成了他的运行,删除原始视频。</li> </ol> <p>这看起来不太难,但我对python很在行:)</p> <p>对剧本的样子有什么想法吗?</p> <p>附加问题:我应该使用</p> <blockquote> <p>os.system</p> </blockquote> <p>或者</p> <blockquote> <p>subprocess.call</p> </blockquote> <p>是吗?</p> <p>Subprocess.call似乎允许更可读的脚本,因为我可以这样编写命令:</p> <blockquote> <p>cmdLine = ['mencoder', sourceVideo, '-ovc', 'copy', '-oac', 'copy', '-ss', '00:02:54', '-endpos', '00:00:54', '-o', destinationVideo]</p> </blockquote> <p>编辑:好的,可以:</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>为了清楚起见,我已经删除了mencoder命令,因为我还在处理它。</p> <p>感谢大家的投入。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>Python可能会为此而大肆杀戮。</p> <pre><code>for file in *; do mencoder -some options $file; rm -f $file ; done </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何替换子字符串,但前提是它正好出现在两个单词之间
1 回答
如何替换字典中所有出现的指定字符
8 回答
如何替换字典中所有键的第一个字符?
4 回答
如何替换字典所有键中的子字符串
2 回答
如何替换字符串python中的变量值?
7 回答
如何替换字符串Python中的第二次迭代
2 回答
如何替换字符串y Python中不等于字符串x的所有内容?
10 回答
如何替换字符串中出现的第n个单词?
2 回答
如何替换字符串中单词的一部分
4 回答
如何替换字符串中同时出现的2个或更多特殊字符或下划线
7 回答
如何替换字符串中指定位置(索引)的字符?
5 回答
如何替换字符串中某个字符的所有匹配项?
2 回答
如何替换字符串中的
2 回答
如何替换字符串中的一个字符
10 回答
如何替换字符串中的主题(固定位置)
10 回答
如何替换字符串中的分隔逗号?
9 回答
如何替换字符串中的列名(python)?
7 回答
如何替换字符串中的制表符?
10 回答
如何替换字符串中的单个单词而不是用相同的字符替换其他单词
8 回答
如何替换字符串中的单个字符?
5 回答