Skip to content

Commit e8b2478

Browse files
sebdesignRomain
authored andcommitted
Fix missing audio artwork metadata on multiple exports (PHP-FFMpeg#340)
When the metadata filter is applied on an `Audio` media, the `artwork` parameter was being unset from the metadata array. Saving the same `Audio` instance into multiple formats generated the correct commands for the first export, but the subsequent commands were missing the `artwork` parameter. This commit fixes this issue by copying (by value) the `metaArr` property to a local variable each time the filter is applied.
1 parent eebdbea commit e8b2478

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/FFMpeg/Filters/Audio/AddMetadataFilter.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
11+
1212
namespace FFMpeg\Filters\Audio;
1313

1414
use FFMpeg\Filters\Audio\AudioFilterInterface;
1515
use FFMpeg\Format\AudioInterface;
1616
use FFMpeg\Media\Audio;
1717

1818
class AddMetadataFilter implements AudioFilterInterface
19-
{
19+
{
2020
/** @var Array */
2121
private $metaArr;
2222
/** @var Integer */
@@ -36,17 +36,20 @@ public function getPriority()
3636

3737
public function apply(Audio $audio, AudioInterface $format)
3838
{
39-
if (is_null($this->metaArr))
39+
$meta = $this->metaArr;
40+
41+
if (is_null($meta)) {
4042
return ['-map_metadata', '-1', '-vn'];
43+
}
4144

4245
$metadata = [];
4346

44-
if (array_key_exists("artwork", $this->metaArr)) {
45-
array_push($metadata, "-i", $this->metaArr['artwork'], "-map", "0", "-map", "1");
46-
unset($this->metaArr['artwork']);
47+
if (array_key_exists("artwork", $meta)) {
48+
array_push($metadata, "-i", $meta['artwork'], "-map", "0", "-map", "1");
49+
unset($meta['artwork']);
4750
}
4851

49-
foreach ($this->metaArr as $k => $v) {
52+
foreach ($meta as $k => $v) {
5053
array_push($metadata, "-metadata", "$k=$v");
5154
}
5255

tests/Unit/Filters/Audio/AudioMetadataTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function testAddArtwork()
4141
$filters = new AudioFilters($audio);
4242
$filters->addMetadata(array('genre' => 'Some Genre', 'artwork' => "/path/to/file.jpg"));
4343
$this->assertEquals(array(0 => "-i", 1 => "/path/to/file.jpg", 2 => "-map", 3 => "0", 4 => "-map", 5 => "1", 6 => "-metadata", 7 => "genre=Some Genre"), $capturedFilter->apply($audio, $format));
44+
$this->assertEquals(array(0 => "-i", 1 => "/path/to/file.jpg", 2 => "-map", 3 => "0", 4 => "-map", 5 => "1", 6 => "-metadata", 7 => "genre=Some Genre"), $capturedFilter->apply($audio, $format));
4445
}
4546

4647
public function testRemoveMetadata()

0 commit comments

Comments
 (0)