Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My understanding is that a codec is both a decoder and a specification for decoding. So some group writes a codec which explains how to decode from their format back into the raw bitstream, and they leave the encoding implementation up to anybody who wants to write a compatible encoder. Thus, for example, h.264 is a famous video codec (decoder) and x264 is a well-known FOSS encoder for h.264. But there are many other h.264 encoders.

My understanding is that VideoForLinux (V4L2) is a suite of kernel- and user-space libraries for working with streaming video on Linux machines.

My understanding is that ALSA is a suite of kernel- and user-space libraries for working with streaming audio on Linux machines.

If anything I have stated above is incorrect, please begin by correcting/clarifying me!

Assuming I'm more or less correct, then I'm failing to see what role (if any) V4L2 and ALSA have to play when trying to encode, compress and transmit audio and video bitstreams on a Linux machine.

If I could use x264 to encode my video stream, faac to encode my audio stream, and then ffmpeg to compress, mux and transmit the two streams inside, say, an MPEG-TS container, then where do V4L2 and ALSA come into play?

And if the answer is "they don't", then could someone please give an example or two for when V4L2/ALSA would be used so I can put them into context and understand the use cases where they are required? Thanks in advance.

share|improve this question

2 Answers 2

up vote 1 down vote accepted
  1. Just a fine point detail, most codecs start as specs defining the format, and the methodology by which encoding and decoding occur, including API specs if applicable. From there implementations of both the encoder and decoder may be created. Not all implementations are created equal. For instance the CoreAVC H.264 decoder is multithreaded, whereas many other implementations are not.

  2. V4L2 is primarilly used for creating/capturing video on Linux systems, so it has an encoder built into it (or more likely it references an external one). It's largely used for webcams and video capture/TV cards. See more on Wikipedia. Apps that create raw streams use V4L2 to encode the video to their taste. The decoding is done by a different package (libavcodec perhaps).

  3. ALSA contains codecs, but is itself the support stack for all audio operations in Linux, so wherever you hear sound, ALSA is whats making that happen. I'm sure ALSA has components for audio input (mic/line-in) so it must be capable of some form of encoding, but I've not worked with it.

In your example, I don't believe that V4L2 would be involved at all, since you are using an H.264 encoder, which likely provides much better quality and performance than V4L2. ALSA will be use to play your video back, but will not be used in encoding it.

When you play any sound, that's ALSA at work. When you use your webcam, that's L4V2 at work.

share|improve this answer

As for ffmpeg, ALSA and V4L2 are called input devices, not codecs (not that the term codec is always accurate—I generally call something an encoder and/or decoder to be more specific). Other input devices include JACK, pulse, x11grab, iec61883, dv1394, etc. From the FFmpeg documentation:

Input devices are configured elements in FFmpeg which allow to access the data coming from a multimedia device attached to your system.

For example, you can use ALSA to capture audio from a microphone that is plugged into your audio card. You can use V4L2 to capture video from a webcam. Basic, untested example command:

ffmpeg -f video4linux2 -i /dev/video0 -f alsa -i hw:0 output.mkv

You mention:

h.264 is a famous video codec (decoder)

H.264 is a standard, not a codec. FFmpeg has a decoder named h264. It can be confusing. See What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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