How to extract audio from video with one command

Many times it has happened to me that I have X video clip whose song is attractive to me, however I do not have the audio file of that song (.mp3, .ogg, etc.). The solution is simple: «download the .mp3 or CD from the internet), but this in addition to being something illegal, ... is in my opinion a bad waste of bandwidth, because if I already have the audio in the video, why what not to get the audio out of the video? 🙂

To do this we have several alternatives, in this article I will show you how to do it with just 1 command 😀

First we must have installed mplayer, if you don't have it installed you must install it 😉

En Debian, Ubuntu, SolusOS, Mint, etc ... would be:

sudo apt-get install mplayer

En ArchLinux y Chakra:

pacman -S mplayer

And well, the idea is understood right? 😀

Now suppose the video file is: basshunter_saturday.mkv

We open a terminal in the folder where the file is, and we put:

mplayer -vo null -dumpaudio -dumpfile archivo.mp3 basshunter_saturday.mkv

That is:

mplayer -vo null -dumpaudio -dumpfile archivo-de-audio-final.mp3 el-video.loquesea

In my case a file called file.mp3 right next to the video:

What is quite simple? 😀

It has personally helped me many times.

Now… is there no way to do this graphically using an application? … Yes, of course, but that's another post 😀

regards


28 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   EAT WITH said

    This is exactly the only thing that RealPlayer Converter was missing!
    Thank you, thank you, thank you, I use it mostly to extract audio from YouTube videos. For evil purposes.

    1.    KZKG ^ Gaara said

      A pleasure to help 😀

      1.    hexborg said

        That page is cool. I have to try it. Until now I used ffmpeg. I love seeing how many different ways there are to do each thing. 🙂

  2.   giskard said

    Using a graphical application I always use Avidemux. It is a workhorse.

    1.    VaryHeavy said

      With SoundKonverter (Qt) and SoundConverter (GTK) you can too.

  3.   nosferatuxx said

    Interesting, although in my case I use firefox addons for it, or the mobile media converter.

    1.    KZKG ^ Gaara said

      I actually use MMC for many things https://blog.desdelinux.net/mobile-media-converter-excelente-aplicacion-para-convertir-videos/
      but ... I am lazy to have to open it for something so simple, I open a terminal right there in the file browser, and that's it 😀

  4.   Leo said

    I kill the end of the post, ha.
    Very good, I did not know that you could do that with mplayer, I always use ffmpeg.
    Thanks for the information.

  5.   City said

    Thanks, I did not know that function in Mplayer as well….

    1.    KZKG ^ Gaara said

      A pleasure to help ... and, mplayer is a genius, you can do everything with him haha.

  6.   Daniel said

    It did not work for me with a couple of flv videos = (

    1.    sieg84 said

      try with: ffmpeg -i tuvideo.mp4 -vn -acodec copy audio.m4a
      You can use m4a or aac as audio output, videos in flv (in your case) or mp4 normally use the h264 codec for video and the aac codec for audio (those of youtube).

      I think I am missing as a note in the article, that you can only copy or "extract" the audio in the format it is, if you want in the crappy .mp3, it would be to copy / extract the audio and then convert.

      1.    sieg84 said

        I missed adding, if you want to know the codec that uses the video / audio (speaking of the terminal) you can do it with ffprobe (part of ffmpeg)

        ffprobe yourvideo.mp4

        After it shows you what codec it uses for the audio, you apply the command and output of the corresponding audio.
        it can also be done with mediainfo (tugestordepaquentes install mediainfo)
        or from VLC with Ctrl + J or Menpu Tools - Codec information

        1.    KZKG ^ Gaara said

          Excellent your comments 😀

    2.    KZKG ^ Gaara said

      What error did it give you? … I have tried it with MKV, RMVB and other rare formats and it worked for me 🙁
      Open those videos with VLC, and see if it indicates that the index of the video is corrupt.

  7.   Max Steel said

    Or easier:

    ffmpeg -i video-file audio.mp3 (or whatever audio format you want)

    1.    KZKG ^ Gaara said

      I had not tried this one, I'll keep an eye on it lol
      Thank you

    2.    Hugo said

      Good tip, in fact I was seeing that with certain parameters the track can be extracted very, very quickly (I already did the test).

      For example if we say ffmpeg -i file-video.flv

      The streams that the video contains should be output as a result, and if then we notice that the audio is encoded in mp3, for example, we could do something like this:

      ffmpeg -i archivo-video.flv -vn -sn -acodec copy audio.mp3

      In this way we are telling it not to process the video streams and subtitles, and to copy the audio stream as is, without recoding so that quality is not lost.

      How flexible is free software, right?

  8.   tahed said

    Dumpfile only dumps the audio of the video in the format it was encoded in.

    You can check the true audio codec with ffmpeg as follows:
    ffmpeg -i multimedia-file.ext 2> & 1 | grep -E '(Duration) | (Stream)'

    If the audio codec is mp3 if you can convert it to mp3, let's see what the command would look like

    ffmpeg -i basshunter_saturday.mkv 2> & 1 | grep -E mp3 && mplayer -vo null -dumpaudio -dumpfile file.mp3 basshunter_saturday.mkv
    Note: it seems to me that the video formats that use the mp3 codec are the divx (.avi).

    If the video codec is not mp3 we will use these methods:

    1- With lame (only if it supports the codec):
    lame -r "basshunter_saturday.mkv" "output-file.mp3"

    2- Extracting the video codec to wav and encoding:
    mplayer -vo null -vc dump -ao pcm: file = »file.wav» video.ext && lame -r «file.wav» «file.mp3» && rm «file.wav»

  9.   elav said

    A tutoring with Kdenlive and Avidemux is coming 😛

  10.   Sergio said

    It does not work, it does not extract aac type file, a file (data) appears that it has to be converted later.

  11.   luchio said

    When you fall and fall to the same place to lift a tip, a tip, a help, a fishing rod, it is that on the other side there is a great community work, impossible not to drop a simple thank you pin.
    Thank you desdelinux!

  12.   Angel said

    I did not try it because I found another option with VLC but my respects kzkg gara, you have very good contributions (Y) one day I will be Hokage XD lol but really my respects

  13.   Marc gurt said

    Thank you very much mate!

    With cclive (http://linuxgnublog.org/descargar-videos-de-youtube-en-gnulinux/) to download videos from Youtube and the solution that you propose I have the perfect tools to download and extract the sound.

    A abrazo.

  14.   Emanuel said

    To extract Mp3 from Youtube this website: http://www.youtomp3.net/

    This great, totally free with a single click.

    http://www.youtomp3.net/

  15.   GENDA said

    Is there a command that gives me a kind of demultiplexer? in other words, it extracts everything without converting anything. MP4 OGV H.264, MP2 AAC AC3 MP3, SRT SUB,

  16.   mee43 said

    with mp4 it takes longer? mkv there nomas extracts the audio

    I had to use another online method to convert mp4 to ac3 https://convertio.co/es/mp4-ac3/