@@ -46,13 +46,22 @@ public function video(): Video
46
46
/**
47
47
* @return array{0: int, 1: string[]}
48
48
*/
49
- protected function execute (string $ command ): array
49
+ protected function execute (string $ command, bool $ throw = true ): array
50
50
{
51
+
51
52
if ($ this ->logChannel ) {
52
53
Log::channel ($ this ->logChannel )->info ("ffmpeg: {$ command }" );
53
54
}
54
55
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
+ }
56
65
57
66
return [$ code , $ output ];
58
67
}
@@ -62,30 +71,14 @@ protected function execute(string $command): array
62
71
*/
63
72
public function ffmpeg (string $ command ): array
64
73
{
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 }" );
74
75
}
75
76
76
77
/**
77
78
* @return array{0: int, 1: string[]}
78
79
*/
79
80
public function ffprobe (string $ command ): array
80
81
{
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 }" );
90
83
}
91
84
}
0 commit comments