Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
17018 efrain 1
<?php
2
namespace LeadersLinked\Library;
3
 
4
 
5
class Video
6
{
7
 
8
 
9
    public static function extractPoster($source_filename, $target_filename)
10
    {
11
 
12
        try {
13
            $cmd        = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $source_filename";
14
            $response   = trim(shell_exec($cmd));
15
 
16
            $source_duration = 0;
17
            $lines = explode("\n", $response);
18
            foreach ($lines as $line) {
19
                $line = trim(strtolower($line));
20
                if (strpos($line, 'duration') !== false) {
21
                    $values = explode('=', $line);
22
                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
23
                }
24
            }
25
 
26
 
27
            if ($source_duration == 0) {
28
                $second_extract = '00:00:02';
29
            } else {
30
                if ($source_duration > 10) {
31
                    $second_extract = '00:00:10';
32
                } else {
33
                    $second_extract = '00:00:02';
34
                }
35
            }
36
 
37
            $cmd = "/usr/bin/ffmpeg -y -i $source_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $target_filename";
38
            exec($cmd);
39
 
40
            return true;
41
 
42
        }
43
        catch (\Throwable $e)
44
        {
45
 
46
            return false;
47
 
48
        }
49
 
50
 
51
    }
52
}