conversion from mp3 to ogg using php

2019-07-29 23:01发布

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.

4条回答
贪生不怕死
2楼-- · 2019-07-29 23:21

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-29 23:27

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.

查看更多
老娘就宠你
4楼-- · 2019-07-29 23:31

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.

查看更多
甜甜的少女心
5楼-- · 2019-07-29 23:32

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

查看更多
登录 后发表回答