Linux: "video to mp3"

From Luky-Wiki
Revision as of 18:47, 13 February 2016 by Lukas Dzunko (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Problem: I have video file with concert or music show and I would like to play it in car or on phone.

In both cases it is enough to have audio track and it is necessary to have correct format. My car radio can play only mp3 files (and of course regular cdda).

Here are steps how to get sound track from video and store it as mp3. It is possible to do it directly via ffmpeg but I prefer lame mp3 creator. Depending on source I normalize tracks before converting to mp3. This is also recommend only on lossless file formats.

Step 1 - extract audio from video file

ffmpeg is powerful video converter. With correct option it can "dump" audio track or directly encode it to mp3. I am using following way to extract audio:

video with stereo audio track

ffmpeg -i input.mkv -vn output.wav

-i == input file, -vn == no video processing

video with DTS audio track (5.1 or all other X.Y combinations)

ffmpeg -i input.mkv -vn -ac 2 output.wav

-ac == number of output channels

video with more audio tracks

If source file contain more that one audio track (I don't mean channels). Then it is necessary to specify which one will be saved to output file. See man page and option -map (for example: -map 0:a:0) or AudioChannelManipulation. If you are unsure what is content of file then simply run:

ffmpeg -i input.mkv

It will show technical details and ten quit due to missing output file.

Step 2 - normalize tracks

I am using normalize tool to correct volume levels. Reason is simple. Different produces use different volume configuration or it was simple precaution for clipping in club recording.

unrelated files

For longer recordings it is better to normalize files separately. I am using this approach for >30 minutes recordings.

for a in *.wav
do
    normalize "${a}"
done

Another approach is "mix mode". This is suitable for shorter files but they should be similar (e.g. same genre)

normalize -m *.wav

related files

Related files are for example songs from one album. This mode retain relative volumes between songs and normalize all songs to maximum.

normalize -b *.wav

Step 3 - create mp3 file

Once all *.wav files are prepared it is time to compress them to mp3. I prefer lame mp3 creator. Build in ---presets are allready well configured to fulfill almost all needs. There are 4 possible options:

  • medium - there is no much space saved compared to standard but quality is reduced
  • standard - well balanced option. There is lot of noise in car anyway so this level should be good for listening in car.
  • extreme - use this if you have really good equipment at home
  • insane - best quality regardless of size

For more details check man page of lame(1)

Once I have all files prepared in directory I run:

for a in *
do
   lame --preset standard "${a}"
done

Step 4 - burn CD

Can your car radio read memory card ? Then your are lucky. Just copy files to card and you are done. All others should use favorite burning program and burn CD-R(W).

Usually I am preparing all files on my media-pc via ssh. Final CD can be burn easily via bashburn from command line.