|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once(dirname(__FILE__) . "/../../vendor/autoload.php"); |
| 4 | +require_once(dirname(__FILE__) . "/../../FfmpegVideoTranscoding.php"); |
| 5 | +require_once(dirname(__FILE__) . "/../../FfmpegVideoFile.php"); |
| 6 | + |
| 7 | + |
| 8 | +$SETTINGS = array( |
| 9 | + "autorotate" => FALSE |
| 10 | +); |
| 11 | + |
| 12 | +$ASSETS = array( |
| 13 | + "NORMAL_VIDEO" => dirname(__FILE__) . "/../assets/video-640-360.mp4", |
| 14 | + "ROTATED_VIDEO" => dirname(__FILE__) . "/../assets/iphone_rotated.mov" |
| 15 | +); |
| 16 | + |
| 17 | +$TMPFILES = array( |
| 18 | + "TMP_IMAGE" => "/tmp/test-img.png", |
| 19 | + "TMP_VIDEO" => "/tmp/test-video.mp4" |
| 20 | +); |
| 21 | + |
| 22 | + |
| 23 | +class FfmpegRotationTest extends PHPUnit_Framework_TestCase { |
| 24 | + |
| 25 | + public function testReadRotation() { |
| 26 | + global $ASSETS, $SETTINGS; |
| 27 | + |
| 28 | + $normalVideoNoRotateAdd = new FfmpegVideoFile($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 29 | + "rotation" => TRUE |
| 30 | + ))); |
| 31 | + $this->assertEquals($normalVideoNoRotateAdd->getWidth(), 640); |
| 32 | + $this->assertEquals($normalVideoNoRotateAdd->getHeight(), 360); |
| 33 | + $this->assertEquals($normalVideoNoRotateAdd->getRotation(), 0); |
| 34 | + |
| 35 | + $normalVideoWithRotateAdd = new FfmpegVideoFile($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 36 | + "rotation" => TRUE, |
| 37 | + "rotate_add" => 90 |
| 38 | + ))); |
| 39 | + $this->assertEquals($normalVideoWithRotateAdd->getWidth(), 360); |
| 40 | + $this->assertEquals($normalVideoWithRotateAdd->getHeight(), 640); |
| 41 | + $this->assertEquals($normalVideoWithRotateAdd->getRotation(), 90); |
| 42 | + |
| 43 | + $rotatedVideoNoRotateAdd = new FfmpegVideoFile($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 44 | + "rotation" => TRUE |
| 45 | + ))); |
| 46 | + $this->assertEquals($rotatedVideoNoRotateAdd->getWidth(), 320); |
| 47 | + $this->assertEquals($rotatedVideoNoRotateAdd->getHeight(), 568); |
| 48 | + $this->assertEquals($rotatedVideoNoRotateAdd->getRotation(), 90); |
| 49 | + |
| 50 | + $rotatedVideoWithRotateAdd = new FfmpegVideoFile($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 51 | + "rotation" => TRUE, |
| 52 | + "rotate_add" => 90 |
| 53 | + ))); |
| 54 | + $this->assertEquals($rotatedVideoWithRotateAdd->getWidth(), 568); |
| 55 | + $this->assertEquals($rotatedVideoWithRotateAdd->getHeight(), 320); |
| 56 | + $this->assertEquals($rotatedVideoWithRotateAdd->getRotation(), 180); |
| 57 | + } |
| 58 | + |
| 59 | + public function testWriteRotation() { |
| 60 | + global $ASSETS, $SETTINGS, $TMPFILES; |
| 61 | + |
| 62 | + $normalVideoNoRotateAdd = new FfmpegVideoFile($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 63 | + "rotation" => TRUE |
| 64 | + ))); |
| 65 | + @unlink($TMPFILES["TMP_IMAGE"]); |
| 66 | + $normalVideoNoRotateAdd->saveImageByPercentage($TMPFILES["TMP_IMAGE"]); |
| 67 | + $readImg = new FfmpegVideoFile($TMPFILES["TMP_IMAGE"]); |
| 68 | + unlink($TMPFILES["TMP_IMAGE"]); |
| 69 | + $this->assertEquals($readImg->getWidth(), 640); |
| 70 | + $this->assertEquals($readImg->getHeight(), 360); |
| 71 | + $this->assertEquals($readImg->getRotation(), 0); |
| 72 | + |
| 73 | + $normalVideoWithRotateAdd = new FfmpegVideoFile($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 74 | + "rotation" => TRUE, |
| 75 | + "rotate_add" => 90 |
| 76 | + ))); |
| 77 | + @unlink($TMPFILES["TMP_IMAGE"]); |
| 78 | + $normalVideoWithRotateAdd->saveImageByPercentage($TMPFILES["TMP_IMAGE"]); |
| 79 | + $readImg = new FfmpegVideoFile($TMPFILES["TMP_IMAGE"]); |
| 80 | + unlink($TMPFILES["TMP_IMAGE"]); |
| 81 | + $this->assertEquals($readImg->getWidth(), 360); |
| 82 | + $this->assertEquals($readImg->getHeight(), 640); |
| 83 | + $this->assertEquals($readImg->getRotation(), 0); |
| 84 | + |
| 85 | + $rotatedVideoNoRotateAdd = new FfmpegVideoFile($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 86 | + "rotation" => TRUE |
| 87 | + ))); |
| 88 | + @unlink($TMPFILES["TMP_IMAGE"]); |
| 89 | + $rotatedVideoNoRotateAdd->saveImageByPercentage($TMPFILES["TMP_IMAGE"]); |
| 90 | + $readImg = new FfmpegVideoFile($TMPFILES["TMP_IMAGE"]); |
| 91 | + unlink($TMPFILES["TMP_IMAGE"]); |
| 92 | + $this->assertEquals($readImg->getWidth(), 320); |
| 93 | + $this->assertEquals($readImg->getHeight(), 568); |
| 94 | + $this->assertEquals($readImg->getRotation(), 0); |
| 95 | + |
| 96 | + $rotatedVideoWithRotateAdd = new FfmpegVideoFile($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 97 | + "rotation" => TRUE, |
| 98 | + "rotate_add" => 90 |
| 99 | + ))); |
| 100 | + @unlink($TMPFILES["TMP_IMAGE"]); |
| 101 | + $rotatedVideoWithRotateAdd->saveImageByPercentage($TMPFILES["TMP_IMAGE"]); |
| 102 | + $readImg = new FfmpegVideoFile($TMPFILES["TMP_IMAGE"]); |
| 103 | + unlink($TMPFILES["TMP_IMAGE"]); |
| 104 | + $this->assertEquals($readImg->getWidth(), 568); |
| 105 | + $this->assertEquals($readImg->getHeight(), 320); |
| 106 | + $this->assertEquals($readImg->getRotation(), 0); |
| 107 | + } |
| 108 | + |
| 109 | + public function testTranscodingRotation() { |
| 110 | + global $ASSETS, $SETTINGS, $TMPFILES; |
| 111 | + |
| 112 | + @unlink($TMPFILES["TMP_VIDEO"]); |
| 113 | + FfmpegVideoTranscoding::transcodeGracefully($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 114 | + "rotate" => TRUE, |
| 115 | + "resizefit" => "fit", |
| 116 | + "target" => $TMPFILES["TMP_VIDEO"], |
| 117 | + ))); |
| 118 | + $readVid = new FfmpegVideoFile($TMPFILES["TMP_VIDEO"]); |
| 119 | + unlink($TMPFILES["TMP_VIDEO"]); |
| 120 | + $this->assertEquals($readVid->getWidth(), 640); |
| 121 | + $this->assertEquals($readVid->getHeight(), 360); |
| 122 | + $this->assertEquals($readVid->getRotation(), 0); |
| 123 | + |
| 124 | + @unlink($TMPFILES["TMP_VIDEO"]); |
| 125 | + FfmpegVideoTranscoding::transcodeGracefully($ASSETS["NORMAL_VIDEO"], array_merge($SETTINGS, array( |
| 126 | + "rotate" => TRUE, |
| 127 | + "resizefit" => "fit", |
| 128 | + "rotate_add" => 90, |
| 129 | + "target" => $TMPFILES["TMP_VIDEO"], |
| 130 | + ))); |
| 131 | + $readVid = new FfmpegVideoFile($TMPFILES["TMP_VIDEO"]); |
| 132 | + unlink($TMPFILES["TMP_VIDEO"]); |
| 133 | + $this->assertEquals($readVid->getWidth(), 360); |
| 134 | + $this->assertEquals($readVid->getHeight(), 640); |
| 135 | + $this->assertEquals($readVid->getRotation(), 0); |
| 136 | + |
| 137 | + @unlink($TMPFILES["TMP_VIDEO"]); |
| 138 | + FfmpegVideoTranscoding::transcodeGracefully($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 139 | + "rotate" => TRUE, |
| 140 | + "resizefit" => "fit", |
| 141 | + "target" => $TMPFILES["TMP_VIDEO"], |
| 142 | + ))); |
| 143 | + $readVid = new FfmpegVideoFile($TMPFILES["TMP_VIDEO"]); |
| 144 | + unlink($TMPFILES["TMP_VIDEO"]); |
| 145 | + $this->assertEquals($readVid->getWidth(), 320); |
| 146 | + $this->assertEquals($readVid->getHeight(), 568); |
| 147 | + $this->assertEquals($readVid->getRotation(), 0); |
| 148 | + |
| 149 | + @unlink($TMPFILES["TMP_VIDEO"]); |
| 150 | + FfmpegVideoTranscoding::transcodeGracefully($ASSETS["ROTATED_VIDEO"], array_merge($SETTINGS, array( |
| 151 | + "rotate" => TRUE, |
| 152 | + "resizefit" => "fit", |
| 153 | + "rotate_add" => 90, |
| 154 | + "target" => $TMPFILES["TMP_VIDEO"], |
| 155 | + ))); |
| 156 | + $readVid = new FfmpegVideoFile($TMPFILES["TMP_VIDEO"]); |
| 157 | + unlink($TMPFILES["TMP_VIDEO"]); |
| 158 | + $this->assertEquals($readVid->getWidth(), 568); |
| 159 | + $this->assertEquals($readVid->getHeight(), 320); |
| 160 | + $this->assertEquals($readVid->getRotation(), 0); |
| 161 | + } |
| 162 | + |
| 163 | +} |
0 commit comments