April 5, 2007

HOWTO: ALSA line-in capture with MPlayer

Filed under: Blog — krkhan @ 5:34 pm

I had an MSI TV @nywhere Plus card, and although it worked perfectly under Windows, I never got its sound working on my Linux box. The main reason for it was that the TV-Tuner card outputted sound through a separate cable to ALSA-line in. One way of getting around the mess was to launch MPlayer for video, and then capture audio through this separate command:

arecord -D hw:0 -r 44100 -c 2 -f S16_LE | aplay -

The solution wasn’t only ugly per se, but was also quite annoying because of a second’s lag in audio. After some searching in the mailing list archives of MPlayer, I combined various tricks in the following command which did the magic (relevant switches are highlighted):

mplayer -tv driver=v4l2:width=640:height=480:outfmt=i420:alsa:adevice=hw.0:
:norm=PAL tv://

The adevice, amode and audiorate are dependent on your tuner card, whereas the alsa, forceaudio and immediatemode=0 are mandatory if you’re trying to capture sound from line-in.

That’s it. Now I don’t have to boot to Windows every time I want to do some video-recording. The profusion of capturing options in mencoder compared to MSI’s bundled software comes as an additional bonus for me.

Tags: , , , , , , , , , ,


  1. Great, that was exactly what I was looking for. Thanks!

    Comment by Meertn — January 10, 2008 @ 2:16 pm

  2. Thanks a lot. I only wish your post ranked higher on Google ^^

    Comment by Wishmechaos — April 26, 2008 @ 5:16 am

  3. Many many thanks. This is the solution!!

    Comment by Kai — September 9, 2009 @ 3:25 am

  4. Ditto all the other comments. Wish this ranked higher on Google. Goes to show you can’t just answer people’s questions by saying “use Google”.

    Comment by Chuckk — October 10, 2009 @ 1:05 pm

  5. Thank’s soooooo much!!!!!!!!!!!!!!!!!!!!!!!!!

    Comment by Guest — October 13, 2009 @ 5:04 pm

  6. First of all, the above command works on Fedora 11. But hw:XXX is slow. Better follow the instructions from the

    man arecord

    page and create a loop back device:

    In your $HOME/.asoundrc add:

    pcm.copy {
    type plug
    slave {
    pcm hw
    route_policy copy

    and then use the following mencoder command line:

    mencoder -tv driver=v4l2:outfmt=mjpeg:alsa:adevice=copy:immediatemode=0:norm=PAL tv://

    [adevice=copy uses the defined copy device and outfmt=mjpeg uses the hardware mpeg encoder, if available.]


    Comment by peter_jones_jr — December 31, 2009 @ 6:26 pm

  7. Thanks a lot for the tip Peter, I will edit the post to include this in.

    Comment by Kamran — January 7, 2010 @ 9:29 am

  8. “forceaudio” – I knew there was an option missing. Mplayer’s orifinal ducumentation -as well ffmpegs docs- is quite vague about audio input.

    Comment by Tom — April 21, 2011 @ 7:50 pm

  9. Thank you very much indeed.I have used the forceaudio option before but the immediatemode=0 did the trick.

    Comment by Sven — December 25, 2011 @ 7:55 pm

  10. what if you aren’t using a tv card. Where do you put the alsa line? I’ve tried -ao -rawaudio. Can’t seem to get that line to work.I’m using an easycap using somagic-capture piped to mplayer using rawvideo “ntsc:etc etc”. I can get audio captured fine when recording using ffmpeg, but I can’t get mplayer to play my microphone

    Comment by Craig — May 22, 2012 @ 2:33 am

  11. […] allows the sound of sound card to comeout from the speaker So I thought it has to do with line-in,…e-with-mplayer. But I followed everything on the blog but nothing worked. I must have done something incorrectly. […]

    Pingback by recording sound from pcm along with tv by mencoder — September 8, 2013 @ 6:36 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment