Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

If one downloads videos from YouTube using youtube-dl, they get .mp4 files which are a ISO Media, MPEG v4 system, version 2.

Can these files be converted to audio-only, ideally with no quality loss?
The goal is to save space by throwing out the unneeded visual part.

share|improve this question

marked as duplicate by Ask, souravc, BuZZ-dEE, Bruno Pereira Feb 18 at 11:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
even after you convert it to mp3, I don't think the size will change see my question from yesterday askubuntu.com/questions/421777/… –  Fischer Feb 17 at 11:37
2  
Voting to keep this open, as the answers and question here are superior, and with a slightly different focus. –  belacqua Feb 17 at 23:25
    
Voting to close. There is already a question about How to extract audio from video files. –  Lucio Feb 18 at 23:31
add comment

5 Answers 5

up vote 7 down vote accepted

You can convert existing downloaded files using ffmpeg from the command-line

ffmpeg -i "input file.mp4" -acodec copy "output file.aac"

The "acodec copy" part is the bit that doesn't change the audio stream.

share|improve this answer
add comment

You can convert to audio only formats using youtube-dl itself, although it still downloads the video and then converts it.

To do this, use -x or --extract-audio to the command, for example:

youtube-dl -x http://www.youtube.com/watch?v=0iyeUcFKRv4&feature=c4-overview&list=UU1KPy3cAAj0i0RIFC_SzjMg
share|improve this answer
3  
+1d it, totally CLI ninja trick :D –  Kush Feb 17 at 7:29
add comment

enter image description here

YouTube Center is excellent user script, which works accross browsers, doesn't involve bloating your OS with ton of Youtube downloaders unless you're a strictly 320 kbps person for your audio files. Besides, you have Handbrake at your disposal which involves bit of a manual work but will do exactly what you want. :)

share|improve this answer
add comment

A command line alternative to download and immediately convert to a desired format is to send a file downloaded with cclive Install cclive to avconv with the cclive option --exec.

Examples:

  1. Download video, then extract the audio track to keep the original encoding:

    cclive -f best <videolink> --exec "avconv -i '%n' -acodec copy <name>.<extension>"
    
    • needs <extension> to be in the same format as the source audio format (e.g. aac)
  2. Download video, then convert audio to mp3 (or any other supported audio codec):

    cclive -f best <videolink> --exec "avconv -i '%n' -acodec lbmp3lame -b:a 256k <name>.mp3"
    
    • will download and convert to 256 kb/s mp3.
  3. Download video, copy audio, and delete video:

    cclive -f best <videolink> --exec "avconv -i '%n' -acodec copy <name>.aac" --exec "rm '%n'"
    
    • will delete the downloaded video after audio extraction.

We are quite versatile to convert to any audio codec avconv can encode, and this will also work on download sites other than YouTube.

Note for cclive >= 0.7.12 in Ubuntu >= 13.10:
Option -f was replaced by option -s. Give option -s best for best available encoding, -s <ID> for any other encoding as can be listed with cclive -S <URL>.

share|improve this answer
add comment

youtube-dl --help explains how:

  Post-processing Options:
    -x, --extract-audio              convert video files to audio-only
                                     files (requires ffmpeg or avconv and
                                     ffprobe or avprobe)
    --audio-format FORMAT            "best", "aac", "vorbis", "mp3", "m4a",
                                     "opus", or "wav"; best by default
    --audio-quality QUALITY          ffmpeg/avconv audio quality
                                     specification, insert a value between
                                     0 (better) and 9 (worse) for VBR or a
                                     specific bitrate like 128K (default 5)

Also look at my answer here which describes how to download just the audio instead of first downloading the video+audio and then discarding the video which is just wasteful.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.