Skip to content

Commit 82de51e

Browse files
committed
throw ffmpeg error
1 parent 9260f88 commit 82de51e

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/FFMpeg/FFMpeg.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ public function video(): Video
4646
/**
4747
* @return array{0: int, 1: string[]}
4848
*/
49-
protected function execute(string $command): array
49+
protected function execute(string $command, bool $throw = true): array
5050
{
51+
5152
if ($this->logChannel) {
5253
Log::channel($this->logChannel)->info("ffmpeg: {$command}");
5354
}
5455

55-
exec($command, $output, $code);
56+
exec("{$command} 2>&1", $output, $code);
57+
58+
if ($throw && $code !== 0) {
59+
throw new Exception(
60+
"Error Executing ffmpeg: {$command}",
61+
500,
62+
new Exception(implode("\n", $output), $code)
63+
);
64+
}
5665

5766
return [$code, $output];
5867
}
@@ -62,30 +71,14 @@ protected function execute(string $command): array
6271
*/
6372
public function ffmpeg(string $command): array
6473
{
65-
$cmd = "{$this->ffmpeg} {$command} 2>&1";
66-
67-
[$code, $output] = $this->execute($cmd);
68-
69-
if ($code !== 0) {
70-
throw new Exception("Error Executing ffmpeg: {$cmd}", $code);
71-
}
72-
73-
return [$code, $output];
74+
return $this->execute("{$this->ffmpeg} {$command}");
7475
}
7576

7677
/**
7778
* @return array{0: int, 1: string[]}
7879
*/
7980
public function ffprobe(string $command): array
8081
{
81-
$cmd = "{$this->ffprobe} {$command} 2>&1";
82-
83-
[$code, $output] = $this->execute($cmd);
84-
85-
if ($code !== 0) {
86-
throw new Exception("Error Executing ffprobe: {$cmd}", $code);
87-
}
88-
89-
return [$code, $output];
82+
return $this->execute("{$this->ffprobe} {$command}");
9083
}
9184
}

0 commit comments

Comments
 (0)