conversion from mp3 to ogg using php

我怕爱的太早我们不能终老 提交于 2020-01-05 07:39:19

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/14957544/conversion-from-mp3-to-ogg-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!