soluble-io /
soluble-mediatools-cli
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Soluble\MediaTools\Preset\Prod; |
||
| 6 | |||
| 7 | use Soluble\MediaTools\Cli\Service\MediaToolsServiceInterface; |
||
| 8 | use Soluble\MediaTools\Preset\PresetInterface; |
||
| 9 | use Soluble\MediaTools\Video\Filter\Type\FFMpegVideoFilterInterface; |
||
| 10 | use Soluble\MediaTools\Video\Filter\VideoFilterChain; |
||
| 11 | use Soluble\MediaTools\Video\VideoConvertParams; |
||
| 12 | use Soluble\MediaTools\Video\VideoInfoInterface; |
||
| 13 | |||
| 14 | class ResolvePreset implements PresetInterface |
||
| 15 | { |
||
| 16 | /** @var MediaToolsServiceInterface */ |
||
| 17 | private $mediaTools; |
||
| 18 | |||
| 19 | /** @var VideoInfoInterface|null */ |
||
| 20 | private $videoInfo; |
||
| 21 | |||
| 22 | public function __construct(MediaToolsServiceInterface $mediaTools) |
||
| 23 | { |
||
| 24 | $this->mediaTools = $mediaTools; |
||
| 25 | } |
||
| 26 | |||
| 27 | private function getVideoInfo(string $file): VideoInfoInterface |
||
| 28 | { |
||
| 29 | if ($this->videoInfo === null) { |
||
| 30 | $this->videoInfo = $this->mediaTools->getReader()->getInfo($file); |
||
| 31 | } |
||
| 32 | |||
| 33 | return $this->videoInfo; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getParams(string $file, ?int $width = null, ?int $height = null): VideoConvertParams |
||
| 37 | { |
||
| 38 | $info = $this->getVideoInfo($file); |
||
| 39 | |||
| 40 | $firstAudio = $info->getAudioStreams()->getFirst(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 41 | $firstVideo = $info->getVideoStreams()->getFirst(); |
||
|
0 ignored issues
–
show
|
|||
| 42 | |||
| 43 | $filters = new VideoFilterChain(); |
||
|
0 ignored issues
–
show
|
|||
| 44 | |||
| 45 | // ffmpeg -i <input> -c:v dnxhd -vf "scale=1920:1080,fps=30000/1001,format=yuv422p" -b:v 145M -c:a pcm_s16le test3.mov |
||
| 46 | // http://www.deb-indus.org/tuto/ffmpeg-howto.htm#Encoding_VC-3 |
||
| 47 | $params = (new VideoConvertParams()) |
||
| 48 | ->withVideoCodec('dnxhd') |
||
| 49 | ->withAudioCodec('pcm_s16le') |
||
| 50 | ->withVideoBitrate('145M') |
||
| 51 | ->withVideoFilter(new class() implements FFMpegVideoFilterInterface { |
||
| 52 | public function getFFmpegCLIValue(): string |
||
| 53 | { |
||
| 54 | return 'scale=1920:1080,fps=30000/1001,format=yuv422p'; |
||
| 55 | } |
||
| 56 | }) |
||
| 57 | ->withOutputFormat('mov'); |
||
| 58 | |||
| 59 | return $params; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getFileExtension(): string |
||
| 63 | { |
||
| 64 | return 'mov'; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | /* |
||
| 69 | * Project Format Resolution Frame Size Bits FPS <bitrate> |
||
| 70 | 1080i / 59.94 DNxHD 220 1920 x 1080 8 29.97 220Mb |
||
| 71 | 1080i / 59.94 DNxHD 145 1920 x 1080 8 29.97 145Mb |
||
| 72 | 1080i / 50 DNxHD 185 1920 x 1080 8 25 185Mb |
||
| 73 | 1080i / 50 DNxHD 120 1920 x 1080 8 25 120Mb |
||
| 74 | 1080p / 25 DNxHD 185 1920 x 1080 8 25 185Mb |
||
| 75 | 1080p / 25 DNxHD 120 1920 x 1080 8 25 120Mb |
||
| 76 | 1080p / 25 DNxHD 36 1920 x 1080 8 25 36Mb |
||
| 77 | 1080p / 24 DNxHD 175 1920 x 1080 8 24 175Mb |
||
| 78 | 1080p / 24 DNxHD 115 1920 x 1080 8 24 115Mb |
||
| 79 | 1080p / 24 DNxHD 36 1920 x 1080 8 24 36Mb |
||
| 80 | 1080p / 23.976 DNxHD 175 1920 x 1080 8 23.976 175Mb |
||
| 81 | 1080p / 23.976 DNxHD 115 1920 x 1080 8 23.976 115Mb |
||
| 82 | 1080p / 23.976 DNxHD 36 1920 x 1080 8 23.976 36Mb |
||
| 83 | 1080p / 29.7 DNxHD 45 1920 x 1080 8 29.97 45Mb |
||
| 84 | 720p / 59.94 DNxHD 220 1280x720 8 59.94 220Mb |
||
| 85 | 720p / 59.94 DNxHD 145 1280x720 8 59.94 145Mb |
||
| 86 | 720p / 50 DNxHD 175 1280x720 8 50 175Mb |
||
| 87 | 720p / 50 DNxHD 115 1280x720 8 50 115Mb |
||
| 88 | 720p / 23.976 DNxHD 90 1280x720 8 23.976 90Mb |
||
| 89 | 720p / 23.976 DNxHD 60 1280x720 8 23.976 60Mb |
||
| 90 | */ |
||
| 91 |