scratch – Blame information for rev 115

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\Media;
13  
14 use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
15 use FFMpeg\Filters\Waveform\WaveformFilterInterface;
16 use FFMpeg\Filters\Waveform\WaveformFilters;
17 use FFMpeg\Driver\FFMpegDriver;
18 use FFMpeg\FFProbe;
19 use FFMpeg\Exception\RuntimeException;
20  
21 class Waveform extends AbstractMediaType
22 {
23 /** @var Video */
24 private $audio;
25 private $width;
26 private $height;
27  
28 public function __construct(Audio $audio, FFMpegDriver $driver, FFProbe $ffprobe, $width, $height)
29 {
30 parent::__construct($audio->getPathfile(), $driver, $ffprobe);
31 $this->audio = $audio;
32 $this->width = $width;
33 $this->height = $height;
34 }
35  
36 /**
37 * Returns the audio related to the waveform.
38 *
39 * @return Audio
40 */
41 public function getAudio()
42 {
43 return $this->audio;
44 }
45  
46 /**
47 * {@inheritdoc}
48 *
49 * @return WaveformFilters
50 */
51 public function filters()
52 {
53 return new WaveformFilters($this);
54 }
55  
56 /**
57 * {@inheritdoc}
58 *
59 * @return Waveform
60 */
61 public function addFilter(WaveformFilterInterface $filter)
62 {
63 $this->filters->add($filter);
64  
65 return $this;
66 }
67  
68 /**
69 * Saves the waveform in the given filename.
70 *
71 * @param string $pathfile
72 *
73 * @return Waveform
74 *
75 * @throws RuntimeException
76 */
77 public function save($pathfile)
78 {
79 /**
80 * might be optimized with http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg
81 * @see http://ffmpeg.org/ffmpeg.html#Main-options
82 */
83 $commands = array(
84 '-i', $this->pathfile, '-filter_complex',
85 'showwavespic=s='.$this->width.'x'.$this->height,
86 '-frames:v', '1'
87 );
88  
89 foreach ($this->filters as $filter) {
90 $commands = array_merge($commands, $filter->apply($this));
91 }
92  
93 $commands = array_merge($commands, array($pathfile));
94  
95 try {
96 $this->driver->command($commands);
97 } catch (ExecutionFailureException $e) {
98 $this->cleanupTemporaryFile($pathfile);
99 throw new RuntimeException('Unable to save waveform', $e->getCode(), $e);
100 }
101  
102 return $this;
103 }
104 }