Automatically Trimming an Mp3 in PHP

Automatically trimming an mp3 in PHP

You could try the MP3 Class on PHPClasses. It features the following example:

require_once './class.mp3.php';
$mp3 = new mp3;
$mp3->cut_mp3('input.mp3', 'output.mp3', 0, -1, 'frame', false);

In this case, the 'frame' can be substituted with 'second' to base the cut on a time-frame.

ffmpeg being inprecise when trimming mp3 files

You can't trim MP3 (nor most lossy codec output) with that level of precision. An MP3 frame or so of padding is added during encoding. (See also: https://wiki.hydrogenaud.io/index.php?title=Gapless, and all the hacks required to make this work.)

If you need precision timing, use something uncompressed like PCM in WAV, or a lossless compression like FLAC.

Autoplay sound mp3 each one minute

Simply you can merge both sound with your timing and implemented just like this:

<audio controls="controls" onloadeddata="audioSoundFunction()">
<source src="horse.mp3" type="audio/mp3" />
</audio>

Javascript:

function audioSoundFunction() {
var audioSound = this;
setTimeout(function() {
audioSound.play();
}, 10000)
}

PHP header returning with spaces when using variables?

You should url encode and trim extra whitespace before placing in the header.

$name = rawurlencode(trim($name));
header("Content-Disposition: attachment; filename='{$name}'");

Final Solution

$name = $extract['original_name'];
$name2 = urlencode(trim($name));
$name3 = str_replace("+", " ", $name2);
$quote = '"';
header("Content-Disposition: attachment; filename=$quote{$name3}$quote");

I am pretty sure you could clean this up:

$name = $extract['original_name'];
$name = urlencode(trim($name));
$name = str_replace("+", " ", $name);
header("Content-Disposition: attachment; filename=\"{$name}\"");

And, if the urlencode does not seem to make a difference, I am pretty certain you can just do this:

$name = $extract['original_name'];
$name = trim($name);

header("Content-Disposition: attachment; filename=\"{$name}\"");


Related Topics



Leave a reply



Submit