Completed
Push — master ( 359fe7...152344 )
by Sébastien
03:49
created

ResolvePreset.php$0 ➔ getParams()   A

Complexity

Conditions 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 16
cp 0
rs 9.536
c 0
b 0
f 0
cc 1
crap 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A ResolvePreset.php$0 ➔ getFFmpegCLIValue() 0 3 1
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 */
20
    private $videoInfo;
21
22
    public function __construct(MediaToolsServiceInterface $mediaTools)
23
    {
24
        $this->mediaTools = $mediaTools;
25
    }
26
27
    public function getName(): string
28
    {
29
        return __CLASS__;
30
    }
31
32
    private function getVideoInfo(string $file): VideoInfoInterface
33
    {
34
        if ($this->videoInfo === null) {
35
            $this->videoInfo = $this->mediaTools->getReader()->getInfo($file);
36
        }
37
38
        return $this->videoInfo;
39
    }
40
41
    public function getParams(string $file, ?int $width = null, ?int $height = null): VideoConvertParams
42
    {
43
        $info = $this->getVideoInfo($file);
44
45
        $firstAudio = $info->getAudioStreams()->getFirst();
0 ignored issues
show
Unused Code introduced by
The assignment to $firstAudio is dead and can be removed.
Loading history...
46
        $firstVideo = $info->getVideoStreams()->getFirst();
0 ignored issues
show
Unused Code introduced by
The assignment to $firstVideo is dead and can be removed.
Loading history...
47
48
        $filters = new VideoFilterChain();
0 ignored issues
show
Unused Code introduced by
The assignment to $filters is dead and can be removed.
Loading history...
49
50
        // ffmpeg -i <input> -c:v dnxhd -vf "scale=1920:1080,fps=30000/1001,format=yuv422p" -b:v 145M -c:a pcm_s16le test3.mov
51
        // http://www.deb-indus.org/tuto/ffmpeg-howto.htm#Encoding_VC-3
52
        $params = (new VideoConvertParams())
53
            ->withVideoCodec('dnxhd')
54
            ->withAudioCodec('pcm_s16le')
55
            ->withVideoBitrate('145M')
56
            ->withVideoFilter(new class() implements FFMpegVideoFilterInterface {
57
                public function getFFmpegCLIValue(): string
58
                {
59
                    return 'scale=1920:1080,fps=30000/1001,format=yuv422p';
60
                }
61
            })
62
            ->withOutputFormat('mov');
63
64
        return $params;
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