FFmpeg works on terminal not with PHP exec
15,707
Solution 1
The problem is that you use exec
instead of shell_exec
the point is that environement of exec don't know about any FFmpeg executable, but shell_exec
* does, becuase it uses env. of the bash/shell
Ths solution is to use the full path to FFmpeg executable, eg. /usr/bin/ffmpeg
Solution 2
add 2>&1
to the end of the command and it will work:
exec("ffmpeg -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv 2>&1", $o, $v);
Related videos on Youtube
Author by
InziKhan
Updated on September 18, 2022Comments
-
InziKhan almost 2 years
If I execute a Ffmpeg command from terminal, I get the desired result:
ffmpeg -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv
Terminal's output:
... video:3404kB audio:1038kB global headers:0kB muxing overhead 2.966904%
And
video.flv
is created correctly.Then, if called via PHP exec:
exec("ffmpeg -i src.mp4 -ar 22050 -ab 32 -f flv -s 320x240 video.flv", $o, $v); var_dump($o); var_dump($v);
The output is this:
array(0) { } int(1)
And no file is created. Any thoughts on how to approach this?
I can
exec('whoami')
with no problems and I have used the FFmpeg full path as well:/usr/local/bin/ffmpeg
-
Oliver Salzburg over 12 yearsMaybe exec() only captures stdout in
output
, not stderr. -
slhck over 12 yearsFFmpeg produces very weird output — you have to redirect both stdout and stderr to get everything AFAIK.
-
-
slhck almost 12 yearsNo, the user said they tried
/usr/local/bin/ffmpeg
as well. -
Rodislav Moldovan almost 12 yearswe had same issue half year ago, solution, described above, solved the problem, what about "/usr/local/bin/ffmpeg", maybe - bin folder is not correct !?..
-
Rishiraj Purohit almost 4 years
exec
with full path/usr/local/bin/ffmpeg
worked for me, i found the path usingwhich ffmpeg