Exemplo n.º 1
0
 /**
  * @dataProvider provide90degresTranspositions
  */
 public function testApplyWithSizeTransformation($value)
 {
     $stream = new Stream(array('width' => 320, 'height' => 240, 'codec_type' => 'video'));
     $streams = new StreamCollection(array($stream));
     $video = $this->getVideoMock();
     $video->expects($this->once())->method('getStreams')->will($this->returnValue($streams));
     $format = $this->getMock('FFMpeg\\Format\\VideoInterface');
     $filter = new RotateFilter($value);
     $this->assertEquals(array('-vf', $value, '-metadata:s:v:0', 'rotate=0'), $filter->apply($video, $format));
     $this->assertEquals(240, $stream->get('width'));
     $this->assertEquals(320, $stream->get('height'));
 }
Exemplo n.º 2
0
 public function testApplyWatermark()
 {
     $stream = new Stream(array('width' => 320, 'height' => 240, 'codec_type' => 'video'));
     $streams = new StreamCollection(array($stream));
     $video = $this->getVideoMock();
     $format = $this->getMock('FFMpeg\\Format\\VideoInterface');
     $filter = new WatermarkFilter(__DIR__ . '/../../files/watermark.png');
     $this->assertEquals(array('-vf', 'overlay 0:0'), $filter->apply($video, $format));
     // check size of video is unchanged
     $this->assertEquals(320, $stream->get('width'));
     $this->assertEquals(240, $stream->get('height'));
 }
Exemplo n.º 3
0
 public function testCommandParamsAreCorrectAndStreamIsUpdated()
 {
     $stream = new Stream(array('width' => 320, 'height' => 240, 'codec_type' => 'video'));
     $streams = new StreamCollection(array($stream));
     $video = $this->getVideoMock();
     $video->expects($this->once())->method('getStreams')->will($this->returnValue($streams));
     $format = $this->getMock('FFMpeg\\Format\\VideoInterface');
     $dimension = new Dimension(200, 150);
     $point = new Point(25, 35);
     $filter = new CropFilter($point, $dimension);
     $expected = array('-filter:v', 'crop=' . $dimension->getWidth() . ":" . $dimension->getHeight() . ":" . $point->getX() . ":" . $point->getY());
     $this->assertEquals($expected, $filter->apply($video, $format));
     $this->assertEquals(200, $stream->get('width'));
     $this->assertEquals(150, $stream->get('height'));
 }
Exemplo n.º 4
0
 /**
  * Extracts a ratio from a string in a \d+:\d+ format given a key name.
  *
  * @param  Stream     $stream The stream where to look for the ratio.
  * @param  string     $name   the name of the key.
  * @return null|array An array containing the width and the height, null if not found.
  */
 private function extractRatio(Stream $stream, $name)
 {
     if ($stream->has($name)) {
         $ratio = $stream->get($name);
         if (preg_match('/\\d+:\\d+/', $ratio)) {
             $data = array_filter(explode(':', $ratio), function ($int) {
                 return $int > 0;
             });
             if (2 === count($data)) {
                 return array_map(function ($int) {
                     return (int) $int;
                 }, $data);
             }
         }
     }
     return null;
 }
Exemplo n.º 5
0
 /**
  * @dataProvider provideInvalidRatios
  */
 public function testGetDimensionsFromVideoWithInvalidDisplayRatio($invalidRatio)
 {
     $stream = new Stream(array('codec_type' => 'video', 'width' => 960, 'height' => 720, 'sample_aspect_ratio' => $invalidRatio, 'display_aspect_ratio' => '16:9'));
     $this->assertEquals(new Dimension(960, 720), $stream->getDimensions());
 }