Skip to content

Commit 879b7c1

Browse files
adding module
1 parent 546fded commit 879b7c1

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

examples/concatenate.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Sharapov A. <alexander@sharapov.biz>
5+
* Web: http://sharapov.biz
6+
* Date: 18.03.2018
7+
* Time: 23:46
8+
*/
9+
10+
11+
ini_set('display_errors', 1);
12+
date_default_timezone_set('UTC');
13+
require_once dirname(__FILE__) . '/../vendor/autoload.php';
14+
15+
// Init ffmpeg library
16+
$ffmpeg = \Sharapov\FFMpegExtensions\FFMpeg::create([
17+
'ffmpeg.binaries' => dirname(__FILE__).'/../../../ffmpeg-static/ffmpeg-3.4.2-64bit-static/ffmpeg',
18+
'ffprobe.binaries' => dirname(__FILE__).'/../../../ffmpeg-static/ffmpeg-3.4.2-64bit-static/ffprobe',
19+
'timeout' => 3600, // The timeout for the underlying process
20+
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
21+
]);
22+
23+
// $ffmpeg->open('source/ez/spokesperson-clip-01.mp4')
24+
25+
$collection = new \Sharapov\FFMpegExtensions\Media\VideoCollection();
26+
27+
28+
$collection
29+
->add($ffmpeg->open('source/ez/spokesperson-clip-01.mp4'))
30+
->add($ffmpeg->open('source/ez/spokesperson-clip-02.mp4'));
31+
32+
$result = $ffmpeg->concatenate($collection);
33+
34+
35+
36+

src/php-ffmpeg-extensions/FFMpeg.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Sharapov\FFMpegExtensions\Input\FileInterface;
1818
use Sharapov\FFMpegExtensions\Media\Audio;
1919
use Sharapov\FFMpegExtensions\Media\Video;
20+
use Sharapov\FFMpegExtensions\Media\VideoCollection;
2021

2122
class FFMpeg {
2223
/** @var FFMpegDriver */
@@ -99,6 +100,23 @@ public function open( $file ) {
99100
throw new InvalidArgumentException( 'Unable to detect file format, only audio and video supported' );
100101
}
101102

103+
/**
104+
* Opens a collection to be processed.
105+
*
106+
* @param $file
107+
* @return Audio|Video
108+
*
109+
* @throws InvalidArgumentException
110+
* @throws RuntimeException
111+
*/
112+
public function concatenate(\IteratorAggregate $collection) {
113+
114+
115+
print_r($collection);
116+
117+
return 'done';
118+
}
119+
102120
/**
103121
* Creates a new FFMpeg instance.
104122
*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* This file is part of PHP-FFmpeg-Extensions library.
4+
*
5+
* (c) Alexander Sharapov <alexander@sharapov.biz>
6+
* http://sharapov.biz/
7+
*
8+
*/
9+
10+
namespace Sharapov\FFMpegExtensions\Media;
11+
12+
/**
13+
* Video collection
14+
* @package Sharapov\FFMpegExtensions\Filters\Video\FilterComplexOptions
15+
*/
16+
class VideoCollection implements \Countable, \IteratorAggregate {
17+
private $_streams;
18+
19+
public function __construct( array $options = [] ) {
20+
$this->_streams = array_values( $options );
21+
}
22+
23+
/**
24+
* Returns the first video stream of the collection, null if the collection is
25+
* empty.
26+
*
27+
* @return null|Video
28+
*/
29+
public function first() {
30+
$option = reset( $this->_streams );
31+
32+
return $option ? : null;
33+
}
34+
35+
/**
36+
* Adds a video stream to the collection.
37+
*
38+
* @param Video $stream
39+
*
40+
* @return VideoCollection
41+
*/
42+
public function add( Video $stream ) {
43+
$this->_streams[] = $stream;
44+
45+
return $this;
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function count() {
52+
return count( $this->_streams );
53+
}
54+
55+
/**
56+
* Returns the array of contained options.
57+
*
58+
* @return array
59+
*/
60+
public function all() {
61+
return $this->_streams;
62+
}
63+
64+
/**
65+
* {@inheritdoc}
66+
*/
67+
public function getIterator() {
68+
return new \ArrayIterator( $this->_streams );
69+
}
70+
}

0 commit comments

Comments
 (0)