I have a php upload script that converts MP3 files after they have been uploaded. I am keeping the mp3 file which is why I am doing it afterwards. A copy is created and then that is converted to ogg. The problem i am having is with FFMPEG as it is just not doing anything. I have never used FFMPEG or a tool like it before, nor have I used PHP's exec() function so I really have no idea how to use it but I have had a thorough look around for my answer before I came here.
exec("ffmpeg -i ".$target_path."".$hash_filename.".".$path_extension." ".$hash_filename.".ogg");
What the function could look like with data instead of variables:
ffmpeg -i ../uploads/ee78d5deb564901626067cc0008456ed.mp3 ee78d5deb564901626067cc0008456ed.ogg
I have checked with SSH and FFMPEG is located under the usual usr/bin/ffmpeg. I wondered if I should be targeting the file from where FFMPEG is or where the phpscript is but I have had no luck with either. Perhaps I am still targeting it from the wrong place?
I have checked and the codecs required for mp3 to ogg conversion are installed. I did also try adding those codecs into the command but the same thing happened. I understand FFMPEG automatically chooses which codecs to use so I ommited them.
Related
I am creating a website which enables to upload videos. But we know that user can upload any kind of video but the browser can't play them. So, I thought that I somehow can convert them into .swf and play them using a flash player. I tried to use ffmpeg-php but it didn't worked. my code was:
shell_exec('ffmpeg -i in.mp4 out.swf');
It does not show any error neither it returns out.swf.
Please! help me.
Things to check:
Does the in.mp4 file actually exist on the server and is it in the
correct temporary folder?
Check that file size limits (upload_max_filesize PHP setting) are
not being hit.
Does the ffmpeg command work properly from a shell promt as the
user that the webserver is running as? (this test should be
performed in the folder where you are processing the file) Use the
verbose logging options to check for errors
Capture all the output from the shell_exec and check for errors.
Try using system or exec where you can also capture the return
value of ffmpeg which can then be used for error checking
Finally, I would specify actual directory names for the input and output files. This will narrow down problems as you know exactly what folder to look in for results. You can also adjust permissions if required
Am new to php. With some of the reference to the posts on Stackoverflow, i've tried out the method to convert an mp3 audio file to ogg simultaneously while uploading to the server, initially i checked on my localhost, i always got an output int(1) in response for var_dump($output), but i cant see the ogg converted file saved anywhere in folder. Can any please guilde, its urgent. My questions are:
1) Do i need to provide path for both input and output files, if yes then, did i mention properly in code here.
2) where exactly i need to save/place the entire ffmpeg folder / ffmpeg.exe
3) Are all the path mentioned w.r.t the input and output file proper in code here ?
passthru("/admin/ffmpeg32/bin/ffmpeg.exe -i audioUpload/".$_FILES['audio_file']['name']." -vcodec libtheora -acodec libvorbis -target ./ffmpeg32/ogg/$file_name".".ogg",$output);
var_dump($output);
imagemagick convert does not work through php shell_exec but does through a shell.
In a shell convert file.pdf file.png works fine. But when I have this within a php file as shell_exec('convert file.pdf file.png'); Then I get no output! I have the permissions to do this, so I think it isn't that that's the problem; I have checked the directory I am in by way of getcwd() and this is also ok.
I know shell_exec works because I have used it earlier in the code and that works fine.
Any ideas?
I got the solution thanks to Crontab from another thread. I quote from there:
[I]f you're trying to convert a PDF to a PNG using ImageMagick ...
even using the full path to ImageMagick's convert won't work if the
script's PATH doesn't contain the path location to Ghostscript also.
Without messing with any user paths, you could add:
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
Or something similar depending on your setup. The gs executable has
to be in your script user's path somewhere or ImageMagick will fail to
convert PDF or EPS files.
Try the full path to convert, i.e. shell_exec('/usr/bin/convert file.pdf file.png);. You can use which convert to find the location on your system.
There are several reason why this could happen, but I suggest reading this page and the user comments:
http://php.net/manual/en/function.shell-exec.php
I have a problem. I have the service which is giving me .exe file which they claim is in fact zip archive. A self-extracting archive.
Problem is that I am downloading that with my app (php) to server and need to extract it there witout downloading to local computer.
I have tried download .exe file to local computer - it is self extracting on windows to /temp dir and than self launching FLASH player.
$zip = zip_open($myfile); gives in print_r($zip): 1
zip->open gives no results either.
change .exe to .zip doesn't let winzip or other kind of un-packer on windows to open it - .exe cannot be opened by winzip too.
Now I have no idea how to deal with it. If anybody can advise please.
Try to execute the program as an executable with the system command
Executing files from an external source you don't trust 100% is never a good idea.
The info-zip version of zip allows you to remove the SFX stub from a self-extracting zip file (with the -J flag) converting it back into a normal zip file.
Source code is freely available.
Making a self-extracting zip file is a matter of prepending a zip file with the SFX binary code, then appending the size of the binary stub to the resulting file - but I'm not sure how the data is represented - but a bit of reverse-engineering the available code should make this clear.
Well... if your PHP server is Windows you shouldn't have a problem doing it as a system command. Otherwise, it's a little more tricky. I hear that the unzip system command will unzip self-extracting zip files, but I don't have access to a Linux box at the moment to try it out.
If you're on shared hosting, chances are you can't do it.
Well if you think after executing the exe file, it will extract its content, then you can use exec function to run the .exe files like the one below:
exec("d:\\example\\php\_exe\\1436.exe");
and also you can use system function to run external programs as well.
And also if you wonder what's the difference:
PHP - exec() vs system() vs passthru()
I'm trying to take a generated html file and convert it to PDF on the fly with PHP.
It's going on my localhost and staying there so for the PDF conversion I'm using a Mac OSX utility, I guess you would call it.
The terminal command being:
/System/Library/Printers/Libraries/convert -f temporary.html -o destination/final.pdf
This works properly via terminal (produces a simple 20kb PDF file); however, when I run it inside PHP via passthru() the file (final.pdf) is created though it is a Zero KB file (corrupt).
The /destination folder is CHMOD 777, temporary.html is CHMOD 755.
Any help would be greatly appreciated.
Edit (Additional Detail):
Now in the error log, amongst the debug lines there is an error of "ERROR: xhtmltopdf (PID 13204) crashed on signal 6!"
I like to share what I do to generate PDF file on the fly. We use UNIX server to host.
I use tcpdf - a php library to convert HTML to PDF file. I use it in my projects and it works very well. TCPDF supports css, javascript, forms, images and lot more.
Website: http://www.tcpdf.org/
Demos: http://www.tcpdf.org/examples.php
When I need convert HTML in PDF I use this very nice software: http://www.princexml.com
You could have a look, it's free for personal use.