我正在尝试将文件夹中视频文件的尺寸存储到列表中。
#!/usr/bin/env python
# src_dimensions.py
# requires mediainfo package
import subprocess
proc = subprocess.Popen('mediainfo --Inform="Video;%Width%x%Height%\n" /home/saad/Videos/*.*', shell=True, stdout=subprocess.PIPE)
for line in iter(proc.stdout.readline,''):
print line
该程序的结果输出是:
384x288640x480480x350352x162480x360640x360480x360384x288240x180320x240480x360384x288346x26
当我mediainfo
在终端中运行命令时,每个视频维度都在换行符上:
384x288
640x480
480x350
352x162
480x360
我希望每个维度都作为单独的项目存储在列表中。我正在尝试迭代,stdout
但它不起作用。
更新#1
import subprocess
dim = []
proc = subprocess.Popen('mediainfo --Inform="Video;%Width%x%Height%\\n" /home/saad/Videos/*.*', shell=True, stdout=subprocess.PIPE)
for line in iter(proc.stdout.readline, ''):
dim.append(line.rstrip('\n'))
print dim
感谢@Chakib 的建议,这似乎给了我列表。
['440x360', '320x240', '480x360', '320x240', '480x360', '320x240', '320x240', '400x224', '']