@@ -26,7 +26,7 @@ def __init__(self,video_file):
26
26
except :
27
27
raise IOError ('ffprobe not found.' )
28
28
if os .path .isfile (video_file ):
29
- p = subprocess .check_output (["ffprobe" ,"-show_streams" ,self .video_file ],stderr = subprocess .PIPE ,shell = True )
29
+ p = subprocess .Popen (["ffprobe" ,"-show_streams" ,self .video_file ], stdout = subprocess . PIPE ,stderr = subprocess .PIPE ,shell = True )
30
30
self .format = None
31
31
self .created = None
32
32
self .duration = None
@@ -36,14 +36,24 @@ def __init__(self,video_file):
36
36
self .video = []
37
37
self .audio = []
38
38
datalines = []
39
- for a in str (p .decode ( sys . stdout .encoding )). split ( ' \n ' ):
39
+ for a in iter (p .stdout .readline , b' ' ):
40
40
if re .match ('\[STREAM\]' ,a ):
41
41
datalines = []
42
42
elif re .match ('\[\/STREAM\]' ,a ):
43
43
self .streams .append (FFStream (datalines ))
44
44
datalines = []
45
45
else :
46
46
datalines .append (a )
47
+ for a in iter (p .stderr .readline , b'' ):
48
+ if re .match ('\[STREAM\]' ,a ):
49
+ datalines = []
50
+ elif re .match ('\[\/STREAM\]' ,a ):
51
+ self .streams .append (FFStream (datalines ))
52
+ datalines = []
53
+ else :
54
+ datalines .append (a )
55
+ p .stdout .close ()
56
+ p .stderr .close ()
47
57
for a in self .streams :
48
58
if a .isAudio ():
49
59
self .audio .append (a )
@@ -100,7 +110,11 @@ def frameSize(self):
100
110
size = None
101
111
if self .isVideo ():
102
112
if self .__dict__ ['width' ] and self .__dict__ ['height' ]:
103
- size = (int (self .__dict__ ['width' ]),int (self .__dict__ ['height' ]))
113
+ try :
114
+ size = (int (self .__dict__ ['width' ]),int (self .__dict__ ['height' ]))
115
+ except Exception as e :
116
+ print "None integer size %s:%s" % (str (self .__dict__ ['width' ]),str (+ self .__dict__ ['height' ]))
117
+ size = (0 ,0 )
104
118
return size
105
119
106
120
def pixelFormat (self ):
@@ -121,7 +135,10 @@ def frames(self):
121
135
f = 0
122
136
if self .isVideo () or self .isAudio ():
123
137
if self .__dict__ ['nb_frames' ]:
124
- f = int (self .__dict__ ['nb_frames' ])
138
+ try :
139
+ f = int (self .__dict__ ['nb_frames' ])
140
+ except Exception as e :
141
+ print "None integer frame count"
125
142
return f
126
143
127
144
def durationSeconds (self ):
@@ -132,7 +149,10 @@ def durationSeconds(self):
132
149
f = 0.0
133
150
if self .isVideo () or self .isAudio ():
134
151
if self .__dict__ ['duration' ]:
135
- f = float (self .__dict__ ['duration' ])
152
+ try :
153
+ f = float (self .__dict__ ['duration' ])
154
+ except Exception as e :
155
+ print "None numeric duration"
136
156
return f
137
157
138
158
def language (self ):
@@ -177,7 +197,10 @@ def bitrate(self):
177
197
"""
178
198
b = 0
179
199
if self .__dict__ ['bit_rate' ]:
180
- b = int (self .__dict__ ['bit_rate' ])
200
+ try :
201
+ b = int (self .__dict__ ['bit_rate' ])
202
+ except Exception as e :
203
+ print "None integer bitrate"
181
204
return b
182
205
183
206
if __name__ == '__main__' :
0 commit comments