Pergunta

I want to convert mp3 file to ogg. I tried the following code

exec("/usr/local/bin/ffmpeg -i 1.mp4 -vcodec libtheora -acodec libvorbis testjohn4545454.ogg",$output);
var_dump($output);

But it does not convert the file and it only returns array(0) { } and it only takes a little execution time.

But the conversion is success when using ssh command.

Please give me solution.

Foi útil?

Solução 4

Thank you for the replies. I used passthru() instead of exec() and it works fine.

Outras dicas

Funny thing here, you want to execute this in it's own process and in the background, otherwise your PHP script will hang whilst waiting for the conversion to complete.

The code:

passthru("nohup /usr/local/bin/ffmpeg -i 1.mp4 -vcodec libtheora -acodec libvorbistestjohn4545454.ogg 1> /path/to/logfile.txt 2>&1 &");

Note the "nohup" and the ampersand on the end: these should give you what you require. Also, you can now check your logfile periodically to make sure that it's doing what you want.

And finally, check out this question for creating a progress bar, if you like.

I had a similar problem once but i've choose to save and read files (input file and output converted file) in a apache writable folder You can also check if convertion is alredy done via reading that directory.

Can you check your disabled_functions configuration on PHP and see if exec is not there? Also you might want to enable all error reporting and after try to exec() with a simple bash echo and see how it goes. If all goes well then check if you are using the correct files, as Jamie pointed out, the working directory might be the wrong one so use absolute paths or relative, whatever is most convenient. The Unix command for checking what is the current working directory is pwd.

Edit: Also, exec has another caveat When safe mode is enabled, you can only execute files within the safe_mode_exec_dir so be sure to have a good read on the manual for other problems.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top