Completed
Push — master ( e18231...8c2386 )
by Amin
02:57
created

MediaInfo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
c 1
b 1
f 0
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getJsonOutPut() 0 3 1
A initialize() 0 12 2
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\MediaInfo;
14
15
16
use Streaming\MediaInfo\Streams\Stream;
17
use Streaming\MediaInfo\Streams\StreamCollection;
18
use Streaming\Process\Process;
19
20
class MediaInfo
21
{
22
    /**
23
     * @param string|null $binary
24
     * @param string $path
25
     * @return StreamCollection
26
     * @throws \Streaming\Exception\Exception
27
     */
28
    public static function initialize(string $path, string $binary = 'mediainfo'): StreamCollection
29
    {
30
        $media_info = json_decode(static::getJsonOutPut(new Process($binary), $path), true);
31
32
        $streams = $media_info["media"]["track"];
33
        $stream_collection = [];
34
35
        foreach ($streams as $stream){
36
            $stream_collection[] = new Stream($stream);
37
        }
38
39
        return new StreamCollection($stream_collection);
40
    }
41
42
    /**
43
     * @param Process $media_info
44
     * @param string $path
45
     * @return string
46
     * @throws \Streaming\Exception\Exception
47
     */
48
    private static function getJsonOutPut(Process $media_info, string $path): string
49
    {
50
        return $media_info->addCommand(['--Output=JSON', $path])->run();
51
    }
52
}