Jump to content

Need suggestions for trimming a .mp3


BinaryBird

Recommended Posts

Hello, me a few friends of mine are developing a php-based music store for a client. The client specifically wanted a preview option where by users could listen to the first 30 seconds of a song. All the songs are .mp3's

 

Could any one tell me, if it is possible to trim down a mp3's duration to the first 30 seconds using php? or suggest any player that will limit the clip duration to 30 seconds? We are currently using a xml based flash player to play the songs on the site.

 

There are quite a high number of songs, so creating a short 30 seconds clips would not be ideal.

 

And please forgive me if i have posted the question in the wrong section.

 

Kindly help me out. Thanks in advance.

Link to comment
Share on other sites

If you've got ffmpeg on your server, you can use it to do it. Something like this should do the trick:

 

ffmpeg -t 30 -i original.mp3 -acodec copy trimmed.mp3

 

The server has Cent OS 5 running.

 

The option you are suggesting is to trim the song on the fly?

Link to comment
Share on other sites

I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea.

 

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

redirTime = "26000";

redirURL = "http://your_domain_and_file.htm";

function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }

//  End -->

</script>

Link to comment
Share on other sites

Thanks for the suggestion. Is it not possible to limit the duration of a mp3 using php?

 

The main problem is that there are more than 100,000 songs. So creating separate clips for all those songs will take up space and if required to do on the fly, it might take up server resources. So thinking if there is a way to extract 30 seconds from a song or limit the duration to 30 sec using php.

 

In any case thanks for your suggestion.

Link to comment
Share on other sites

I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea.

 

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

redirTime = "26000";

redirURL = "http://your_domain_and_file.htm";

function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }

//  End -->

</script>

 

Thanks for the idea paddy. Will try it out.

Link to comment
Share on other sites

Thanks for the suggestion. Is it not possible to limit the duration of a mp3 using php?

 

The main problem is that there are more than 100,000 songs. So creating separate clips for all those songs will take up space and if required to do on the fly, it might take up server resources. So thinking if there is a way to extract 30 seconds from a song or limit the duration to 30 sec using php.

 

In any case thanks for your suggestion.

 

Doing it on-the-fly takes no time. I just tried on a random MP3 file and it took 0.04 seconds completing. If you have a lot of users and are worried about spending a lot of resources, pre-generating them and storing them on the disk would be a good idea.

 

You could implement a trimming function using PHP, but it would be no more efficient than using ffmpeg. Actually, it's unlikely it would be more efficient.

 

I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea.

 

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

redirTime = "26000";

redirURL = "http://your_domain_and_file.htm";

function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }

//  End -->

</script>

 

Thanks for the idea paddy. Will try it out.

 

That won't work unless you're willing to let anyone download the entire file. What's preventing them from disabling Javascript or just checking out your HTML code?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.