0

I would like to find a solution to this problem: I have a list of images that i want to convert into a video on the server. I've created a virtual machine with centOS and installed ffmpeg to test that. Everything working well when I type myself this line in the terminal

sudo ffmpeg -r 10 -i img%03d.png -c:v libx264 -preset veryslow -crf 0 
video.mp4

What I want is to call this when I click on a button. Here is the code:

Javascript:

$(document).ready(function(){
    $("#ffmpeg").click(function(){
        $.get('ffmpegBooklet.php', function (data) {
            console.log(data);
       });
    });
});

PHP:

echo shell_exec("/usr/local/bin/ffmpeg  -r 10 -i /img%03d.png -c:v 
libx264 -preset veryslow -crf 0 video.mp4 2>&1");

What i get in the console of the browser is : the log from ffmpeg and at the end --> Permission denied

I've tried with a static build (after reading on internet) but I have the same problem. Is there any solution to do this without the sudo rights? I don't want to do this as sudo or to some tricky command to give sudo permissions through php because I think it's not secure.

Any helps is welcome! Thanks for reading it :)

P.G
  • 1
  • 5
  • Possible duplicate of [Execute root commands via PHP](https://stackoverflow.com/questions/8532304/execute-root-commands-via-php) – Sean Aug 07 '17 at 10:16
  • 1
    Instead of running as root set up the proper permissions for the output paths. – aergistal Aug 07 '17 at 10:48
  • ok! The permission's problem is not coming from the execution of ffmpeg but from output? I thought that calling the program without being root was the problem – P.G Aug 07 '17 at 11:26
  • I've tried with a folder with permissions (chmod 777) and I get the same error : permission denied – P.G Aug 07 '17 at 12:10
  • @P.G check the input too. And instead of `777` change the group to one which includes the owner of the `php` process and make sure it can write to it. – aergistal Aug 07 '17 at 12:16
  • @aergistral thanks for your help: both folders, input and output are in blue with green background when I list the folders. Still the same permission denied... I also understand that it would cleaner to work with group and I'll do that but it should work now or I miss something? – P.G Aug 07 '17 at 12:31
  • P.G. if if still not works I would check if `SELinux` is enabled – aergistal Aug 07 '17 at 12:37
  • Thanks I'll take a moment with all this permissions story. I think I' missing something and I'll go back to you :) – P.G Aug 07 '17 at 12:41
  • Sooooo I conceded as root and change the owner for input and output paths (which were root). I check and both are not root anymore but my name (my session). I still have a permission denied and now I receive a ,message from SELinux Alert broker saying that ffmpeg (process) tried to attempt this access (write) in the directory. SELinux give me the explanation on "how to allow ffmpeg to write on the directory". Should I try this? – P.G Aug 07 '17 at 14:05

1 Answers1

0

Fixed like this. Thank you for the help.

I disabled SELinux just to check what happened. FFmpeg through php worked like a charm. I checked the file created and the owner and group were apache:apache. First, I've changed the owner of the folder for input and output and set apache. Then I gave rights to apache. I switched on SELinux and had again the permission problem. I've found this solution, which fixed my issue:

# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html(/.*)?'

# restorecon -R /var/www/html

I've also add my profile to the apache group because I couldn't access the folder anymore.

Now everything is working with SELinux ON, which satisfied me. FFmpeg/apache are not blocked anymore!

P.G
  • 1
  • 5