scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of PHP-FFmpeg.
5 *
6 * (c) Alchemy <info@alchemy.fr>
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 namespace FFMpeg;
13  
14 use Alchemy\BinaryDriver\ConfigurationInterface;
15 use FFMpeg\Driver\FFMpegDriver;
16 use FFMpeg\Exception\InvalidArgumentException;
17 use FFMpeg\Exception\RuntimeException;
18 use FFMpeg\Media\Audio;
19 use FFMpeg\Media\Video;
20 use Psr\Log\LoggerInterface;
21  
22 class FFMpeg
23 {
24 /** @var FFMpegDriver */
25 private $driver;
26 /** @var FFProbe */
27 private $ffprobe;
28  
29 public function __construct(FFMpegDriver $ffmpeg, FFProbe $ffprobe)
30 {
31 $this->driver = $ffmpeg;
32 $this->ffprobe = $ffprobe;
33 }
34  
35 /**
36 * Sets FFProbe.
37 *
38 * @param FFProbe
39 *
40 * @return FFMpeg
41 */
42 public function setFFProbe(FFProbe $ffprobe)
43 {
44 $this->ffprobe = $ffprobe;
45  
46 return $this;
47 }
48  
49 /**
50 * Gets FFProbe.
51 *
52 * @return FFProbe
53 */
54 public function getFFProbe()
55 {
56 return $this->ffprobe;
57 }
58  
59 /**
60 * Sets the ffmpeg driver.
61 *
62 * @return FFMpeg
63 */
64 public function setFFMpegDriver(FFMpegDriver $ffmpeg)
65 {
66 $this->driver = $ffmpeg;
67  
68 return $this;
69 }
70  
71 /**
72 * Gets the ffmpeg driver.
73 *
74 * @return FFMpegDriver
75 */
76 public function getFFMpegDriver()
77 {
78 return $this->driver;
79 }
80  
81 /**
82 * Opens a file in order to be processed.
83 *
84 * @param string $pathfile A pathfile
85 *
86 * @return Audio|Video
87 *
88 * @throws InvalidArgumentException
89 */
90 public function open($pathfile)
91 {
92 if (null === $streams = $this->ffprobe->streams($pathfile)) {
93 throw new RuntimeException(sprintf('Unable to probe "%s".', $pathfile));
94 }
95  
96 if (0 < count($streams->videos())) {
97 return new Video($pathfile, $this->driver, $this->ffprobe);
98 } elseif (0 < count($streams->audios())) {
99 return new Audio($pathfile, $this->driver, $this->ffprobe);
100 }
101  
102 throw new InvalidArgumentException('Unable to detect file format, only audio and video supported');
103 }
104  
105 /**
106 * Creates a new FFMpeg instance.
107 *
108 * @param array|ConfigurationInterface $configuration
109 * @param LoggerInterface $logger
110 * @param FFProbe $probe
111 *
112 * @return FFMpeg
113 */
114 public static function create($configuration = array(), LoggerInterface $logger = null, FFProbe $probe = null)
115 {
116 if (null === $probe) {
117 $probe = FFProbe::create($configuration, $logger, null);
118 }
119  
120 return new static(FFMpegDriver::create($logger, $configuration), $probe);
121 }
122 }