Jump to content

youtube to mp3

mich991

Hey, 

 

could anyone explain me how does youtube to mp3 converter works? How can I create my own in PHP?

Link to comment
Share on other sites

Link to post
Share on other sites

Depends, a few Dowload the raw video then you ffpeg to convert it to an mp3.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

If it's a local application it is very easy, all you do just create a sound device output, open the web link in a hidden and run it with sound output changed to your custom output device. Then all you do is streamwrite to the disk as a certain format. Most likely raw at first then reopen and encode. NAudio can do all of this very easily. If i would have to make it a web thing then i wouldn't complicate my life an do the same app and just execute the process server side and all the web page has to do is check if the process is complete to present the user with the result.

Link to comment
Share on other sites

Link to post
Share on other sites

You can write the code to enumerate the video and audio streams available for that youtube url

then, you can download the audio stream that you want, most videos have the audio available in OPUS, AAC or mp3.

You then download the audio only and convert it to mp3 on your server using ffmpeg or other tools (ex opusdec to export to wav then lame encoder to compress to mp3)

Another option is to just use youtube-dl or other scripts in the background as a service on your server (if you have a vps or a dedicated server you can run programs in background)

 

Anyway... youtube to mp3 sites don't have much life and I don't see the point of them... youtube can serve you the audio directly in AAC or Opus, which are both formats much better than mp3. AAC can be converted without recompression to m4a audio files, opus files can be saved with the .opus extension and most audio players play them directly.

 

Also, keep in mind that all requests and downloads would be made from the IP of your server. If the website becomes popular and you make 2-3 downloads all the time or more, Youtube will simply block your IP. You could work around that by renting lots of vps or servers to have multiple ips but that's costly.

That's why browser extensions and software programs are more common and popular, because the download is made by the user, on user's computer... not initiated by your server.

 

I personally use JDownloader  and a Firefox extension YouTube Video and Audio Downloader (WebEx) – Get this Extension for ? Firefox (en-US)

For both of these the source code is available, so you can see how all the formats available are determined and how you can download selectively just video or just audio or both.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 1/19/2020 at 5:36 AM, mich991 said:

Hey, 

 

could anyone explain me how does youtube to mp3 converter works? How can I create my own in PHP?

The movie file contains two different streams: the video and audio stream. You extract the audio stream and wrap it around an audio file container or find a way to decode the audio stream from the format it's in into another one.

 

You could probably create it in PHP, but you'd have to study up on how the file is structured.

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, wasab said:

There are websites that do this for free. 

Or for the bulk downloads, programs.

Sometimes I do wonder why they seem to lose quite a bit of quality, some stuff genuinely sounds like garbage when downloaded off of YT but in playback is fine.

When the PC is acting up haunted,

who ya gonna call?
"Monotone voice" : A local computer store.

*Terrible joke I know*

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Sfekke said:

Or for the bulk downloads, programs.

Sometimes I do wonder why they seem to lose quite a bit of quality, some stuff genuinely sounds like garbage when downloaded off of YT but in playback is fine.

Yeah I know, I made a gui python app that does this. It's still on my github somewhere. I didn't bother to do mp3 conversion however, instead I just rename the file extension to mp3 and the operating system will then treat it like an audio file. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, wasab said:

Yeah I know, I made a gui python app that does this. It's still on my github somewhere. I didn't bother to do mp3 conversion however, instead I just rename the file extension to mp3 and the operating system will then treat it like an audio file. 

If you find the source, mind PM'ing it to me?

Genuinely didn't know about that filename extension trick yet!

I knew it worked for image files, but now I know what to do when I feel lazy and want my to play an MP4 without the video feed ;)

When the PC is acting up haunted,

who ya gonna call?
"Monotone voice" : A local computer store.

*Terrible joke I know*

 

Link to comment
Share on other sites

Link to post
Share on other sites

The file extension "trick" is no trick at all.  It's like renaming a jpg file to png... an image viewer that supports both image formats will not rely on file extension to decode it.

Your audio player probably supports opus, aac and mp3 ... so you're downloading an aac stream (m4a extension) and you're renaming to mp3 ... the player is smart enough to determine the container or uses windows direct x filters / splitters to figure out the audio part.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Sfekke said:

If you find the source, mind PM'ing it to me?

Genuinely didn't know about that filename extension trick yet!

I knew it worked for image files, but now I know what to do when I feel lazy and want my to play an MP4 without the video feed ;)

Sure, you want to see the source code? 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 11 months later...

There's no reason in 2021 to use websites for that.

 

There are lots of browser addons that let you download the video or audio tracks from Youtube, without converting them to mp3 (losing more quality) - you can save the original AAC or Opus (better quality than AAC most of the time) audio tracks.


There's also download applications like JDownloader : https://jdownloader.org/home/index

  - you just paste the youtube link in it and it will download the video and audio, thumbnail and even close captions / subtitles if you wish, and you can choose the quality (video format and resolution, audio format) or download just the video or just the audio.

You can also configure from options what video and audio formats to accept from youtube (ex. only choose to download H264 and VP9, don't download older formats)

 

Link to comment
Share on other sites

Link to post
Share on other sites

Guest
This topic is now closed to further replies.

×