Fix missing audio artwork metadata on multiple exports (#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.
This commit is contained in:
parent
eebdbea1f7
commit
e8b247891b
2 changed files with 11 additions and 7 deletions
|
|
@ -8,7 +8,7 @@
|
|||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
namespace FFMpeg\Filters\Audio;
|
||||
|
||||
use FFMpeg\Filters\Audio\AudioFilterInterface;
|
||||
|
|
@ -16,7 +16,7 @@ use FFMpeg\Format\AudioInterface;
|
|||
use FFMpeg\Media\Audio;
|
||||
|
||||
class AddMetadataFilter implements AudioFilterInterface
|
||||
{
|
||||
{
|
||||
/** @var Array */
|
||||
private $metaArr;
|
||||
/** @var Integer */
|
||||
|
|
@ -36,17 +36,20 @@ class AddMetadataFilter implements AudioFilterInterface
|
|||
|
||||
public function apply(Audio $audio, AudioInterface $format)
|
||||
{
|
||||
if (is_null($this->metaArr))
|
||||
$meta = $this->metaArr;
|
||||
|
||||
if (is_null($meta)) {
|
||||
return ['-map_metadata', '-1', '-vn'];
|
||||
}
|
||||
|
||||
$metadata = [];
|
||||
|
||||
if (array_key_exists("artwork", $this->metaArr)) {
|
||||
array_push($metadata, "-i", $this->metaArr['artwork'], "-map", "0", "-map", "1");
|
||||
unset($this->metaArr['artwork']);
|
||||
if (array_key_exists("artwork", $meta)) {
|
||||
array_push($metadata, "-i", $meta['artwork'], "-map", "0", "-map", "1");
|
||||
unset($meta['artwork']);
|
||||
}
|
||||
|
||||
foreach ($this->metaArr as $k => $v) {
|
||||
foreach ($meta as $k => $v) {
|
||||
array_push($metadata, "-metadata", "$k=$v");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class AudioMetadataTest extends TestCase
|
|||
$filters = new AudioFilters($audio);
|
||||
$filters->addMetadata(array('genre' => 'Some Genre', 'artwork' => "/path/to/file.jpg"));
|
||||
$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));
|
||||
$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));
|
||||
}
|
||||
|
||||
public function testRemoveMetadata()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue