Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

DASHFilter::DASHFilter()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 5
eloc 14
c 1
b 1
f 1
nc 8
nop 1
dl 0
loc 24
rs 9.4888
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
13
namespace Streaming\Filters;
14
15
16
use Streaming\DASH;
17
use Streaming\Format\X264;
18
use Streaming\Representation;
19
20
class DASHFilter extends Filter
21
{
22
    /**
23
     * @param $media
24
     */
25
    public function setFilter($media): void
26
    {
27
        $this->filter = $this->DASHFilter($media);
28
    }
29
30
    /**
31
     * @param DASH $media
32
     * @return array
33
     */
34
    private function DASHFilter(DASH $media)
35
    {
36
        $filter = $this->getAdditionalFilters($media->getFormat(), count($media->getRepresentations()));
37
38
        foreach ($media->getRepresentations() as $key => $representation) {
39
            if ($representation instanceof Representation) {
40
                $filter[] = "-map";
41
                $filter[] = "0";
42
                $filter[] = "-b:v:" . $key;
43
                $filter[] = $representation->getKiloBitrate() . "k";
44
45
                if (null !== $representation->getResize()) {
46
                    $filter[] = "-s:v:" . $key;
47
                    $filter[] = $representation->getResize();
48
                }
49
            }
50
        }
51
52
        if ($media->getAdaption()) {
53
            $filter[] = "-adaptation_sets";
54
            $filter[] = $media->getAdaption();
55
        }
56
57
        return $filter;
58
    }
59
60
    /**
61
     * @param $format
62
     * @param $count
63
     * @return array
64
     */
65
    private function getAdditionalFilters($format, $count)
66
    {
67
        $filter = [
68
            "-bf", "1", "-keyint_min", "120", "-g", "120",
69
            "-sc_threshold", "0", "-b_strategy", "0",
70
            "-use_timeline", "1", "-use_template", "1", "-f", "dash"
71
        ];
72
73
        if ($format instanceof X264) {
74
            $filter[] = "-profile:v:0";
75
            $filter[] = "main";
76
77
            while ($count > 0) {
78
                $filter[] = "-profile:v:" . $count;
79
                $filter[] = "baseline";
80
                $count--;
81
            }
82
        }
83
84
        return $filter;
85
    }
86
}