@@ -118,11 +118,22 @@ def export_pyav(sequence, filename, rate=30, bitrate=None,
118
118
else :
119
119
raise NotImplemented
120
120
121
- output = av .open (str (filename ), str ('w' ), format = format , options = options )
122
121
# Maximum allowed timebase is 66535 (at least for mpeg4)
123
122
# see https://github.com/mikeboers/PyAV/issues/242
124
123
export_rate_frac = Fraction (export_rate ).limit_denominator (65535 )
125
- stream = output .add_stream (codec , rate = export_rate_frac )
124
+
125
+ output = av .open (str (filename ), str ('w' ), format = format )
126
+ try :
127
+ # from PyAv 6.0, options can be supplied here
128
+ stream = output .add_stream (
129
+ codec , rate = export_rate_frac , options = options
130
+ )
131
+ except TypeError : # before, we should supply it at .open
132
+ output = av .open (
133
+ str (filename ), str ('w' ), format = format , options = options
134
+ )
135
+ stream = output .add_stream (codec , rate = export_rate_frac )
136
+
126
137
stream .pix_fmt = str (pixel_format )
127
138
128
139
for frame_no in itertools .count ():
@@ -157,7 +168,10 @@ def export_pyav(sequence, filename, rate=30, bitrate=None,
157
168
158
169
# Finish encoding the stream
159
170
while True :
160
- packet = stream .encode ()
171
+ try :
172
+ packet = stream .encode ()
173
+ except av .AVError : # End of file raises AVError since after av 0.4
174
+ break
161
175
if packet is None :
162
176
break
163
177
output .mux (packet )
0 commit comments