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\Concat;
6 use Neutron\TemporaryFilesystem\Manager as FsManager;
7  
8 class ConcatTest extends AbstractMediaTestCase
9 {
10 public function testGetSources()
11 {
12 $driver = $this->getFFMpegDriverMock();
13 $ffprobe = $this->getFFProbeMock();
14  
15 $concat = new Concat(array(__FILE__, __FILE__), $driver, $ffprobe);
16 $this->assertSame(array(__FILE__, __FILE__), $concat->getSources());
17 }
18  
19 public function testFiltersReturnFilters()
20 {
21 $driver = $this->getFFMpegDriverMock();
22 $ffprobe = $this->getFFProbeMock();
23  
24 $concat = new Concat(array(__FILE__, __FILE__), $driver, $ffprobe);
25 $this->assertInstanceOf('FFMpeg\Filters\Concat\ConcatFilters', $concat->filters());
26 }
27  
28 public function testAddFiltersAddsAFilter()
29 {
30 $driver = $this->getFFMpegDriverMock();
31 $ffprobe = $this->getFFProbeMock();
32  
33 $filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
34 ->disableOriginalConstructor()
35 ->getMock();
36  
37 $filter = $this->getMock('FFMpeg\Filters\Concat\ConcatFilterInterface');
38  
39 $filters->expects($this->once())
40 ->method('add')
41 ->with($filter);
42  
43 $concat = new Concat(array(__FILE__, __FILE__), $driver, $ffprobe);
44 $concat->setFiltersCollection($filters);
45 $concat->addFilter($filter);
46 }
47  
48 /**
49 * @dataProvider provideSaveFromSameCodecsOptions
50 */
51 public function testSaveFromSameCodecs($streamCopy, $commands)
52 {
53 $driver = $this->getFFMpegDriverMock();
54 $ffprobe = $this->getFFProbeMock();
55  
56 $pathfile = '/target/destination';
57  
58 array_push($commands, $pathfile);
59  
60 $driver->expects($this->exactly(1))
61 ->method('command')
62 ->with($this->isType('array'), false, $this->anything())
63 ->will($this->returnCallback(function ($commands, $errors, $listeners) {}));
64  
65 $concat = new Concat(array(__FILE__, 'concat-2.mp4'), $driver, $ffprobe);
66 $concat->saveFromSameCodecs($pathfile, $streamCopy);
67  
68 $this->assertEquals('-f', $commands[0]);
69 $this->assertEquals('concat', $commands[1]);
70 $this->assertEquals('-safe', $commands[2]);
71 $this->assertEquals('0', $commands[3]);
72 $this->assertEquals('-i', $commands[4]);
73 if(isset($commands[6]) && (strcmp($commands[6], "-c") == 0)) {
74 $this->assertEquals('-c', $commands[6]);
75 $this->assertEquals('copy', $commands[7]);
76 }
77 }
78  
79 public function provideSaveFromSameCodecsOptions()
80 {
81 $fs = FsManager::create();
82 $tmpFile = $fs->createTemporaryFile('ffmpeg-concat');
83  
84 return array(
85 array(
86 TRUE,
87 array(
88 '-f', 'concat',
89 '-safe', '0',
90 '-i', $tmpFile,
91 '-c', 'copy'
92 ),
93 ),
94 array(
95 FALSE,
96 array(
97 '-f', 'concat',
98 '-safe', '0',
99 '-i', $tmpFile
100 )
101 ),
102 );
103 }
104  
105 /**
106 * @dataProvider provideSaveFromDifferentCodecsOptions
107 */
108 public function testSaveFromDifferentCodecs($commands)
109 {
110 $driver = $this->getFFMpegDriverMock();
111 $ffprobe = $this->getFFProbeMock();
112 $format = $this->getFormatInterfaceMock();
113  
114 $pathfile = '/target/destination';
115  
116 array_push($commands, $pathfile);
117  
118 $configuration = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
119  
120 $driver->expects($this->any())
121 ->method('getConfiguration')
122 ->will($this->returnValue($configuration));
123  
124 $driver->expects($this->once())
125 ->method('command')
126 ->with($commands);
127  
128 $concat = new Concat(array(__FILE__, 'concat-2.mp4'), $driver, $ffprobe);
129 $this->assertSame($concat, $concat->saveFromDifferentCodecs($format, $pathfile));
130 }
131  
132 public function provideSaveFromDifferentCodecsOptions()
133 {
134 return array(
135 array(
136 array(
137 '-i', __FILE__,
138 '-i', 'concat-2.mp4',
139 '-filter_complex',
140 '[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]',
141 '-map', '[v]',
142 '-map', '[a]'
143 ),
144 ),
145 );
146 }
147 }