Converting mp3 to ogg in php in joomla

Asked

Viewed 108 times

6

I am trying to convert a mp3 file to ogg using ffmpeg.exe the problem is that Joomla won’t let me run an external file even in the same directory.

<?php exec('C:\\path\\to\\ffmpeg.exe -y -i file.mp3 -acodec libvorbis file.ogg'); ?>

This code does not return any error, it just does not execute. Is there any other way to run ffmpeg.exe within Joomla? Or there is a way to direct convert via php that Joomla accepts?

2 answers

1

I managed to run and convert the file, but only in the same directory where the ffmpeg.exe Yeah, then I had to move him. Before making the call exec activated the safe_mode and added the directory where I am working and worked.

ini_set('safe_mode',true);
ini_set('safe_mode_exec_dir','C:\\path\\to\\');
exec('C:\\path\\to\\ffmpeg.exe -y -i file.mp3 -acodec libvorbis file.ogg');

I don’t know if this is the best way, but so it worked. I moved the file using the Jfile::move().

1

The safe_mode this in disuse in PHP5.3 and was removed in PHP5.4

The most correct way is to use the function exec with $output and pass the arguments with escapeshellcmd (in the case of Windows), if it is linux/like-Unix use the command escapeshellarg

Example:

<?php
$comando = 'C:\\path\\to\\ffmpeg.exe';
$argumentos = escapeshellcmd('-y -i file.mp3 -acodec libvorbis file.ogg');

exec($comando . ' ' . $argumentos, $output);

echo '<pre>';
print_r($output);
echo '</pre>';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.