new option to extract as mp3? is this possible? #2

Closed
opened 2026-02-20 20:59:07 -05:00 by deekerman · 25 comments
Owner

Originally created by @rg3 on GitHub (Nov 1, 2010).

Was: http://bitbucket.org/rg3/youtube-dl/issue/83/

Hi there thanks for the program!

is it possible to have an option to extract the youtube video as mp3s?

I am using a mac btw and i love ur program on my terminall

Originally created by @rg3 on GitHub (Nov 1, 2010). Was: http://bitbucket.org/rg3/youtube-dl/issue/83/ Hi there thanks for the program! is it possible to have an option to extract the youtube video as mp3s? I am using a mac btw and i love ur program on my terminall
deekerman 2026-02-20 20:59:07 -05:00
  • closed this issue
  • added the
    request
    label
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

Originally by "obeythepenguin":

youtube-dl just downloads the raw video file; there's no conversion. However, there are some front-ends that can do conversion. I'm developing one called youtube2mp3 ( http://youtube2mp3.sourceforge.net/ ), although I don't use a Mac so I don't know how well it works on OS X. There are, of course, plenty of others.

@rg3 commented on GitHub (Nov 1, 2010): Originally by "obeythepenguin": youtube-dl just downloads the raw video file; there's no conversion. However, there are some front-ends that can do conversion. I'm developing one called youtube2mp3 ( http://youtube2mp3.sourceforge.net/ ), although I don't use a Mac so I don't know how well it works on OS X. There are, of course, plenty of others.
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

The internal code in youtube-dl allows for postprocessing, so anybody can implement a postprocessor to extract the audio from the video file using an external tool (like obeythepenguin said, youtube-dl just downloads the raw video file without looking at its internal format). I'd gladly merge that code into the program if someone is willing to maintain that part. I haven't implemented any postprocessing yet because I don't postprocess any video.

I'm leaving the issue open just in case someone wants me to merge it.

@rg3 commented on GitHub (Nov 1, 2010): The internal code in youtube-dl allows for postprocessing, so anybody can implement a postprocessor to extract the audio from the video file using an external tool (like obeythepenguin said, youtube-dl just downloads the raw video file without looking at its internal format). I'd gladly merge that code into the program if someone is willing to maintain that part. I haven't implemented any postprocessing yet because I don't postprocess any video. I'm leaving the issue open just in case someone wants me to merge it.
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

Originally by "rmunn":

In the meantime, one easy way to extract the audio from a downloaded video file is to use Audacity (http://audacity.sourceforge.net/). Open the .mp4 in Audacity and it will automatically extract the audio for you -- then just do File -> Export and save it as an .mp3. (Remember to download the LAME DLL for Audacity so it can save MP3's, of course (see http://audacity.sourceforge.net/help/faq?s=install&item=lame-mp3 for details).

@rg3 commented on GitHub (Nov 1, 2010): Originally by "rmunn": In the meantime, one easy way to extract the audio from a downloaded video file is to use Audacity (http://audacity.sourceforge.net/). Open the .mp4 in Audacity and it will automatically extract the audio for you -- then just do File -> Export and save it as an .mp3. (Remember to download the LAME DLL for Audacity so it can save MP3's, of course (see http://audacity.sourceforge.net/help/faq?s=install&item=lame-mp3 for details).
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

Originally by anonymous:

ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv famous_last_word.mp3

via http://www.catonmat.net/blog/how-to-extract-audio-tracks-from-youtube-videos/

@rg3 commented on GitHub (Nov 1, 2010): Originally by anonymous: ffmpeg.exe -i My_Chemical_Romance_-_Famous_Last_Words.flv famous_last_word.mp3 via http://www.catonmat.net/blog/how-to-extract-audio-tracks-from-youtube-videos/
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

Originally by anonymous:

And add -ab parameter to ffmpeg to set the audio bitrate (default is 64k).

ffmpeg -ab 192k -i <input.file> <output.file>

@rg3 commented on GitHub (Nov 1, 2010): Originally by anonymous: And add -ab parameter to ffmpeg to set the audio bitrate (default is 64k). ffmpeg -ab 192k -i <input.file> <output.file>
Author
Owner

@rg3 commented on GitHub (Nov 1, 2010):

Originally by anonymous:

Or with mplayer:

$ mplayer -dumpaudio -dumpfile out.mp3

Maybe to add a generic postprocessor that calls external programs like mplayer, ffmpeg or what ever. The command should also accept "variables" similar to the litteral titel formating rules, e.g

$ youtube-dl http://www.youtube.com/watch?v=foobar -i "mplayer -dumpaudio %(filename)s -dumpfile %(title)s.mp3"

Maybe it is just the work of adding some lines to the program ...

Alex

@rg3 commented on GitHub (Nov 1, 2010): Originally by anonymous: Or with mplayer: $ mplayer -dumpaudio <video-file> -dumpfile out.mp3 Maybe to add a generic postprocessor that calls external programs like mplayer, ffmpeg or what ever. The command should also accept "variables" similar to the litteral titel formating rules, e.g $ youtube-dl http://www.youtube.com/watch?v=foobar -i "mplayer -dumpaudio %(filename)s -dumpfile %(title)s.mp3" Maybe it is just the work of adding some lines to the program ... Alex
Author
Owner

@lx5415 commented on GitHub (Dec 19, 2010):

I've written a program (PC) to extract an mp3 from the video file. If anyone is interested email me lx5415@gmail.com

@lx5415 commented on GitHub (Dec 19, 2010): I've written a program (PC) to extract an mp3 from the video file. If anyone is interested email me lx5415@gmail.com
Author
Owner

@rg3 commented on GitHub (Dec 19, 2010):

The issue tracker is no place for promoting your own software. mplayer can trivially extract the audio from the video file, and it works on many platforms. The issue at hand here is if someone is willing to code a postprocessor that uses it, or other software, to extract the MP3 and integrate it with youtube-dl.

@rg3 commented on GitHub (Dec 19, 2010): The issue tracker is no place for promoting your own software. mplayer can trivially extract the audio from the video file, and it works on many platforms. The issue at hand here is if someone is willing to code a postprocessor that uses it, or other software, to extract the MP3 and integrate it with youtube-dl.
Author
Owner

@lx5415 commented on GitHub (Dec 19, 2010):

i forgot to mention that it is free and open and it uses youtube_dl. I am in no way trying to sell anything. I am just trying to contribute to the open source community. This may or may not be warranted in this forum. Sorry!

@lx5415 commented on GitHub (Dec 19, 2010): i forgot to mention that it is free and open and it uses youtube_dl. I am in no way trying to sell anything. I am just trying to contribute to the open source community. This may or may not be warranted in this forum. Sorry!
Author
Owner

@chrisbra commented on GitHub (Feb 16, 2011):

https://github.com/chrisbra/youtube2audio uses youtube-dl or clive to extract videos from youtube and convert it to mp3 or ogg.

Christian

@chrisbra commented on GitHub (Feb 16, 2011): https://github.com/chrisbra/youtube2audio uses youtube-dl or clive to extract videos from youtube and convert it to mp3 or ogg. Christian
Author
Owner

@dz0ny commented on GitHub (Feb 20, 2011):

Hi simple implementation can be found at https://github.com/dz0ny/YoutubeDl-Server

@dz0ny commented on GitHub (Feb 20, 2011): Hi simple implementation can be found at https://github.com/dz0ny/YoutubeDl-Server
Author
Owner

@ph03 commented on GitHub (Feb 21, 2011):

I'd loved to see an option that rg3 suggested that calls a given program with the downloaded file after succesful download. I automatically download some videos every day but want to reencode them at night for my Android phone with optimal settings and this would be very easy using such an option. I think i'll implement it by myself and let you know if it works.

@ph03 commented on GitHub (Feb 21, 2011): I'd loved to see an option that rg3 suggested that calls a given program with the downloaded file after succesful download. I automatically download some videos every day but want to reencode them at night for my Android phone with optimal settings and this would be very easy using such an option. I think i'll implement it by myself and let you know if it works.
Author
Owner

@dz0ny commented on GitHub (Feb 21, 2011):

Implement class
class ToFFmpegMP4(youtubedl.PostProcessor):
def run(self, inf):
command = "/usr/bin/ffmpeg -i '%s' -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k '%s' && rm '%s' &" % (inf["filepath"] ,VideoPath + "/" + inf["title"] + ".mp4", inf["filepath"])
os.system(command) ## WARNING shell injection
return inf

then add
ffmpeg = ToFFmpegMP4()
fd.add_post_processor(ffmpeg)

again see my project, for more complete example https://github.com/dz0ny/YoutubeDl-Server/blob/master/youtubedl-server.py

@dz0ny commented on GitHub (Feb 21, 2011): Implement class class ToFFmpegMP4(youtubedl.PostProcessor): def run(self, inf): command = "/usr/bin/ffmpeg -i '%s' -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k '%s' && rm '%s' &" % (inf["filepath"] ,VideoPath + "/" + inf["title"] + ".mp4", inf["filepath"]) os.system(command) ## WARNING shell injection return inf then add ffmpeg = ToFFmpegMP4() fd.add_post_processor(ffmpeg) again see my project, for more complete example https://github.com/dz0ny/YoutubeDl-Server/blob/master/youtubedl-server.py
Author
Owner

@rg3 commented on GitHub (Feb 21, 2011):

dz0ny,

Why don't you clean that part of the code a little bit, avoid the command injection problem and submit a postprocessor to be integrated with the program, activated by a command line switch?

That way every youtube-dl user would benefit from the postprocessor.

@rg3 commented on GitHub (Feb 21, 2011): dz0ny, Why don't you clean that part of the code a little bit, avoid the command injection problem and submit a postprocessor to be integrated with the program, activated by a command line switch? That way every youtube-dl user would benefit from the postprocessor.
Author
Owner

@dz0ny commented on GitHub (Feb 21, 2011):

@rg3 would something like this, be sufficient?

Transcoding Options (uses ffmpeg):
-T FILE_TYPE, --transcode_to=FILE_TYPE
                    transcode to specific video or audio format (example:
                    mp3 mp4 mov mkv)
--transcode_extra=ARGS
                    pass additional parameters to ffmpeg (example: -vcodec
                    libx264 -vpre slow -vpre ipod640 -b 2048k -acodec
                    libfaac -ab 96k)
@dz0ny commented on GitHub (Feb 21, 2011): @rg3 would something like this, be sufficient? ``` Transcoding Options (uses ffmpeg): -T FILE_TYPE, --transcode_to=FILE_TYPE transcode to specific video or audio format (example: mp3 mp4 mov mkv) --transcode_extra=ARGS pass additional parameters to ffmpeg (example: -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k) ```
Author
Owner

@ph03 commented on GitHub (Feb 22, 2011):

@dz0ny I would rather also like to be able to call a costum command with the downloaded file like

-i COMMAND, --excecute=COMMAND
excecutes the command given by the string COMMAND by
replacing '%f' with the downloaded file name.

I think this would be more flexible as everyone can call his own commands (e.g., not only for transcoding but to schedule other events on downloaded files, e.g., movement etc). I need it because I would like to be able to do two pass encodings which would not be possible with your single ffmpeg transcode command. But the -T option should still be usefull in many situations.

@ph03 commented on GitHub (Feb 22, 2011): @dz0ny I would rather also like to be able to call a costum command with the downloaded file like -i COMMAND, --excecute=COMMAND excecutes the command given by the string COMMAND by replacing '%f' with the downloaded file name. I think this would be more flexible as everyone can call his own commands (e.g., not only for transcoding but to schedule other events on downloaded files, e.g., movement etc). I need it because I would like to be able to do two pass encodings which would not be possible with your single ffmpeg transcode command. But the -T option should still be usefull in many situations.
Author
Owner

@ph03 commented on GitHub (Feb 22, 2011):

B.t.w. yesterday I implemented my transcoder event as a postprocessor sucessfully in youtube-dl. However, I realized that the postprocessors are also called on already existing files due to the success state "True":

self.report_file_already_downloaded(filename)
return True

and for my application it made more sense to mark already downloaded files as not successful to not make the transcoder work on that file again.

@ph03 commented on GitHub (Feb 22, 2011): B.t.w. yesterday I implemented my transcoder event as a postprocessor sucessfully in youtube-dl. However, I realized that the postprocessors are also called on already existing files due to the success state "True": self.report_file_already_downloaded(filename) return True and for my application it made more sense to mark already downloaded files as not successful to not make the transcoder work on that file again.
Author
Owner

@dz0ny commented on GitHub (Feb 22, 2011):

Hi just quick thought how about

Post download action:
-C COMMAND, --command=COMMAND
command to run after file has been downloaded
(example: "sh -c cp /tmp/

@dz0ny commented on GitHub (Feb 22, 2011): Hi just quick thought how about Post download action: -C COMMAND, --command=COMMAND command to run after file has been downloaded (example: "sh -c cp <filepath> /tmp/<title>.tmp && rm <filepath>" ) or implement command chaining -T mp4 --transcode_extra ... -T mkv --transcode_extra ...
Author
Owner

@dz0ny commented on GitHub (Feb 22, 2011):

Check https://github.com/dz0ny/youtube-dl

youtube-dl http://www.youtube.com/watch?v=BRHRssf3B6o -T mp4 -C "rm <filepath>"
[youtube] Setting language
[youtube] BRHRssf3B6o: Downloading video webpage
[youtube] BRHRssf3B6o: Downloading video info webpage
[youtube] BRHRssf3B6o: Extracting video information
[download] Destination: BRHRssf3B6o.flv
[download] 100.0% of 966.33k at  103.70k/s ETA 00:00 
[transcode] Started transcoding of BRHRssf3B6o.flv to BRHRssf3B6o.mp4
[transcode] Completed transcoding of BRHRssf3B6o.flv to BRHRssf3B6o.mp4
[PostProcessor] Started command rm BRHRssf3B6o.flv
[PostProcessor] Finnished command rm BRHRssf3B6o.flv
@dz0ny commented on GitHub (Feb 22, 2011): Check https://github.com/dz0ny/youtube-dl ``` youtube-dl http://www.youtube.com/watch?v=BRHRssf3B6o -T mp4 -C "rm <filepath>" [youtube] Setting language [youtube] BRHRssf3B6o: Downloading video webpage [youtube] BRHRssf3B6o: Downloading video info webpage [youtube] BRHRssf3B6o: Extracting video information [download] Destination: BRHRssf3B6o.flv [download] 100.0% of 966.33k at 103.70k/s ETA 00:00 [transcode] Started transcoding of BRHRssf3B6o.flv to BRHRssf3B6o.mp4 [transcode] Completed transcoding of BRHRssf3B6o.flv to BRHRssf3B6o.mp4 [PostProcessor] Started command rm BRHRssf3B6o.flv [PostProcessor] Finnished command rm BRHRssf3B6o.flv ```
Author
Owner

@rg3 commented on GitHub (Feb 22, 2011):

Custom commands can be a good thing but they can't replace extracting the audio from the video file in the form of a simple option that would call mencoder or ffmpeg to losslessly dump the audio stream to a file, then delete the original video, all by itself.

Dumping the audio stream could have an extra option to choose if you want to preserve the original format, or force it to be in MP3 or AAC, losslessly when possible. For example, I can run the following command in the example above:

$ ffmpeg -i BRHRssf3B6o.flv
...
    Stream # 0.1: Audio: aac, 22050 Hz, mono, s16, 47 kb/s

Knowing it's in AAC lets me run:

$ ffmpeg -i BRHRssf3B6o.flv -vn -acodec copy test.m4a

And get:

$ file test.m4a 
test.m4a: ISO Media, MPEG v4 system, iTunes AAC-LC

Which is the original audio in MPEG v4 container, playable by many portable devices. I think people interested in this bug would like such a feature to do all this work automatically for them.

@rg3 commented on GitHub (Feb 22, 2011): Custom commands can be a good thing but they can't replace extracting the audio from the video file in the form of a simple option that would call mencoder or ffmpeg to losslessly dump the audio stream to a file, then delete the original video, all by itself. Dumping the audio stream could have an extra option to choose if you want to preserve the original format, or force it to be in MP3 or AAC, losslessly when possible. For example, I can run the following command in the example above: ``` $ ffmpeg -i BRHRssf3B6o.flv ... Stream # 0.1: Audio: aac, 22050 Hz, mono, s16, 47 kb/s ``` Knowing it's in AAC lets me run: ``` $ ffmpeg -i BRHRssf3B6o.flv -vn -acodec copy test.m4a ``` And get: ``` $ file test.m4a test.m4a: ISO Media, MPEG v4 system, iTunes AAC-LC ``` Which is the original audio in MPEG v4 container, playable by many portable devices. I think people interested in this bug would like such a feature to do all this work automatically for them.
Author
Owner

@dz0ny commented on GitHub (Feb 22, 2011):

I think such feature as you describe(everything done automatically) is for people who use GUI applications, those who use CLI tools prefer more options and more control over the process. BUT most transcoders have presents for devices or user-cases, have a look for example Handbrake https://trac.handbrake.fr/wiki/BuiltInPresets.

I would propose something like -T ipad --preserve-original --strip-video, maybe we could use handbrake for this and not ffmpeg? How is support for ffmeg on OSX?

Is Handbrake better choice for this, because is multiplatform and has solid codebase (ffmpeg is in some distributions stripped of proprietary codecs)?

For other user cases "Custom commands" are must for such tool, as youtube-dl is.

@dz0ny commented on GitHub (Feb 22, 2011): I think such feature as you describe(everything done automatically) is for people who use GUI applications, those who use CLI tools prefer more options and more control over the process. BUT most transcoders have presents for devices or user-cases, have a look for example Handbrake https://trac.handbrake.fr/wiki/BuiltInPresets. I would propose something like -T ipad --preserve-original --strip-video, maybe we could use handbrake for this and not ffmpeg? How is support for ffmeg on OSX? Is Handbrake better choice for this, because is multiplatform and has solid codebase (ffmpeg is in some distributions stripped of proprietary codecs)? For other user cases "Custom commands" are must for such tool, as youtube-dl is.
Author
Owner

@ph03 commented on GitHub (Feb 23, 2011):

@dz0ny

Your -C COMMAND, --command=COMMAND option works great, thanks, just what I needed. Now I check for an already downloaded file by myself in the called script to not recode an already coded file once again.
Is it possible that this commit could be importet to this original youtoube-dl branch or will they keep diverging?

@ph03 commented on GitHub (Feb 23, 2011): @dz0ny Your -C COMMAND, --command=COMMAND option works great, thanks, just what I needed. Now I check for an already downloaded file by myself in the called script to not recode an already coded file once again. Is it possible that this commit could be importet to this original youtoube-dl branch or will they keep diverging?
Author
Owner

@dz0ny commented on GitHub (Feb 24, 2011):

Just to note -C has following replaceble variables

upload_date "Jan 7 2011"
description "No description available."
format "35"
url "http://v12.lscache6.c.youtube.com/v..."
title "Barron Falls Queensland"
player_url "http://s.ytimg.com/yt/swfbin/watch_as3-vflO2K4B9.swf"
filepath "Tz9ihXnS9s4.flv"
thumbnail "http://i1.ytimg.com/vi/Tz9ihXnS9s4/default.jpg"
ext "flv"
stitle "Barron_Falls_Queensland"
uploader "newrealm06"
id "Tz9ihXnS9s4"
@dz0ny commented on GitHub (Feb 24, 2011): Just to note -C has following replaceble variables ``` upload_date "Jan 7 2011" description "No description available." format "35" url "http://v12.lscache6.c.youtube.com/v..." title "Barron Falls Queensland" player_url "http://s.ytimg.com/yt/swfbin/watch_as3-vflO2K4B9.swf" filepath "Tz9ihXnS9s4.flv" thumbnail "http://i1.ytimg.com/vi/Tz9ihXnS9s4/default.jpg" ext "flv" stitle "Barron_Falls_Queensland" uploader "newrealm06" id "Tz9ihXnS9s4" ```
Author
Owner

@rg3 commented on GitHub (Feb 25, 2011):

Those wanting so much "control over the process" can script something outside youtube-dl.

@rg3 commented on GitHub (Feb 25, 2011): Those wanting so much "control over the process" can script something outside youtube-dl.
Author
Owner

@rg3 commented on GitHub (Feb 25, 2011):

Add an audio extracting PostProcessor using ffmpeg (closed by 3072fab115)

@rg3 commented on GitHub (Feb 25, 2011): Add an audio extracting PostProcessor using ffmpeg (closed by 3072fab115b3c89322edc906a8f88f997e46dedd)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl#2
No description provided.