scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 namespace Tests\FFMpeg\Unit\Media;
4  
5 use FFMpeg\Media\Video;
6 use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
7 use FFMpeg\Format\VideoInterface;
8  
9 class VideoTest extends AbstractStreamableTestCase
10 {
11 public function testFiltersReturnsVideoFilters()
12 {
13 $driver = $this->getFFMpegDriverMock();
14 $ffprobe = $this->getFFProbeMock();
15  
16 $video = new Video(__FILE__, $driver, $ffprobe);
17 $this->assertInstanceOf('FFMpeg\Filters\Video\VideoFilters', $video->filters());
18 }
19  
20 public function testAddFiltersAddsAFilter()
21 {
22 $driver = $this->getFFMpegDriverMock();
23 $ffprobe = $this->getFFProbeMock();
24  
25 $filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
26 ->disableOriginalConstructor()
27 ->getMock();
28  
29 $video = new Video(__FILE__, $driver, $ffprobe);
30 $video->setFiltersCollection($filters);
31  
32 $filter = $this->getMock('FFMpeg\Filters\Video\VideoFilterInterface');
33  
34 $filters->expects($this->once())
35 ->method('add')
36 ->with($filter);
37  
38 $video->addFilter($filter);
39 }
40  
41 public function testAddAudioFilterAddsAFilter()
42 {
43 $driver = $this->getFFMpegDriverMock();
44 $ffprobe = $this->getFFProbeMock();
45  
46 $filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
47 ->disableOriginalConstructor()
48 ->getMock();
49  
50 $video = new Video(__FILE__, $driver, $ffprobe);
51 $video->setFiltersCollection($filters);
52  
53 $filter = $this->getMock('FFMpeg\Filters\Audio\AudioFilterInterface');
54  
55 $filters->expects($this->once())
56 ->method('add')
57 ->with($filter);
58  
59 $video->addFilter($filter);
60 }
61  
62 public function testFrameShouldReturnAFrame()
63 {
64 $driver = $this->getFFMpegDriverMock();
65 $ffprobe = $this->getFFProbeMock();
66  
67 $at = $this->getTimeCodeMock();
68  
69 $video = new Video(__FILE__, $driver, $ffprobe);
70 $frame = $video->frame($at);
71  
72 $this->assertInstanceOf('FFMpeg\Media\Frame', $frame);
73 $this->assertSame($at, $frame->getTimeCode());
74 $this->assertSame(__FILE__, $frame->getPathfile());
75 }
76  
77 public function testSaveWithFailure()
78 {
79 $driver = $this->getFFMpegDriverMock();
80 $ffprobe = $this->getFFProbeMock();
81 $outputPathfile = '/target/file';
82 $format = $this->getMock('FFMpeg\Format\VideoInterface');
83 $format->expects($this->any())
84 ->method('getPasses')
85 ->will($this->returnValue(1));
86 $format->expects($this->any())
87 ->method('getExtraParams')
88 ->will($this->returnValue(array()));
89  
90 $configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
91  
92 $driver->expects($this->any())
93 ->method('getConfiguration')
94 ->will($this->returnValue($configuration));
95  
96 $failure = new ExecutionFailureException('failed to encode');
97 $driver->expects($this->once())
98 ->method('command')
99 ->will($this->throwException($failure));
100  
101 $video = new Video(__FILE__, $driver, $ffprobe);
102 $this->setExpectedException('FFMpeg\Exception\RuntimeException');
103 $video->save($format, $outputPathfile);
104 }
105  
106 public function testSaveAppliesFilters()
107 {
108 $driver = $this->getFFMpegDriverMock();
109 $ffprobe = $this->getFFProbeMock();
110 $outputPathfile = '/target/file';
111 $format = $this->getMock('FFMpeg\Format\VideoInterface');
112 $format->expects($this->any())
113 ->method('getExtraParams')
114 ->will($this->returnValue(array()));
115 $format->expects($this->any())
116 ->method('getPasses')
117 ->will($this->returnValue(2));
118  
119 $configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
120  
121 $driver->expects($this->any())
122 ->method('getConfiguration')
123 ->will($this->returnValue($configuration));
124  
125 $video = new Video(__FILE__, $driver, $ffprobe);
126  
127 $filter = $this->getMock('FFMpeg\Filters\Video\VideoFilterInterface');
128 $filter->expects($this->once())
129 ->method('apply')
130 ->with($video, $format)
131 ->will($this->returnValue(array('extra-filter-command')));
132  
133 $capturedCommands = array();
134  
135 $driver->expects($this->exactly(2))
136 ->method('command')
137 ->with($this->isType('array'), false, $this->anything())
138 ->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands) {
139 $capturedCommands[] = $commands;
140 }));
141  
142 $video->addFilter($filter);
143 $video->save($format, $outputPathfile);
144  
145 foreach ($capturedCommands as $commands) {
146 $this->assertEquals('-y', $commands[0]);
147 $this->assertEquals('-i', $commands[1]);
148 $this->assertEquals(__FILE__, $commands[2]);
149 $this->assertEquals('extra-filter-command', $commands[3]);
150 }
151 }
152  
153 /**
154 * @dataProvider provideSaveData
155 */
156 public function testSaveShouldSave($threads, $expectedCommands, $expectedListeners, $format)
157 {
158 $driver = $this->getFFMpegDriverMock();
159 $ffprobe = $this->getFFProbeMock();
160  
161 $configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
162  
163 $driver->expects($this->any())
164 ->method('getConfiguration')
165 ->will($this->returnValue($configuration));
166  
167 $configuration->expects($this->once())
168 ->method('has')
169 ->with($this->equalTo('ffmpeg.threads'))
170 ->will($this->returnValue($threads));
171  
172 if ($threads) {
173 $configuration->expects($this->once())
174 ->method('get')
175 ->with($this->equalTo('ffmpeg.threads'))
176 ->will($this->returnValue(24));
177 } else {
178 $configuration->expects($this->never())
179 ->method('get');
180 }
181  
182 $capturedCommands = array();
183 $capturedListeners = null;
184  
185 $driver->expects($this->exactly(count($expectedCommands)))
186 ->method('command')
187 ->with($this->isType('array'), false, $this->anything())
188 ->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands, &$capturedListeners) {
189 $capturedCommands[] = $commands;
190 $capturedListeners = $listeners;
191 }));
192  
193 $outputPathfile = '/target/file';
194  
195 $video = new Video(__FILE__, $driver, $ffprobe);
196 $video->save($format, $outputPathfile);
197  
198 foreach ($capturedCommands as $passKey => $pass) {
199 $prefix = null;
200 if (count($expectedCommands) > 1) {
201 // look for pass commands only in multipass cases
202 foreach ($pass as $command) {
203 $prefix = null;
204 if (false !== strpos($command, '/pass-')) {
205 $prefix = $command;
206 break;
207 }
208 }
209  
210 if (null === $prefix) {
211 $this->fail('Unable to find pass prefix command.');
212 }
213 }
214  
215 $found = false || (null === $prefix);
216 foreach ($pass as $key => $command) {
217 if ($command === $prefix) {
218 $found = true;
219 unset($capturedCommands[$passKey][$key]);
220 $capturedCommands[$passKey] = array_values($capturedCommands[$passKey]);
221 break;
222 }
223 }
224  
225 if (!$found) {
226 $this->fail('Unable to find pass prefix command back.');
227 }
228 }
229  
230 $this->assertEquals($expectedCommands, $capturedCommands);
231 $this->assertEquals($expectedListeners, $capturedListeners);
232 }
233  
234 public function provideSaveData()
235 {
236 $format = $this->getMock('FFMpeg\Format\VideoInterface');
237 $format->expects($this->any())
238 ->method('getExtraParams')
239 ->will($this->returnValue(array()));
240 $format->expects($this->any())
241 ->method('getKiloBitrate')
242 ->will($this->returnValue(663));
243 $format->expects($this->any())
244 ->method('getAudioKiloBitrate')
245 ->will($this->returnValue(92));
246 $format->expects($this->any())
247 ->method('getAudioChannels')
248 ->will($this->returnValue(2));
249 $format->expects($this->any())
250 ->method('getPasses')
251 ->will($this->returnValue(2));
252 $format->expects($this->any())
253 ->method('getAdditionalParameters')
254 ->will($this->returnValue(array('foo', 'bar')));
255  
256 $format2 = $this->getMock('FFMpeg\Format\VideoInterface');
257 $format2->expects($this->any())
258 ->method('getExtraParams')
259 ->will($this->returnValue(array()));
260 $format2->expects($this->any())
261 ->method('getKiloBitrate')
262 ->will($this->returnValue(663));
263 $format2->expects($this->any())
264 ->method('getAudioKiloBitrate')
265 ->will($this->returnValue(92));
266 $format2->expects($this->any())
267 ->method('getAudioChannels')
268 ->will($this->returnValue(2));
269 $format2->expects($this->any())
270 ->method('getPasses')
271 ->will($this->returnValue(2));
272 $format2->expects($this->any())
273 ->method('getAdditionalParameters')
274 ->will($this->returnValue(array('foo', 'bar')));
275  
276 $audioFormat = $this->getMock('FFMpeg\Format\AudioInterface');
277 $audioFormat->expects($this->any())
278 ->method('getExtraParams')
279 ->will($this->returnValue(array()));
280 $audioFormat->expects($this->any())
281 ->method('getAudioCodec')
282 ->will($this->returnValue('patati-patata-audio'));
283 $audioFormat->expects($this->any())
284 ->method('getAudioKiloBitrate')
285 ->will($this->returnValue(92));
286 $audioFormat->expects($this->any())
287 ->method('getAudioChannels')
288 ->will($this->returnValue(2));
289 $audioFormat->expects($this->any())
290 ->method('getPasses')
291 ->will($this->returnValue(1));
292  
293 $audioVideoFormat = $this->getMock('FFMpeg\Format\VideoInterface');
294 $audioVideoFormat->expects($this->any())
295 ->method('getExtraParams')
296 ->will($this->returnValue(array()));
297 $audioVideoFormat->expects($this->any())
298 ->method('getVideoCodec')
299 ->will($this->returnValue('gloubi-boulga-video'));
300 $audioVideoFormat->expects($this->any())
301 ->method('getAudioCodec')
302 ->will($this->returnValue('patati-patata-audio'));
303 $audioVideoFormat->expects($this->any())
304 ->method('getKiloBitrate')
305 ->will($this->returnValue(664));
306 $audioVideoFormat->expects($this->any())
307 ->method('getAudioKiloBitrate')
308 ->will($this->returnValue(92));
309 $audioVideoFormat->expects($this->any())
310 ->method('getAudioChannels')
311 ->will($this->returnValue(2));
312 $audioVideoFormat->expects($this->any())
313 ->method('getPasses')
314 ->will($this->returnValue(2));
315 $audioVideoFormat->expects($this->any())
316 ->method('getAdditionalParameters')
317 ->will($this->returnValue(array()));
318  
319 $audioVideoFormatSinglePass = $this->getMock('FFMpeg\Format\VideoInterface');
320 $audioVideoFormatSinglePass->expects($this->any())
321 ->method('getExtraParams')
322 ->will($this->returnValue(array()));
323 $audioVideoFormatSinglePass->expects($this->any())
324 ->method('getVideoCodec')
325 ->will($this->returnValue('gloubi-boulga-video'));
326 $audioVideoFormatSinglePass->expects($this->any())
327 ->method('getAudioCodec')
328 ->will($this->returnValue('patati-patata-audio'));
329 $audioVideoFormatSinglePass->expects($this->any())
330 ->method('getKiloBitrate')
331 ->will($this->returnValue(664));
332 $audioVideoFormatSinglePass->expects($this->any())
333 ->method('getAudioKiloBitrate')
334 ->will($this->returnValue(92));
335 $audioVideoFormatSinglePass->expects($this->any())
336 ->method('getAudioChannels')
337 ->will($this->returnValue(2));
338 $audioVideoFormatSinglePass->expects($this->any())
339 ->method('getPasses')
340 ->will($this->returnValue(1));
341 $audioVideoFormatSinglePass->expects($this->any())
342 ->method('getAdditionalParameters')
343 ->will($this->returnValue(array()));
344  
345 $formatExtra = $this->getMock('FFMpeg\Format\VideoInterface');
346 $formatExtra->expects($this->any())
347 ->method('getExtraParams')
348 ->will($this->returnValue(array('extra', 'param')));
349 $formatExtra->expects($this->any())
350 ->method('getKiloBitrate')
351 ->will($this->returnValue(665));
352 $formatExtra->expects($this->any())
353 ->method('getAudioKiloBitrate')
354 ->will($this->returnValue(92));
355 $formatExtra->expects($this->any())
356 ->method('getAudioChannels')
357 ->will($this->returnValue(2));
358 $formatExtra->expects($this->any())
359 ->method('getPasses')
360 ->will($this->returnValue(2));
361 $formatExtra->expects($this->any())
362 ->method('getAdditionalParameters')
363 ->will($this->returnValue(array()));
364  
365 $formatExtra2 = $this->getMock('FFMpeg\Format\VideoInterface');
366 $formatExtra2->expects($this->any())
367 ->method('getExtraParams')
368 ->will($this->returnValue(array('extra', 'param')));
369 $formatExtra2->expects($this->any())
370 ->method('getKiloBitrate')
371 ->will($this->returnValue(665));
372 $formatExtra2->expects($this->any())
373 ->method('getAudioKiloBitrate')
374 ->will($this->returnValue(92));
375 $formatExtra2->expects($this->any())
376 ->method('getAudioChannels')
377 ->will($this->returnValue(2));
378 $formatExtra2->expects($this->any())
379 ->method('getPasses')
380 ->will($this->returnValue(2));
381 $formatExtra2->expects($this->any())
382 ->method('getAdditionalParameters')
383 ->will($this->returnValue(array()));
384  
385 $listeners = array($this->getMock('Alchemy\BinaryDriver\Listeners\ListenerInterface'));
386  
387 $progressableFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\Prog')
388 ->disableOriginalConstructor()->getMock();
389 $progressableFormat->expects($this->any())
390 ->method('getExtraParams')
391 ->will($this->returnValue(array()));
392 $progressableFormat->expects($this->any())
393 ->method('createProgressListener')
394 ->will($this->returnValue($listeners));
395 $progressableFormat->expects($this->any())
396 ->method('getKiloBitrate')
397 ->will($this->returnValue(666));
398 $progressableFormat->expects($this->any())
399 ->method('getAudioKiloBitrate')
400 ->will($this->returnValue(92));
401 $progressableFormat->expects($this->any())
402 ->method('getAudioChannels')
403 ->will($this->returnValue(2));
404 $progressableFormat->expects($this->any())
405 ->method('getPasses')
406 ->will($this->returnValue(2));
407  
408 $progressableFormat2 = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\Prog')
409 ->disableOriginalConstructor()->getMock();
410 $progressableFormat2->expects($this->any())
411 ->method('getExtraParams')
412 ->will($this->returnValue(array()));
413 $progressableFormat2->expects($this->any())
414 ->method('createProgressListener')
415 ->will($this->returnValue($listeners));
416 $progressableFormat2->expects($this->any())
417 ->method('getKiloBitrate')
418 ->will($this->returnValue(666));
419 $progressableFormat2->expects($this->any())
420 ->method('getAudioKiloBitrate')
421 ->will($this->returnValue(92));
422 $progressableFormat2->expects($this->any())
423 ->method('getAudioChannels')
424 ->will($this->returnValue(2));
425 $progressableFormat2->expects($this->any())
426 ->method('getPasses')
427 ->will($this->returnValue(2));
428  
429 $progressableAudioFormat = $this->getMockBuilder('Tests\FFMpeg\Unit\Media\AudioProg')
430 ->disableOriginalConstructor()->getMock();
431 $progressableAudioFormat->expects($this->any())
432 ->method('getExtraParams')
433 ->will($this->returnValue(array()));
434 $progressableAudioFormat->expects($this->any())
435 ->method('getAudioCodec')
436 ->will($this->returnValue('patati-patata-audio'));
437 $progressableAudioFormat->expects($this->any())
438 ->method('createProgressListener')
439 ->will($this->returnValue($listeners));
440 $progressableAudioFormat->expects($this->any())
441 ->method('getAudioKiloBitrate')
442 ->will($this->returnValue(92));
443 $progressableAudioFormat->expects($this->any())
444 ->method('getAudioChannels')
445 ->will($this->returnValue(2));
446 $progressableAudioFormat->expects($this->any())
447 ->method('getPasses')
448 ->will($this->returnValue(1));
449  
450 return array(
451 array(false, array(array(
452 '-y', '-i', __FILE__, '-b:v', '663k',
453 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
454 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
455 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
456 '/target/file',
457 ), array(
458 '-y', '-i', __FILE__,
459 '-b:v', '663k',
460 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
461 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
462 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
463 '/target/file',
464 )), null, $format),
465 array(false, array(array(
466 '-y', '-i', __FILE__,
467 '-vcodec', 'gloubi-boulga-video',
468 '-acodec', 'patati-patata-audio', '-b:v', '664k',
469 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
470 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
471 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
472 '/target/file',
473 ), array(
474 '-y', '-i', __FILE__,
475 '-vcodec', 'gloubi-boulga-video',
476 '-acodec', 'patati-patata-audio',
477 '-b:v', '664k',
478 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
479 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
480 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
481 '/target/file',
482 )), null, $audioVideoFormat),
483 array(false, array(array(
484 '-y', '-i', __FILE__,
485 '-vcodec', 'gloubi-boulga-video',
486 '-acodec', 'patati-patata-audio', '-b:v', '664k',
487 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
488 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
489 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2',
490 '/target/file',
491 )), null, $audioVideoFormatSinglePass),
492 array(false, array(array(
493 '-y', '-i', __FILE__,
494 'extra', 'param','-b:v', '665k',
495 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
496 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
497 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
498 '/target/file',
499 ), array(
500 '-y', '-i', __FILE__,
501 'extra', 'param', '-b:v', '665k',
502 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
503 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
504 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
505 '/target/file',
506 )), null, $formatExtra),
507 array(true, array(array(
508 '-y', '-i', __FILE__,
509 '-threads', 24, '-b:v', '663k',
510 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
511 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
512 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 1, '-passlogfile',
513 '/target/file',
514 ), array(
515 '-y', '-i', __FILE__,
516 '-threads', 24,
517 '-b:v', '663k',
518 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
519 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
520 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', 2, 'foo', 'bar', '-pass', 2, '-passlogfile',
521 '/target/file',
522 )), null, $format2),
523 array(true, array(array(
524 '-y', '-i', __FILE__,
525 'extra', 'param', '-threads', 24, '-b:v', '665k',
526 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
527 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
528 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
529 '/target/file',
530 ), array(
531 '-y', '-i', __FILE__,
532 'extra', 'param', '-threads', 24, '-b:v', '665k',
533 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
534 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
535 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
536 '/target/file',
537 )), null, $formatExtra2),
538 array(false, array(array(
539 '-y', '-i', __FILE__, '-b:v', '666k',
540 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
541 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
542 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
543 '/target/file',
544 ), array(
545 '-y', '-i', __FILE__,
546 '-b:v', '666k',
547 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
548 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
549 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
550 '/target/file',
551 )), $listeners, $progressableFormat2),
552 array(true, array(array(
553 '-y', '-i', __FILE__,
554 '-threads', 24, '-b:v', '666k',
555 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
556 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
557 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '1', '-passlogfile',
558 '/target/file',
559 ), array(
560 '-y', '-i', __FILE__,
561 '-threads', 24,
562 '-b:v', '666k',
563 '-refs', '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
564 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71', '-qcomp', '0.6',
565 '-qdiff', '4', '-trellis', '1', '-b:a', '92k', '-ac', '2', '-pass', '2', '-passlogfile',
566 '/target/file',
567 )), $listeners, $progressableFormat),
568 array(true, array(array(
569 '-y', '-i', __FILE__,
570 '-threads', 24, '-acodec', 'patati-patata-audio',
571 '-b:a', '92k', '-ac', '2',
572 '/target/file',
573 )), null, $audioFormat),
574 array(true, array(array(
575 '-y', '-i', __FILE__,
576 '-threads', 24, '-acodec', 'patati-patata-audio',
577 '-b:a', '92k', '-ac', '2',
578 '/target/file',
579 )), $listeners, $progressableAudioFormat),
580 );
581 }
582  
583 public function testSaveShouldNotStoreCodecFiltersInTheMedia()
584 {
585 $driver = $this->getFFMpegDriverMock();
586 $ffprobe = $this->getFFProbeMock();
587  
588 $configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
589  
590 $driver->expects($this->any())
591 ->method('getConfiguration')
592 ->will($this->returnValue($configuration));
593  
594 $configuration->expects($this->any())
595 ->method('has')
596 ->with($this->equalTo('ffmpeg.threads'))
597 ->will($this->returnValue(true));
598  
599 $configuration->expects($this->any())
600 ->method('get')
601 ->with($this->equalTo('ffmpeg.threads'))
602 ->will($this->returnValue(24));
603  
604 $capturedCommands = array();
605  
606 $driver->expects($this->exactly(4))
607 ->method('command')
608 ->with($this->isType('array'), false, $this->anything())
609 ->will($this->returnCallback(function ($commands, $errors, $listeners) use (&$capturedCommands, &$capturedListeners) {
610 $capturedCommands[] = $commands;
611 }));
612  
613 $outputPathfile = '/target/file';
614  
615 $format = $this->getMock('FFMpeg\Format\VideoInterface');
616 $format->expects($this->any())
617 ->method('getExtraParams')
618 ->will($this->returnValue(array('param')));
619 $format->expects($this->any())
620 ->method('getPasses')
621 ->will($this->returnValue(2));
622  
623 $video = new Video(__FILE__, $driver, $ffprobe);
624 $video->save($format, $outputPathfile);
625 $video->save($format, $outputPathfile);
626  
627 $expectedPass1 = array(
628 '-y', '-i', __FILE__, 'param', '-threads', 24, '-b:v', 'k', '-refs',
629 '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
630 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71',
631 '-qcomp', '0.6', '-qdiff', '4', '-trellis', '1',
632 '-pass', '1', '-passlogfile', '/target/file',
633 );
634 $expectedPass2 = array(
635 '-y', '-i', __FILE__, 'param', '-threads', 24, '-b:v', 'k', '-refs',
636 '6', '-coder', '1', '-sc_threshold', '40', '-flags', '+loop',
637 '-me_range', '16', '-subq', '7', '-i_qfactor', '0.71',
638 '-qcomp', '0.6', '-qdiff', '4', '-trellis', '1',
639 '-pass', '2', '-passlogfile', '/target/file',
640 );
641  
642 $n = 1;
643 foreach ($capturedCommands as $capturedCommand) {
644 $prefix = null;
645 foreach ($capturedCommand as $command) {
646 if (false !== strpos($command, '/pass-')) {
647 $prefix = $command;
648 break;
649 }
650 }
651  
652 if (null === $prefix) {
653 $this->fail('Unable to find pass prefix command.');
654 }
655  
656 $found = false;
657 foreach ($capturedCommand as $key => $command) {
658 if ($command === $prefix) {
659 $found = true;
660 unset($capturedCommand[$key]);
661 $capturedCommand = array_values($capturedCommand);
662 break;
663 }
664 }
665  
666 if (!$found) {
667 $this->fail('Unable to find pass prefix command back.');
668 }
669  
670 if (0 === $n % 2) {
671 $this->assertEquals($expectedPass2, $capturedCommand);
672 } else {
673 $this->assertEquals($expectedPass1, $capturedCommand);
674 }
675 $n++;
676 }
677 }
678  
679 public function getClassName()
680 {
681 return 'FFMpeg\Media\Video';
682 }
683 }