1

I wrote few lines of codes today to create an video from an image with ffmpeg.

the command works well directly on my server and the file is saved at the good place, but when running it from PHP, the process goes, but the file won't save for some reason.

Here is the code I use :

$ffmpegcmd= "/usr/bin/ffmpeg -loop 1 -y -i /home/mysite/www/forwork/simpletext.jpg -c:v libx264 -t 30 -pix_fmt yuv420p /home/mysite/www/forwork/movie.avi 2>&1";
exec($ffmpegcmd, $output);  
print_r($output);

And here is the answer I get :

Array ( [0] => ffmpeg version git-2015-09-06-db18b3d Copyright (c) 2000-2015 the FFmpeg developers 
[1] => built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16) 
[2] => configuration: --prefix=/usr/ffmpeg_build --extra-cflags=-I/usr/ffmpeg_build/include --extra-ldflags=-L/usr/ffmpeg_build/lib --bindir=/usr/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 
[3] => libavutil 55. 0.100 / 55. 0.100 
[4] => libavcodec 57. 0.100 / 57. 0.100 
[5] => libavformat 57. 0.100 / 57. 0.100 
[6] => libavdevice 57. 0.100 / 57. 0.100 
[7] => libavfilter 6. 0.100 / 6. 0.100 
[8] => libswscale 4. 0.100 / 4. 0.100 
[9] => libswresample 2. 0.100 / 2. 0.100 
[10] => libpostproc 54. 0.100 / 54. 0.100 
[11] => Input #0, image2, from '/home/mysite/www/forwork/simpletext.jpg': 
[12] => Duration: 00:00:00.04, start: 0.000000, bitrate: 10414 kb/s 
[13] => Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc 
[14] => /home/mysite/www/forwork/movie.avi: Permission denied )

I chmod the forwork directory to 755 but it won't change anything.

help troubleshooting this would be greatly appreciate. Thanks

5
  • Did you do chmod -R 755 /home/mysite/www/forwork/? If the file has different permissions that could be an issue. Also remember php runs a different user to you... Commented Sep 6, 2015 at 18:44
  • @ScottMcGready yes, did the chmod -R and the problem remains unfortunately Commented Sep 6, 2015 at 18:47
  • Which user is apache/PHP running as? Ensure they have permissions to the group that owns movie.avi (might not solve your question but a worthwhile thing to check. Commented Sep 6, 2015 at 18:48
  • 1
    @ScottMcgready Actually after your comment, I deleted the file movie.avi (which was created from the root user) and the script now runs well. So it was actually a problem of permission. Thanks for the heads up. Commented Sep 6, 2015 at 18:51
  • glad to hear it! for the avoidance of doubt I've summarised my comments below as an answer for any future browsers of this question. Commented Sep 6, 2015 at 18:57

1 Answer 1

4

Permissions errors can cause quite the headache. Here's a few things you can do to ensure your script has the correct permissions:

  • Ensure both the parent folder, and it's contents are readable by doing a chmod -R 755 /home/mysite/www/forwork/
  • Check the ownership of the file/directory by doing ls -l
  • Add Apache's user into the group that owns the folder/file (alternatively run chown -R apacheuser:group /home/mysite/www/forwork on the parent folder.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.