scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | office | 1 | <?php |
2 | |||
3 | namespace Tests\FFMpeg\Unit\FFProbe\DataMapping; |
||
4 | |||
5 | use FFMpeg\Coordinate\Dimension; |
||
6 | use Tests\FFMpeg\Unit\TestCase; |
||
7 | use FFMpeg\FFProbe\DataMapping\Stream; |
||
8 | |||
9 | class StreamTest extends TestCase |
||
10 | { |
||
11 | /** |
||
12 | * @dataProvider provideAudioCases |
||
13 | */ |
||
14 | public function testIsAudio($isAudio, $properties) |
||
15 | { |
||
16 | $stream = new Stream($properties); |
||
17 | $this->assertTrue($isAudio === $stream->isAudio()); |
||
18 | } |
||
19 | |||
20 | public function provideAudioCases() |
||
21 | { |
||
22 | return array( |
||
23 | array(true, array('codec_type' => 'audio')), |
||
24 | array(false, array('codec_type' => 'video')), |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @dataProvider provideVideoCases |
||
30 | */ |
||
31 | public function testIsVideo($isVideo, $properties) |
||
32 | { |
||
33 | $stream = new Stream($properties); |
||
34 | $this->assertTrue($isVideo === $stream->isVideo()); |
||
35 | } |
||
36 | |||
37 | public function provideVideoCases() |
||
38 | { |
||
39 | return array( |
||
40 | array(true, array('codec_type' => 'video')), |
||
41 | array(false, array('codec_type' => 'audio')), |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @expectedException FFMpeg\Exception\LogicException |
||
47 | * @expectedExceptionMessage Dimensions can only be retrieved from video streams. |
||
48 | */ |
||
49 | public function testGetDimensionsFromAudio() |
||
50 | { |
||
51 | $stream = new Stream(array('codec_type' => 'audio')); |
||
52 | $stream->getDimensions(); |
||
53 | } |
||
54 | |||
55 | public function testGetDimensionsFromVideo() |
||
56 | { |
||
57 | $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720)); |
||
58 | $this->assertEquals(new Dimension(960, 720), $stream->getDimensions()); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @dataProvider provideInvalidPropertiesForDimensionsExtraction |
||
63 | * @expectedException FFMpeg\Exception\RuntimeException |
||
64 | * @expectedExceptionMessage Unable to extract dimensions. |
||
65 | */ |
||
66 | public function testUnableToGetDimensionsFromVideo($properties) |
||
67 | { |
||
68 | $stream = new Stream(array('codec_type' => 'video', 'width' => 960)); |
||
69 | $stream->getDimensions(); |
||
70 | } |
||
71 | |||
72 | public function provideInvalidPropertiesForDimensionsExtraction() |
||
73 | { |
||
74 | return array( |
||
75 | array('codec_type' => 'video', 'width' => 960), |
||
76 | array('codec_type' => 'video', 'height' => 960), |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @dataProvider providePropertiesForDimensionsExtraction |
||
82 | */ |
||
83 | public function testGetDimensionsFromVideoWithDisplayRatio($data) |
||
84 | { |
||
85 | $stream = new Stream(array( |
||
86 | 'codec_type' => 'video', |
||
87 | 'width' => $data['width'], |
||
88 | 'height' => $data['height'], |
||
89 | 'sample_aspect_ratio' => $data['sar'], |
||
90 | 'display_aspect_ratio' => $data['dar'] |
||
91 | )); |
||
92 | $this->assertEquals(new Dimension($data['result_width'], $data['result_height']), $stream->getDimensions()); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @dataProvider provideInvalidRatios |
||
97 | */ |
||
98 | public function testGetDimensionsFromVideoWithInvalidDisplayRatio($invalidRatio) |
||
99 | { |
||
100 | $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => $invalidRatio, 'display_aspect_ratio' => '16:9')); |
||
101 | $this->assertEquals(new Dimension(960, 720), $stream->getDimensions()); |
||
102 | } |
||
103 | |||
104 | public function provideInvalidRatios() |
||
105 | { |
||
106 | return array(array('0:1'), array('2:1:3')); |
||
107 | } |
||
108 | |||
109 | public function providePropertiesForDimensionsExtraction() |
||
110 | { |
||
111 | return array( |
||
112 | array( |
||
113 | array('width' => '960', 'height' => '720', |
||
114 | 'sar' => '4:3', 'dar' => '16:9', |
||
115 | 'result_width' => '1280', 'result_height' => '720'), |
||
116 | ), |
||
117 | array( |
||
118 | array('width' => '1920', 'height' => '1080', |
||
119 | 'sar' => '1:1', 'dar' => '16:9', |
||
120 | 'result_width' => '1920', 'result_height' => '1080'), |
||
121 | ), |
||
122 | array( |
||
123 | array('width' => '640', 'height' => '480', |
||
124 | 'sar' => '75:74', 'dar' => '50:37', |
||
125 | 'result_width' => '649', 'result_height' => '480'), |
||
126 | ), |
||
127 | array( |
||
128 | array('width' => '720', 'height' => '576', |
||
129 | 'sar' => '52:28', 'dar' => '16:9', |
||
130 | 'result_width' => '1337', 'result_height' => '752'), |
||
131 | ), |
||
132 | ); |
||
133 | } |
||
134 | } |