6
6
class ffmpegDetective implements DetectiveContract
7
7
{
8
8
use DetectiveTrait;
9
-
9
+
10
10
/**
11
11
* Format types detected by ffprobe.
12
12
*
13
13
* @var array
14
14
*/
15
15
private $ formats ;
16
-
16
+
17
17
/**
18
18
* Runs an ffprobe on the file or returns cached information.
19
19
*
20
20
* @return array|false
21
21
*/
22
- private function ffprobe ()
22
+ private function ffprobe ($ binary = " ffmpeg " )
23
23
{
24
24
if (!isset ($ this ->metadata ))
25
25
{
26
- $ cmd = env ( ' LIB_FFPROBE ' , " ffprobe " ) . " -v quiet -print_format json -show_format -show_streams {$ this ->file }" ;
27
-
26
+ $ cmd = "{ $ binary } -v quiet -print_format json -show_format -show_streams {$ this ->file }" ;
27
+
28
28
exec ($ cmd , $ output , $ returnvalue );
29
-
29
+
30
30
$ json = json_decode ( implode ("\n" , $ output ), true );
31
-
31
+
32
32
if (!is_array ($ json ))
33
33
{
34
34
$ json = false ;
35
35
}
36
-
36
+
37
37
$ this ->metadata = $ json ;
38
-
38
+
39
39
if ($ this ->ffprobeHasFormat ())
40
40
{
41
41
$ this ->formats = array_filter (explode (", " , $ json ['format ' ]['format_name ' ]));
42
42
}
43
43
}
44
44
}
45
-
45
+
46
46
/**
47
47
* Checks requested format against what formats ffprobe returned.
48
48
*
@@ -53,25 +53,25 @@ private function ffprobe()
53
53
private function ffprobeFormat ($ format )
54
54
{
55
55
$ this ->ffprobe ();
56
-
56
+
57
57
if (count ($ this ->formats ) > 0 )
58
58
{
59
59
$ args = func_get_args ();
60
-
60
+
61
61
foreach ($ args as $ arg )
62
62
{
63
63
if (in_array ($ arg , $ this ->formats ))
64
64
{
65
65
return true ;
66
66
}
67
67
}
68
-
68
+
69
69
return null ;
70
70
}
71
-
71
+
72
72
return false ;
73
73
}
74
-
74
+
75
75
/**
76
76
* Check our metadata for format name.
77
77
*
@@ -83,10 +83,10 @@ private function ffprobeHasFormat()
83
83
{
84
84
return $ this ->metadata ['format ' ]['format_name ' ] ?: false ;
85
85
}
86
-
86
+
87
87
return false ;
88
88
}
89
-
89
+
90
90
/**
91
91
* Check our metadata for a video stream.
92
92
*
@@ -104,10 +104,10 @@ private function ffprobeHasVideo()
104
104
}
105
105
}
106
106
}
107
-
107
+
108
108
return false ;
109
109
}
110
-
110
+
111
111
/**
112
112
* Check our metadata for an audio stream.
113
113
*
@@ -125,10 +125,10 @@ private function ffprobeHasAudio()
125
125
}
126
126
}
127
127
}
128
-
128
+
129
129
return false ;
130
130
}
131
-
131
+
132
132
/**
133
133
* Checks if the file is a 3GP.
134
134
*
@@ -137,15 +137,15 @@ private function ffprobeHasAudio()
137
137
protected function lead3GP ()
138
138
{
139
139
$ lead = $ this ->ffprobeFormat ("3gp " );
140
-
140
+
141
141
if ($ lead === true )
142
142
{
143
143
return $ this ->closeCase ("3gp " , "video/3gp " , $ this ->metadata );
144
144
}
145
-
145
+
146
146
return null ;
147
147
}
148
-
148
+
149
149
/**
150
150
* Checks if the file is a AAC
151
151
*
@@ -154,15 +154,15 @@ protected function lead3GP()
154
154
protected function leadAAC ()
155
155
{
156
156
$ lead = $ this ->ffprobeFormat ("aac " );
157
-
157
+
158
158
if ($ lead === true )
159
159
{
160
160
return $ this ->closeCase ("aac " , "audio/aac " , $ this ->metadata );
161
161
}
162
-
162
+
163
163
return null ;
164
164
}
165
-
165
+
166
166
/**
167
167
* Checks if the file is a FLV.
168
168
*
@@ -171,15 +171,15 @@ protected function leadAAC()
171
171
protected function leadFLV ()
172
172
{
173
173
$ lead = $ this ->ffprobeFormat ("flv " );
174
-
174
+
175
175
if ($ lead === true )
176
176
{
177
177
return $ this ->closeCase ("flv " , "video/x-flv " , $ this ->metadata );
178
178
}
179
-
179
+
180
180
return null ;
181
181
}
182
-
182
+
183
183
/**
184
184
* Checks if the file is a MP3
185
185
*
@@ -188,15 +188,15 @@ protected function leadFLV()
188
188
protected function leadMP3 ()
189
189
{
190
190
$ lead = $ this ->ffprobeFormat ("mp1 " , "mp2 " , "mp3 " , "mpg " , "mpeg " );
191
-
191
+
192
192
if ($ lead === true )
193
193
{
194
194
return $ this ->closeCase ("mp3 " , "audio/mpeg " , $ this ->metadata );
195
195
}
196
-
196
+
197
197
return null ;
198
198
}
199
-
199
+
200
200
/**
201
201
* Checks if the file is a MP4.
202
202
*
@@ -205,7 +205,7 @@ protected function leadMP3()
205
205
protected function leadMP4 ()
206
206
{
207
207
$ lead = $ this ->ffprobeFormat ("mp4 " , "m4a " );
208
-
208
+
209
209
if ($ lead === true )
210
210
{
211
211
if ($ this ->ffprobeHasVideo () !== false )
@@ -221,10 +221,10 @@ protected function leadMP4()
221
221
return false ;
222
222
}
223
223
}
224
-
224
+
225
225
return null ;
226
226
}
227
-
227
+
228
228
/**
229
229
* Checks if the file is a MKA.
230
230
*
@@ -233,7 +233,7 @@ protected function leadMP4()
233
233
protected function leadMKA ()
234
234
{
235
235
$ lead = $ this ->ffprobeFormat ("matroska " , "webm " );
236
-
236
+
237
237
if ($ lead === true )
238
238
{
239
239
if ($ this ->ffprobeHasAudio () !== false )
@@ -245,10 +245,10 @@ protected function leadMKA()
245
245
return false ;
246
246
}
247
247
}
248
-
248
+
249
249
return null ;
250
250
}
251
-
251
+
252
252
/**
253
253
* Checks if the file is a MKV.
254
254
*
@@ -257,7 +257,7 @@ protected function leadMKA()
257
257
protected function leadMKV ()
258
258
{
259
259
$ lead = $ this ->ffprobeFormat ("matroska " , "webm " );
260
-
260
+
261
261
if ($ lead === true )
262
262
{
263
263
if ($ this ->ffprobeHasVideo () !== false )
@@ -269,10 +269,10 @@ protected function leadMKV()
269
269
return false ;
270
270
}
271
271
}
272
-
272
+
273
273
return null ;
274
274
}
275
-
275
+
276
276
/**
277
277
* Checks if the file is a OGG Audio-only (OGA).
278
278
*
@@ -281,7 +281,7 @@ protected function leadMKV()
281
281
protected function leadOGG ()
282
282
{
283
283
$ lead = $ this ->ffprobeFormat ("ogg " , "oga " , "ogv " );
284
-
284
+
285
285
if ($ lead === true )
286
286
{
287
287
if ($ this ->ffprobeHasVideo () !== false )
@@ -297,10 +297,10 @@ protected function leadOGG()
297
297
return false ;
298
298
}
299
299
}
300
-
300
+
301
301
return null ;
302
302
}
303
-
303
+
304
304
/**
305
305
* Checks if the file is a WAV
306
306
*
@@ -309,15 +309,15 @@ protected function leadOGG()
309
309
protected function leadWAV ()
310
310
{
311
311
$ lead = $ this ->ffprobeFormat ("wav " );
312
-
312
+
313
313
if ($ lead === true )
314
314
{
315
315
return $ this ->closeCase ("wav " , "audio/wave " , $ this ->metadata );
316
316
}
317
-
317
+
318
318
return null ;
319
319
}
320
-
320
+
321
321
/**
322
322
* Checks if the file is a WEBM.
323
323
*
@@ -326,7 +326,7 @@ protected function leadWAV()
326
326
protected function leadWEBM ()
327
327
{
328
328
$ lead = $ this ->ffprobeFormat ("webm " );
329
-
329
+
330
330
if ($ lead === true )
331
331
{
332
332
if ($ this ->ffprobeHasVideo () !== false )
@@ -342,10 +342,10 @@ protected function leadWEBM()
342
342
return false ;
343
343
}
344
344
}
345
-
345
+
346
346
return null ;
347
347
}
348
-
348
+
349
349
/**
350
350
* Can this file type potentially cause damage or intrude on a user's privacy?
351
351
* This means executable programs, or file formats that can contact remote servers in any way (even SVGs).
@@ -356,10 +356,10 @@ protected function leadWEBM()
356
356
public function isRisky ()
357
357
{
358
358
parent ::isRisky ();
359
-
359
+
360
360
return false ;
361
361
}
362
-
362
+
363
363
/**
364
364
* Can the system run this Detective?
365
365
*
@@ -369,7 +369,7 @@ public function on()
369
369
{
370
370
$ ffmpeg = shell_exec ("which ffmpeg " );
371
371
$ ffprobe = shell_exec ("which ffprobe " );
372
-
372
+
373
373
return (empty ($ ffmpeg ) ? false : true ) && (empty ($ ffprobe ) ? false : true );
374
374
}
375
- }
375
+ }
0 commit comments