Permalink
Browse files

added metadata filter

  • Loading branch information...
1 parent d3a71fc commit a1b70b4cdbc007bf2eb915865ba069c5862bc458 @elvenpath committed Jun 2, 2014
@@ -11,6 +11,11 @@
namespace FFMpeg\Filters;
+/**
+ * Interface FilterInterface
+ *
+ * @package FFMpeg\Filters
+ */
interface FilterInterface
{
/**
@@ -1,58 +0,0 @@
-<?php
-
-/*
- * This file is part of PHP-FFmpeg.
- *
- * (c) Alchemy <dev.team@alchemy.fr>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace FFMpeg\Filters\Frame;
-
-use FFMpeg\Exception\RuntimeException;
-use FFMpeg\Media\Frame;
-
-class DisplayRatioFixerFilter implements FrameFilterInterface
-{
- /** @var integer */
- private $priority;
-
- public function __construct($priority = 0)
- {
- $this->priority = $priority;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getPriority()
- {
- return $this->priority;
- }
-
- /**
- * {@inheritdoc}
- */
- public function apply(Frame $frame)
- {
- $dimensions = null;
- $commands = array();
-
- foreach ($frame->getVideo()->getStreams() as $stream) {
- if ($stream->isVideo()) {
- try {
- $dimensions = $stream->getDimensions();
- $commands[] = '-s';
- $commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight();
- break;
- } catch (RuntimeException $e) {
-
- }
- }
- }
-
- return $commands;
- }
-}
@@ -0,0 +1,75 @@
+<?php
+namespace FFMpeg\Filters\Metadata;
+
+use FFMpeg\Exception\RuntimeException;
+use FFMpeg\Filters\FilterInterface;
+use FFMpeg\Format\VideoInterface;
+use FFMpeg\Media\Video;
+
+/**
+ * Class MetadataFilter
+ *
+ * @see http://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata
+ *
+ * @package FFMpeg\Filters\Metadata
+ */
+class MetadataFilter implements FilterInterface
+{
+ /** @var integer */
+ private $priority;
+
+ private $metadata_fields = array();
+
+
+ /**
+ * @param int $priority
+ */
+ public function __construct($priority = 0)
+ {
+ $this->priority = $priority;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPriority()
+ {
+ return $this->priority;
+ }
+
+
+ /**
+ * @param string $field
+ * @param string $value
+ *
+ * @return MetadataFilter
+ */
+ public function set($field, $value)
+ {
+ $this->metadata_fields[$field] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param Video $video
+ * @param VideoInterface $format
+ *
+ * @return array
+ */
+ public function apply(Video $video, VideoInterface $format)
+ {
+ $commands = array();
+ try {
+ foreach ($this->metadata_fields as $field => $value) {
+ $commands[] = '-metadata';
+ $commands[] = $field . '="' . escapeshellarg($value) . '"';
+ }
+ } catch (RuntimeException $e) {
+
+ }
+
+ return $commands;
+ }
+
+}

0 comments on commit a1b70b4

Please sign in to comment.