| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 23:38:04 +01:00
										 |  |  | namespace Tests\FFMpeg\Unit\FFProbe\DataMapping; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  | use FFMpeg\Coordinate\Dimension; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | use FFMpeg\FFProbe\DataMapping\Stream; | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  | use Tests\FFMpeg\Unit\TestCase; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class StreamTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider provideAudioCases | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testIsAudio($isAudio, $properties) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $stream = new Stream($properties); | 
					
						
							|  |  |  |         $this->assertTrue($isAudio === $stream->isAudio()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function provideAudioCases() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             [true, ['codec_type' => 'audio']], | 
					
						
							|  |  |  |             [false, ['codec_type' => 'video']], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider provideVideoCases | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testIsVideo($isVideo, $properties) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $stream = new Stream($properties); | 
					
						
							|  |  |  |         $this->assertTrue($isVideo === $stream->isVideo()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function provideVideoCases() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             [true, ['codec_type' => 'video']], | 
					
						
							|  |  |  |             [false, ['codec_type' => 'audio']], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testGetDimensionsFromAudio() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-19 21:52:13 +01:00
										 |  |  |         $this->expectException( | 
					
						
							|  |  |  |             '\FFMpeg\Exception\LogicException', | 
					
						
							|  |  |  |             'Dimensions can only be retrieved from video streams.' | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $stream = new Stream(['codec_type' => 'audio']); | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  |         $stream->getDimensions(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetDimensionsFromVideo() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $stream = new Stream(['codec_type' => 'video', 'width' => 960, 'height' => 720]); | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  |         $this->assertEquals(new Dimension(960, 720), $stream->getDimensions()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider provideInvalidPropertiesForDimensionsExtraction | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testUnableToGetDimensionsFromVideo($properties) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-19 21:52:13 +01:00
										 |  |  |         $this->expectException( | 
					
						
							|  |  |  |             '\FFMpeg\Exception\RuntimeException', | 
					
						
							|  |  |  |             'Unable to extract dimensions.' | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $stream = new Stream(['codec_type' => 'video', 'width' => 960]); | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  |         $stream->getDimensions(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function provideInvalidPropertiesForDimensionsExtraction() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             ['codec_type' => 'video', 'width' => 960], | 
					
						
							|  |  |  |             ['codec_type' => 'video', 'height' => 960], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2013-09-04 19:00:43 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providePropertiesForDimensionsExtraction | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testGetDimensionsFromVideoWithDisplayRatio($data) | 
					
						
							| 
									
										
										
										
											2013-12-17 17:38:12 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $stream = new Stream([ | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |             'codec_type' => 'video', | 
					
						
							|  |  |  |             'width' => $data['width'], | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |             'height' => $data['height'], | 
					
						
							|  |  |  |             'sample_aspect_ratio' => $data['sar'], | 
					
						
							|  |  |  |             'display_aspect_ratio' => $data['dar'], | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |         $this->assertEquals(new Dimension($data['result_width'], $data['result_height']), $stream->getDimensions()); | 
					
						
							| 
									
										
										
										
											2013-12-17 17:38:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 12:09:39 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider provideInvalidRatios | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testGetDimensionsFromVideoWithInvalidDisplayRatio($invalidRatio) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         $stream = new Stream(['codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => $invalidRatio, 'display_aspect_ratio' => '16:9']); | 
					
						
							| 
									
										
										
										
											2013-09-05 12:09:39 +02:00
										 |  |  |         $this->assertEquals(new Dimension(960, 720), $stream->getDimensions()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-12-17 17:38:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 12:09:39 +02:00
										 |  |  |     public function provideInvalidRatios() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         return [['0:1'], ['2:1:3']]; | 
					
						
							| 
									
										
										
										
											2013-09-05 12:09:39 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providePropertiesForDimensionsExtraction() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 ['width' => '960', 'height' => '720', | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |                 'sar' => '4:3', 'dar' => '16:9', | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |                 'result_width' => '1280', 'result_height' => '720', ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 ['width' => '1920', 'height' => '1080', | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |                 'sar' => '1:1', 'dar' => '16:9', | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |                 'result_width' => '1920', 'result_height' => '1080', ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 ['width' => '640', 'height' => '480', | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |                 'sar' => '75:74', 'dar' => '50:37', | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |                 'result_width' => '649', 'result_height' => '480', ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 ['width' => '720', 'height' => '576', | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |                   'sar' => '52:28', 'dar' => '16:9', | 
					
						
							| 
									
										
										
										
											2022-02-09 14:32:43 +01:00
										 |  |  |                   'result_width' => '1337', 'result_height' => '752', ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2014-06-10 12:27:04 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-25 10:03:20 +02:00
										 |  |  | } |