2

How can we extract audio from video file (MPEG-4 format)?

What is convenient form of storing the extracted audio data for further analysis? (edit: In other words: is it better to use PCM format or something like WAV if I want to get audio sound level?)

From other questions about this topic I learned that ffmpeg is a right tool to do this.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
SteveS
  • 366
  • 1
  • 4
  • 15
  • http://stackoverflow.com/questions/9913032/ffmpeg-to-extract-audio-from-video check this ,maybe it will helpful – Vipin Nair Feb 13 '15 at 08:51
  • What have you tried so far? StackOverflow expects you to [try to solve your own problem first](//meta.stackoverflow.com/q/261592), as your attempts help us to better understand what you want. Please edit the question to show what you've tried, and show a specific roadblock you're running into with a [mcve]. For more information, please see [ask]. – Toby Speight Mar 02 '21 at 11:23

2 Answers2

7

Regarding your first question:

You can indeed do this with ffmpeg, but I can only give you the command line form. You might want to fiddle with the output format, but have a look at the man page at http://linux.die.net/man/1/ffmpeg, or the official ffmpeg (audio) documentation at https://www.ffmpeg.org/ffmpeg.html#Audio-Options

ffmpeg -i mpeg-4videofilename -vn -ac 2 -ar 44100 -ab 320k -f mp3 output.mp3

Explanation of the command line options:

  • -i input file
  • -vn no video
  • -ac audio channel
  • -ar audio sample rate
  • -ab audio bitrate
  • -f output format
sanderr
  • 94
  • 5
  • The problem is that I want to avoid saving audio file as mp3 (or any other format) and opening it again in order to do some analysis. (Sound level check etc...) I am afraid that considering the amount of audio I need to analyze this could potentially lead to a poor performance. – SteveS Feb 13 '15 at 09:59
  • 1
    You can also copy the audio stream, with `-acodec copy`, but then you would need to know in which format your audio is. – sanderr Feb 13 '15 at 10:13
4

You can use the following command:

ffmpeg -i input.mp4 -vn -acodec pcm_s16le -ac 2 -ar 44100 out.wav

-vn: no video

-acodec: audio codec selection.

pcm_sl6le: 2 bytes samples in little endian format

-ac: number of audio channels

-ar: audio sample rate

out.wav output wav file

sourabh gupta
  • 61
  • 1
  • 9
  • delete the space between the first pipe (- i) and change it to (-i) `ffmpeg -i input.mp4 -vn -acodec pcm_s16le -ac 2 -ar 44100 out.wav` – Joaquim Jul 17 '22 at 15:46
  • adding -vn to the conversion is much faster if using other formats as output "mp3" or "m4a". – DanielZanchi Sep 08 '22 at 10:25