skip to Main Content

I’ve set up a VPS server on Digitalocean. Installed Ubuntu 18.04, LAMP, etc.
Finally, I installed ffmpeg. It is working fine from terminal but when I try to execute it through php it gives a weird "Permission denied" error:

Here is some information:

root@vl:/# whereis ffmpeg
ffmpeg: /usr/local/bin/ffmpeg
root@vl:/# whereis ffprobe
ffprobe: /usr/local/bin/ffprobe

root@vl:/# ffmpeg -version
ffmpeg version N-102461-g8649f5dca6 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: –prefix=/usr/local/ffmpeg_build –pkg-config-flags=–static –extra-cflags=-I/usr/local/ffmpeg_build/include –extra-ldflags=-L/usr/local/ffmpeg_build/lib –extra-libs=’-lpthread -lm’ –ld=g++ –bindir=/usr/local/bin –enable-gpl –enable-gnutls –enable-libaom –enable-libass –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libsvtav1 –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 1.100 / 59. 1.100
libavformat 59. 0.101 / 59. 0.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.101 / 8. 0.101
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100

My php file:

echo shell_exec(“ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 output.mp4 2>&1”)
?>

The ERROR!:
ffmpeg version N-102461-g8649f5dca6 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04) configuration: –prefix=/usr/local/ffmpeg_build –pkg-config-flags=–static –extra-cflags=-I/usr/local/ffmpeg_build/include –extra-ldflags=-L/usr/local/ffmpeg_build/lib –extra-libs=’-lpthread -lm’ –ld=g++ –bindir=/usr/local/bin –enable-gpl –enable-gnutls –enable-libaom –enable-libass –enable-libfdk-aac –enable-libfreetype –enable-libmp3lame –enable-libopus –enable-libsvtav1 –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libx265 –enable-nonfree libavutil 57. 0.100 / 57. 0.100 libavcodec 59. 1.100 / 59. 1.100 libavformat 59. 0.101 / 59. 0.101 libavdevice 59. 0.100 / 59. 0.100 libavfilter 8. 0.101 / 8. 0.101 libswscale 6. 0.100 / 6. 0.100 libswresample 4. 0.100 / 4. 0.100 libpostproc 56. 0.100 / 56. 0.100 Input #0, gif, from ‘mj.gif’: Duration: 00:00:01.60, start: 0.000000, bitrate: 22863 kb/s Stream #0:0: Video: gif, bgra, 1400×1050, 10 fps, 10 tbr, 100 tbn output.mp4: Permission denied

From the past 24 hours I’ve tried installing ffmpeg in different ways (compiling & apt install), I’ve also tried changing the permission but still I’m stuck with this error.
Any help would be highly appreciated!
Thanks

2

Answers


  1. php shell stuff runs from a different user as root and you used root to execute it in the terminal. You would need to give the www-data user permission to run the file. probably because the file ffmpeg is trying to access (mj.gif) doesn’t have permissions set for everyone to read the file. Try running chmod 755 mj.gif in the directory the gif is in.

    Login or Signup to reply.
  2. Instead

    echo shell_exec("ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 output.mp4 2>&1")
    

    try something like

    echo shell_exec("ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 /var/www/your_app/output.mp4 2>&1")
    

    If it fails try chmod 777 /var/www/your_app

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search