Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rg3 opened this issue Nov 1, 2010 · 25 comments
Closed

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

rg3 opened this issue Nov 1, 2010 · 25 comments
Labels

Comments

@rg3
Copy link
Collaborator

rg3 commented 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

@rg3
Copy link
Collaborator Author

rg3 commented 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
Copy link
Collaborator Author

rg3 commented 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
Copy link
Collaborator Author

rg3 commented 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
Copy link
Collaborator Author

rg3 commented 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
Copy link
Collaborator Author

rg3 commented 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
Copy link
Collaborator Author

rg3 commented 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

@lx5415
Copy link

lx5415 commented 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

@rg3
Copy link
Collaborator Author

rg3 commented 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.

@lx5415
Copy link

lx5415 commented 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!

@chrisbra
Copy link

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

Christian

@dz0ny
Copy link
Contributor

dz0ny commented Feb 20, 2011

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

@ph03
Copy link

ph03 commented 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.

@dz0ny
Copy link
Contributor

dz0ny commented 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

@rg3
Copy link
Collaborator Author

rg3 commented 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.

@dz0ny
Copy link
Contributor

dz0ny commented 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)

@ph03
Copy link

ph03 commented 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
Copy link

ph03 commented 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.

@dz0ny
Copy link
Contributor

dz0ny commented 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/<title>.tmp && rm
" )

or implement command chaining -T mp4 --transcode_extra ... -T mkv --transcode_extra ...

@dz0ny
Copy link
Contributor

dz0ny commented 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

@rg3
Copy link
Collaborator Author

rg3 commented 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.

@dz0ny
Copy link
Contributor

dz0ny commented 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.

@ph03
Copy link

ph03 commented 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?

@dz0ny
Copy link
Contributor

dz0ny commented 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"

@rg3
Copy link
Collaborator Author

rg3 commented Feb 25, 2011

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

@rg3
Copy link
Collaborator Author

rg3 commented Feb 25, 2011

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

@nagas3000 nagas3000 mentioned this issue Aug 23, 2019
6 tasks
mrBliss referenced this issue in mrBliss/youtube-dl Jun 23, 2020
tsukumijima referenced this issue in tsukumijima/youtube-dl Sep 7, 2020
haimn referenced this issue in haimn/youtube-dl Nov 21, 2020
Merge changes from ytdl-org
tsukumijima referenced this issue in tsukumijima/youtube-dl Dec 2, 2020
pukkandan pushed a commit to pukkandan/youtube-dl-1 that referenced this issue Jan 10, 2021
Sometimes, video files will arrive with a timecode data stream
that causes `-map 0` to error out due to the stream not being
supported in the output container. These data streams generally do
not matter, so tell ffmpeg to ignore them rather than choking on
them.
pukkandan added a commit to pukkandan/youtube-dl-1 that referenced this issue Jan 10, 2021
closes ytdl-org#2, blackjack4494#291

Authored by jbruchon
CNugteren added a commit to CNugteren/youtube-dl that referenced this issue Jan 15, 2021
kobiburnley added a commit to kobiburnley/youtube-dl-1 that referenced this issue Jun 29, 2021
gaming-hacker pushed a commit to gaming-hacker/youtube-dl that referenced this issue Sep 18, 2021
jamilkarami added a commit to jamilkarami/youtube-dl that referenced this issue Feb 21, 2023
@dirkf dirkf mentioned this issue Jul 16, 2023
3 tasks
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants