99 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			99 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace FFMpeg\Tests\Media;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use FFMpeg\Media\Frame;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class FrameTest extends AbstractMediaTestCase
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * @expectedException FFMpeg\Exception\InvalidArgumentException
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function testWithInvalidFile()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        new Frame('/No/file', $this->getFFMpegDriverMock(), $this->getFFProbeMock(), $this->getTimeCodeMock());
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function testGetTimeCode()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $driver = $this->getFFMpegDriverMock();
							 | 
						||
| 
								 | 
							
								        $ffprobe = $this->getFFProbeMock();
							 | 
						||
| 
								 | 
							
								        $timecode = $this->getTimeCodeMock();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = new Frame(__FILE__, $driver, $ffprobe, $timecode);
							 | 
						||
| 
								 | 
							
								        $this->assertSame($timecode, $frame->getTimeCode());
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function testFiltersReturnFilters()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $driver = $this->getFFMpegDriverMock();
							 | 
						||
| 
								 | 
							
								        $ffprobe = $this->getFFProbeMock();
							 | 
						||
| 
								 | 
							
								        $timecode = $this->getTimeCodeMock();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = new Frame(__FILE__, $driver, $ffprobe, $timecode);
							 | 
						||
| 
								 | 
							
								        $this->assertInstanceOf('FFMpeg\Filters\Frame\FrameFilters', $frame->filters());
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function testAddFiltersAddsAFilter()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $driver = $this->getFFMpegDriverMock();
							 | 
						||
| 
								 | 
							
								        $ffprobe = $this->getFFProbeMock();
							 | 
						||
| 
								 | 
							
								        $timecode = $this->getTimeCodeMock();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $filters = $this->getMockBuilder('FFMpeg\Filters\FiltersCollection')
							 | 
						||
| 
								 | 
							
								            ->disableOriginalConstructor()
							 | 
						||
| 
								 | 
							
								            ->getMock();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $filter = $this->getMock('FFMpeg\Filters\Frame\FrameFilterInterface');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $filters->expects($this->once())
							 | 
						||
| 
								 | 
							
								            ->method('add')
							 | 
						||
| 
								 | 
							
								            ->with($filter);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = new Frame(__FILE__, $driver, $ffprobe, $timecode);
							 | 
						||
| 
								 | 
							
								        $frame->setFiltersCollection($filters);
							 | 
						||
| 
								 | 
							
								        $frame->addFilter($filter);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * @dataProvider provideSaveAsOptions
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function testSaveAs($accurate, $commands)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $driver = $this->getFFMpegDriverMock();
							 | 
						||
| 
								 | 
							
								        $ffprobe = $this->getFFProbeMock();
							 | 
						||
| 
								 | 
							
								        $timecode = $this->getTimeCodeMock();
							 | 
						||
| 
								 | 
							
								        $timecode->expects($this->once())
							 | 
						||
| 
								 | 
							
								            ->method('__toString')
							 | 
						||
| 
								 | 
							
								            ->will($this->returnValue('timecode'));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $pathfile = '/target/destination';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        array_push($commands, $pathfile);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $driver->expects($this->once())
							 | 
						||
| 
								 | 
							
								            ->method('command')
							 | 
						||
| 
								 | 
							
								            ->with($commands);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = new Frame(__FILE__, $driver, $ffprobe, $timecode);
							 | 
						||
| 
								 | 
							
								        $this->assertSame($frame, $frame->saveAs($pathfile, $accurate));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function provideSaveAsOptions()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return array(
							 | 
						||
| 
								 | 
							
								            array(false, array(
							 | 
						||
| 
								 | 
							
								                '-ss', 'timecode',
							 | 
						||
| 
								 | 
							
								                '-i', __FILE__,
							 | 
						||
| 
								 | 
							
								                '-vframes', '1',
							 | 
						||
| 
								 | 
							
								                '-f', 'image2')
							 | 
						||
| 
								 | 
							
								            ),
							 | 
						||
| 
								 | 
							
								            array(true, array(
							 | 
						||
| 
								 | 
							
								                '-i', __FILE__,
							 | 
						||
| 
								 | 
							
								                '-vframes', '1', '-ss', 'timecode',
							 | 
						||
| 
								 | 
							
								                '-f', 'image2'
							 | 
						||
| 
								 | 
							
								            )),
							 | 
						||
| 
								 | 
							
								        );
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |